Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix uplink with Python 2.7 #223

Merged
merged 22 commits into from
Dec 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/question.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ about: Pose an inquiry
---

--
**Important:** Before creating an issue, please consider posting your question to our [Gitter Lobby](https://gitter.im/python-uplink/Lobby) first, especially if you suspect that the underlying problem is not a bug nor a feature request.
**Important:** Before creating an issue, please consider posting your question to our [GitHub Discussions](https://github.com/prkumar/uplink/discussions) page first, especially if you suspect that the underlying problem is not a bug nor a feature request.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,6 @@ ENV/
# [2]: https://docs.pipenv.org/advanced/#pipfile-vs-setup-py
#
Pipfile.lock

# macOS
.DS_Store
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
repos:
- repo: https://github.com/ambv/black
rev: 18.6b4
rev: 21.12b0
hooks:
- id: black
python-version: python3.6
python-version: python3.8
files: ^((uplink|examples|tests)\/.+|setup|docs\/conf)\.py$
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v1.3.0
- repo: https://github.com/pycqa/flake8
rev: '4.0.1'
hooks:
- id: flake8
name: flake8
python-version: python3.6
python-version: python3.8
files: ^((uplink|examples|tests)\/.+|setup|docs\/conf)\.py$
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
language: python
dist: bionic # Ubuntu 18.04
python:
- '2.7'
- '3.5'
- '3.6'
- '3.7'
- '3.8'
- '3.9'
- '3.10.1'
before_script:
- pip install tox
- if [[ $TRAVIS_PYTHON_VERSION == 3.6 ]]; then pip install flake8 flake8-bugbear; fi
Expand Down
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ Contributors
- Sakorn Waungwiwatsin (`@SakornW <https://github.com/SakornW>`_)
- Jacob Floyd (`@cognifloyd <https://github.com/cognifloyd>`_)
- Guilherme Crocetti (`@gmcrocetti <https://github.com/gmcrocetti/>`_)
- Alexander Shadchin (`@shadchin <https://github.com/shadchin>`_)
11 changes: 9 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Uplink
******
|PyPI Version| |Build Status| |Coverage Status| |Code Climate| |Documentation Status|
|Gitter| |Code Style|
|GitHub Discussions| |Gitter| |Code Style|

- Builds Reusable Objects for Consuming Web APIs.
- Works with **Requests**, **aiohttp**, and **Twisted**.
Expand Down Expand Up @@ -169,9 +169,14 @@ For new users, a good place to start is this `quick tutorial`_.
Community
=========

Join the conversation on `Gitter`_ to ask questions, provide feedback,
Use the `Discussions`_ tab on GitHub to join the conversation! Ask questions, provide feedback,
and meet other users!

We're migrating our community from `Gitter`_ to GitHub `Discussions`_. Feel free to search our
Gitter lobby for past questions and answers. However, to help us transition, please start new
threads/posts in GitHub Discussions instead of Gitter.

.. _Discussions: https://github.com/prkumar/uplink/discussions
.. _Gitter: https://gitter.im/python-uplink/Lobby


Expand All @@ -182,6 +187,8 @@ Want to report a bug, request a feature, or contribute code to Uplink?
Checkout the `Contribution Guide`_ for where to start.
Thank you for taking the time to improve an open source project :purple_heart:

.. |GitHub Discussions| image:: https://img.shields.io/github/discussions/prkumar/uplink.png
:target: https://github.com/prkumar/uplink/discussions
.. |Build Status| image:: https://travis-ci.com/prkumar/uplink.svg?branch=master
:target: https://travis-ci.com/prkumar/uplink
.. |Code Climate| image:: https://api.codeclimate.com/v1/badges/d5c5666134763ff1d6c0/maintainability
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def read(filename):
# Twisted 19.7.0 dropped py3.4 support
"twisted:python_version == '3.4'": "twisted<=19.2.1",
"typing": ["typing>=3.6.4"],
"tests": ["pytest==4.6.5", "pytest-mock", "pytest-cov", "pytest-twisted"],
"tests": ["pytest", "pytest-mock", "pytest-cov", "pytest-twisted"],
}

metadata = {
Expand Down
4 changes: 4 additions & 0 deletions tests/integration/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ def headers(self):
def data(self):
return self._extras.get("data", None)

@property
def files(self):
return self._extras.get("files", None)

@property
def json(self):
return self._extras.get("json", None)
Expand Down
23 changes: 23 additions & 0 deletions tests/integration/test_form_url_encoded.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Local imports
from uplink import Consumer, form_url_encoded, put, FieldMap

# Constants
BASE_URL = "https://example.com/"


def test_without_converter(mock_response, mock_client):
class Calendar(Consumer):
@form_url_encoded
@put("/user/repos", args={"event_data": FieldMap})
def add_event(self, **event_data):
pass

mock_client.with_response(mock_response)
calendar = Calendar(base_url=BASE_URL, client=mock_client)

# Run
calendar.add_event(name="Weekly Stand-up", public=True)

# Assertions: should not convert if converter is None
request = mock_client.history[0]
assert request.data == {"name": "Weekly Stand-up", "public": True}
24 changes: 24 additions & 0 deletions tests/integration/test_multipart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Local imports
from uplink import Consumer, PartMap, post, multipart

# Constants
BASE_URL = "https://example.com/"


def test_without_converter(mock_response, mock_client):
class Calendar(Consumer):
@multipart
@post("/attachments", args={"files": PartMap})
def upload_attachments(self, **files):
pass

mock_client.with_response(mock_response)
calendar = Calendar(base_url=BASE_URL, client=mock_client)
file = object()

# Run
calendar.upload_attachments(file=file)

# Assertion: should not convert if converter is None
request = mock_client.history[0]
assert request.files == {"file": file}
2 changes: 1 addition & 1 deletion tests/unit/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_tuple(self):

def test_callable(self):
def func():
None
pass

output = auth.get_auth(func)
assert output is func
Expand Down
4 changes: 3 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
# Website (June 2016): http://tox.readthedocs.io/en/latest/

[testenv]
deps = pipenv
deps =
pipenv == 2018.11.26 ; python_version == '2.7'
pipenv ; python_version > '2.7'
commands = pipenv install --skip-lock
pipenv run py.test tests \
--cov-config .coveragerc \
Expand Down
2 changes: 1 addition & 1 deletion uplink/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
"""
# Standard library imports
import collections
from collections import abc
import functools
import inspect

# Local imports
from uplink import exceptions, hooks, interfaces, utils
from uplink.compat import abc
from uplink.converters import keys

__all__ = [
Expand Down
4 changes: 1 addition & 3 deletions uplink/auth.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
"""This module implements the auth layer."""

# Standard library imports
from collections import abc

# Third-party imports
from requests import auth

# Local imports
from uplink import utils
from uplink.compat import abc

__all__ = [
"ApiTokenParam",
Expand Down
5 changes: 1 addition & 4 deletions uplink/clients/io/interfaces.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# Standard library imports
from collections import abc

# Local imports
from uplink import compat

Expand Down Expand Up @@ -69,7 +66,7 @@ def on_failure(self, exc_type, exc_val, exc_tb):
raise NotImplementedError


class Executable(abc.Iterator):
class Executable(compat.abc.Iterator):
"""An abstraction for iterating over the execution of a request."""

def __next__(self):
Expand Down
2 changes: 1 addition & 1 deletion uplink/commands.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Standard library imports
from collections import abc
import functools

# Local imports
Expand All @@ -12,6 +11,7 @@
returns,
utils,
)
from uplink.compat import abc

__all__ = ["get", "head", "put", "post", "patch", "delete"]

Expand Down
3 changes: 2 additions & 1 deletion uplink/compat.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Third-party imports
import six

__all__ = ["reraise"]
__all__ = ["abc", "reraise"]

abc = six.moves.collections_abc
reraise = six.reraise
4 changes: 1 addition & 3 deletions uplink/converters/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Standard library imports
from collections import abc

# Local imports
from uplink._extras import installer, plugin
from uplink.compat import abc
from uplink.converters import keys
from uplink.converters.interfaces import Factory, ConverterFactory, Converter
from uplink.converters.register import (
Expand Down
2 changes: 2 additions & 0 deletions uplink/converters/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ def __call__(self, converter_registry):

def factory_wrapper(*args, **kwargs):
converter = factory(*args, **kwargs)
if not converter:
return None
return functools.partial(self.convert, converter)

return factory_wrapper
Expand Down
2 changes: 1 addition & 1 deletion uplink/converters/typing_.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Standard library imports
import collections
from collections import abc
import functools

# Local imports
from uplink.compat import abc
from uplink.converters import interfaces, register_default_converter_factory

__all__ = ["TypingConverter", "ListConverter", "DictConverter"]
Expand Down
2 changes: 1 addition & 1 deletion uplink/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
handling classes.
"""
# Standard library imports
from collections import abc
import functools
import inspect

# Local imports
from uplink import arguments, helpers, hooks, interfaces, utils
from uplink.compat import abc

__all__ = [
"headers",
Expand Down