From 19b3edba0f6a3b4564ff9af8e472854b5eb8c893 Mon Sep 17 00:00:00 2001 From: Allisson Azevedo Date: Tue, 12 Oct 2021 11:01:12 -0300 Subject: [PATCH 1/2] feat: update requirements to latest versions --- .github/workflows/pythonapp.yml | 35 +++++++++++------------- .gitignore | 2 +- .pre-commit-config.yaml | 46 ++++++++++++++++++-------------- CHANGES.rst | 9 +++++++ README.rst | 2 +- docs/Makefile | 2 +- docs/index.rst | 2 +- docs/installation.rst | 2 +- pyproject.toml | 5 +++- pytest.ini | 2 +- requirements-dev.txt | 2 +- requirements.txt | 4 +-- setup.cfg | 2 +- setup.py | 7 ++--- simple_rest_client/api.py | 19 ++++++------- simple_rest_client/decorators.py | 8 +++++- tests/test_decorators.py | 10 ++++--- 17 files changed, 93 insertions(+), 66 deletions(-) diff --git a/.github/workflows/pythonapp.yml b/.github/workflows/pythonapp.yml index 5d5ddf4..9cc9b97 100644 --- a/.github/workflows/pythonapp.yml +++ b/.github/workflows/pythonapp.yml @@ -4,27 +4,24 @@ on: [push] jobs: build: - runs-on: ubuntu-latest strategy: matrix: - python-version: [3.6, 3.7, 3.8, 3.9] + python-version: [3.7, 3.8, 3.9, 3.10] steps: - - uses: actions/checkout@v2 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements-dev.txt - - name: Lint - run: | - make lint - - name: Test with pytest - run: | - pytest --cov-report=xml - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v1 + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements-dev.txt + - name: pre-commit lint + run: make lint + - name: pytest + run: pytest --cov-report=xml + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v1 diff --git a/.gitignore b/.gitignore index 98d7c08..aa65215 100644 --- a/.gitignore +++ b/.gitignore @@ -90,4 +90,4 @@ ENV/ .ropeproject .DS_Store -.vscode/ \ No newline at end of file +.vscode/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 06960c2..8867e2d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,21 +1,27 @@ repos: -- repo: local - hooks: - - id: black - name: black - entry: black - language: system - types: [python] - args: ['--diff'] - - id: isort - name: isort - entry: isort - language: system - types: [python] - args: ['--check-only'] - - id: flake8 - name: flake8 - entry: flake8 - language: system - types: [python] - args: ['--ignore=E501,W503'] + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.0.1 + hooks: + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace + - repo: https://gitlab.com/pycqa/flake8 + rev: 4.0.1 + hooks: + - id: flake8 + args: ["--ignore=E501"] + - repo: https://github.com/pycqa/isort + rev: 5.9.3 + hooks: + - id: isort + name: isort (python) + - id: isort + name: isort (cython) + types: [cython] + - id: isort + name: isort (pyi) + types: [pyi] + - repo: https://github.com/psf/black + rev: 21.9b0 + hooks: + - id: black diff --git a/CHANGES.rst b/CHANGES.rst index bd24872..eebad33 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,6 +1,15 @@ Changelog --------- +1.1.0 +~~~~~ + +* Drop support for python 3.6.x. +* Fix json_encode_body cannot be overridden bug (thanks @denravonska). +* Replace asynctest with asyncmock. +* Update httpx and python-slugify to latest versions. +* Update pre-commit rules. + 1.0.8 ~~~~~ diff --git a/README.rst b/README.rst index ab59a7e..0132ee6 100644 --- a/README.rst +++ b/README.rst @@ -6,7 +6,7 @@ Simple Rest Client ---- -Simple REST client for python 3.6+. +Simple REST client for python 3.7+. How to install diff --git a/docs/Makefile b/docs/Makefile index e327aeb..24dab33 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -17,4 +17,4 @@ help: # Catch-all target: route all unknown targets to Sphinx using the new # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). %: Makefile - @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) \ No newline at end of file + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/docs/index.rst b/docs/index.rst index e49dd10..3087ccd 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -6,7 +6,7 @@ Welcome to python-simple-rest-client's documentation! ===================================================== -Simple REST client for python 3.6+, supports sync (with requests) and asyncio (with aiohttp) requests +Simple REST client for python 3.7+, supports sync and asyncio (with httpx) requests Contents diff --git a/docs/installation.rst b/docs/installation.rst index a04d872..a8aa194 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -5,4 +5,4 @@ Install the latest stable release via pip:: pip install simple-rest-client -python-simple-rest-client runs with `Python 3.6+ `_ . +python-simple-rest-client runs with `Python 3.7+ `_ . diff --git a/pyproject.toml b/pyproject.toml index c2691b0..1438261 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,6 @@ [tool.black] line-length = 110 -target-version = ['py38'] +target-version = ['py39'] + +[tool.isort] +profile = 'black' diff --git a/pytest.ini b/pytest.ini index 7850921..1aff7f0 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,2 +1,2 @@ [pytest] -addopts = -vvv --cov=simple_rest_client --cov-report=term-missing \ No newline at end of file +addopts = -vvv --cov=simple_rest_client --cov-report=term-missing diff --git a/requirements-dev.txt b/requirements-dev.txt index a335102..b3d8f2d 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,6 +1,6 @@ -r requirements.txt Sphinx -asynctest +asyncmock black codecov flake8 diff --git a/requirements.txt b/requirements.txt index 0206fd9..ccff7a1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ -httpx>=0.16.1 -python-slugify>=4.0.0 +httpx>=0.19.0 +python-slugify>=5.0.2 python-status>=1.0.1 diff --git a/setup.cfg b/setup.cfg index 6a61127..51232b1 100644 --- a/setup.cfg +++ b/setup.cfg @@ -4,4 +4,4 @@ multi_line_output=3 include_trailing_comma=True known_localfolder=simple_rest_client,tests sections=FUTURE,STDLIB,THIRDPARTY,LOCALFOLDER -default_section=THIRDPARTY \ No newline at end of file +default_section=THIRDPARTY diff --git a/setup.py b/setup.py index 44f2223..db96337 100644 --- a/setup.py +++ b/setup.py @@ -25,7 +25,7 @@ changelog = f.read() -install_requirements = ["python-status>=1.0.1", "httpx>=0.16.1", "python-slugify>=4.0.0"] +install_requirements = ["python-status>=1.0.1", "httpx>=0.19.0", "python-slugify>=5.0.2"] tests_requirements = ["pytest", "pytest-asyncio", "pytest-cov", "pytest-httpserver", "coveralls"] @@ -54,12 +54,13 @@ def run(self): classifiers=[ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", - "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", "Topic :: Software Development :: Libraries", ], - keywords="rest client http asyncio", + keywords="rest client http httpx asyncio", packages=find_packages(exclude=["docs", "tests*"]), setup_requires=["pytest-runner"], install_requires=install_requirements, diff --git a/simple_rest_client/api.py b/simple_rest_client/api.py index 92d9eec..a5d495f 100644 --- a/simple_rest_client/api.py +++ b/simple_rest_client/api.py @@ -34,20 +34,21 @@ def add_resource( params=None, headers=None, timeout=None, - append_slash=False, - json_encode_body=False, + append_slash=None, + json_encode_body=None, + ssl_verify=None, ): resource_valid_name = self.correct_attribute_name(resource_name) resource_class = resource_class or Resource resource = resource_class( - api_root_url=api_root_url or self.api_root_url, + api_root_url=api_root_url if api_root_url is not None else self.api_root_url, resource_name=resource_valid_name, - params=params or self.params, - headers=headers or self.headers, - timeout=timeout or self.timeout, - append_slash=append_slash or self.append_slash, - json_encode_body=json_encode_body or self.json_encode_body, - ssl_verify=self.ssl_verify, + params=params if params is not None else self.params, + headers=headers if headers is not None else self.headers, + timeout=timeout if timeout is not None else self.timeout, + append_slash=append_slash if append_slash is not None else self.append_slash, + json_encode_body=json_encode_body if json_encode_body is not None else self.json_encode_body, + ssl_verify=ssl_verify if ssl_verify is not None else self.ssl_verify, ) self._resources[resource_valid_name] = resource setattr(self, resource_valid_name, resource) diff --git a/simple_rest_client/decorators.py b/simple_rest_client/decorators.py index 98e735c..a0bd729 100644 --- a/simple_rest_client/decorators.py +++ b/simple_rest_client/decorators.py @@ -4,7 +4,13 @@ import httpx import status -from .exceptions import AuthError, ClientConnectionError, ClientError, NotFoundError, ServerError +from .exceptions import ( + AuthError, + ClientConnectionError, + ClientError, + NotFoundError, + ServerError, +) logger = logging.getLogger(__name__) client_connection_exceptions = (httpx.RequestError,) diff --git a/tests/test_decorators.py b/tests/test_decorators.py index 4c6755e..769e9e5 100644 --- a/tests/test_decorators.py +++ b/tests/test_decorators.py @@ -3,9 +3,13 @@ import httpx import pytest import status -from asynctest.mock import CoroutineMock +from asyncmock import AsyncMock -from simple_rest_client.decorators import handle_async_request_error, handle_request_error, validate_response +from simple_rest_client.decorators import ( + handle_async_request_error, + handle_request_error, + validate_response, +) from simple_rest_client.exceptions import ( AuthError, ClientConnectionError, @@ -83,6 +87,6 @@ def test_handle_request_error_exceptions(side_effect): ), ) def test_handle_async_request_error_exceptions(event_loop, side_effect): - wrapped = CoroutineMock(side_effect=side_effect(message="message", request="Request")) + wrapped = AsyncMock(side_effect=side_effect(message="message", request="Request")) with pytest.raises(ClientConnectionError): event_loop.run_until_complete(handle_async_request_error(wrapped)()) From 30828f901412a62bead44e84d5fbbcb7f52c00a2 Mon Sep 17 00:00:00 2001 From: Allisson Azevedo Date: Tue, 12 Oct 2021 11:05:21 -0300 Subject: [PATCH 2/2] ci: set python versions as strings --- .github/workflows/pythonapp.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pythonapp.yml b/.github/workflows/pythonapp.yml index 9cc9b97..130371a 100644 --- a/.github/workflows/pythonapp.yml +++ b/.github/workflows/pythonapp.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [3.7, 3.8, 3.9, 3.10] + python-version: ['3.7', '3.8', '3.9', '3.10'] steps: - uses: actions/checkout@v2