From 1ec739d04836e56fe5a1f5e573ae3ffa52ef035e Mon Sep 17 00:00:00 2001 From: Allisson Azevedo Date: Sat, 28 May 2022 19:54:12 -0300 Subject: [PATCH] fix: prepare version 1.1.3 --- .pre-commit-config.yaml | 42 ++++++++++++++++++--------- CHANGES.rst | 7 +++++ examples/async_file_upload.py | 23 --------------- examples/async_github.py | 3 +- examples/async_httpbin.py | 3 +- examples/async_httpbin_disable_ssl.py | 3 +- examples/async_instagram.py | 37 ----------------------- examples/file_upload.py | 17 ----------- examples/instagram.py | 26 ----------------- pyproject.toml | 6 +++- requirements.txt | 4 +-- setup.py | 4 +-- simple_rest_client/api.py | 2 +- simple_rest_client/decorators.py | 2 +- simple_rest_client/request.py | 4 +-- simple_rest_client/resource.py | 6 ++-- tests/test_decorators.py | 6 +--- 17 files changed, 55 insertions(+), 140 deletions(-) delete mode 100644 examples/async_file_upload.py delete mode 100644 examples/async_instagram.py delete mode 100644 examples/file_upload.py delete mode 100644 examples/instagram.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8867e2d..1d57bee 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,27 +1,41 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.0.1 + rev: v4.1.0 hooks: + - id: check-ast + - id: fix-byte-order-marker + - id: check-docstring-first + - id: check-json + - id: check-merge-conflict + - id: check-symlinks + - id: check-toml + - id: check-vcs-permalinks + - id: check-xml - id: check-yaml + - id: debug-statements + - id: destroyed-symlinks - id: end-of-file-fixer - id: trailing-whitespace - - repo: https://gitlab.com/pycqa/flake8 - rev: 4.0.1 + + - repo: https://github.com/MarcoGorelli/absolufy-imports + rev: v0.3.1 hooks: - - id: flake8 - args: ["--ignore=E501"] + - id: absolufy-imports + - repo: https://github.com/pycqa/isort - rev: 5.9.3 + rev: 5.10.1 hooks: - id: isort - name: isort (python) - - id: isort - name: isort (cython) - types: [cython] - - id: isort - name: isort (pyi) - types: [pyi] + args: ["--overwrite-in-place"] + - repo: https://github.com/psf/black - rev: 21.9b0 + rev: 22.3.0 hooks: - id: black + args: ["--line-length=110"] + + - repo: https://github.com/pycqa/flake8 + rev: 4.0.1 + hooks: + - id: flake8 + args: ["--max-line-length=110", "--ignore=E203,E501,W503"] diff --git a/CHANGES.rst b/CHANGES.rst index 1df7cc1..fbc1e65 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,6 +1,13 @@ Changelog --------- +1.1.3 +~~~~~ + +* Update pre-commit config and code format. +* Remove broken examples. +* Update base requirements version. + 1.1.2 ~~~~~ diff --git a/examples/async_file_upload.py b/examples/async_file_upload.py deleted file mode 100644 index 2926126..0000000 --- a/examples/async_file_upload.py +++ /dev/null @@ -1,23 +0,0 @@ -import asyncio - -from simple_rest_client.api import API -from simple_rest_client.resource import AsyncResource - - -class FileUploadResource(AsyncResource): - actions = {"create": {"method": "POST", "url": "post.php?dir=example"}} - - -# http://blog.henrycipolla.com/2011/12/testing-multipartform-data-uploads-with-post-test-server/ -files = {"file": open("github.py", "rb")} -post_test_server_api = API(api_root_url="http://posttestserver.com/", timeout=10) -post_test_server_api.add_resource(resource_name="file_upload", resource_class=FileUploadResource) - - -async def main(): - response = await post_test_server_api.file_upload.create(body=files) - print("post_test_server_api.file_upload.create={!r}".format(response.body)) - - -loop = asyncio.get_event_loop() -loop.run_until_complete(main()) diff --git a/examples/async_github.py b/examples/async_github.py index 5dad0e6..3bcae85 100644 --- a/examples/async_github.py +++ b/examples/async_github.py @@ -34,5 +34,4 @@ async def main(): ) -loop = asyncio.get_event_loop() -loop.run_until_complete(main()) +asyncio.run(main()) diff --git a/examples/async_httpbin.py b/examples/async_httpbin.py index acea3b2..9f080e0 100644 --- a/examples/async_httpbin.py +++ b/examples/async_httpbin.py @@ -19,5 +19,4 @@ async def main(): print("httpbin_api.basic_auth.retrieve={!r}".format(response.body)) -loop = asyncio.get_event_loop() -loop.run_until_complete(main()) +asyncio.run(main()) diff --git a/examples/async_httpbin_disable_ssl.py b/examples/async_httpbin_disable_ssl.py index 47be22d..7bf847a 100644 --- a/examples/async_httpbin_disable_ssl.py +++ b/examples/async_httpbin_disable_ssl.py @@ -19,5 +19,4 @@ async def main(): print("httpbin_api.basic_auth.retrieve={!r}".format(response.body)) -loop = asyncio.get_event_loop() -loop.run_until_complete(main()) +asyncio.run(main()) diff --git a/examples/async_instagram.py b/examples/async_instagram.py deleted file mode 100644 index 652f62e..0000000 --- a/examples/async_instagram.py +++ /dev/null @@ -1,37 +0,0 @@ -import asyncio - -from simple_rest_client.api import API -from simple_rest_client.resource import AsyncResource - - -class UserResource(AsyncResource): - actions = { - "search": {"method": "GET", "url": "users/search"}, - "retrieve": {"method": "GET", "url": "users/{}"}, - "retrieve_media": {"method": "GET", "url": "users/{}/media/recent"}, - "retrieve_likes": {"method": "GET", "url": "users/self/media/recent"}, - } - - -# https://www.slickremix.com/docs/how-to-create-instagram-access-token/ -# get token with public_content scope -default_params = {"access_token": "valid-token"} -instagram_api = API( - api_root_url="https://api.instagram.com/v1/", params=default_params, json_encode_body=True -) -instagram_api.add_resource(resource_name="users", resource_class=UserResource) - - -async def main(): - users_search = await instagram_api.users.search(params={"q": "allissonazevedo"}) - users_retrieve = await instagram_api.users.retrieve("self") - users_retrieve_media = await instagram_api.users.retrieve_media("self") - users_retrieve_likes = await instagram_api.users.retrieve_likes() - print("instagram_api.users.search={!r}".format(users_search.body)) - print("instagram_api.users.retrieve={!r}".format(users_retrieve.body)) - print("instagram_api.users.retrieve_media={!r}".format(users_retrieve_media.body)) - print("instagram_api.users.retrieve_likes={!r}".format(users_retrieve_likes.body)) - - -loop = asyncio.get_event_loop() -loop.run_until_complete(main()) diff --git a/examples/file_upload.py b/examples/file_upload.py deleted file mode 100644 index 1a444a2..0000000 --- a/examples/file_upload.py +++ /dev/null @@ -1,17 +0,0 @@ -from simple_rest_client.api import API -from simple_rest_client.resource import Resource - - -class FileUploadResource(Resource): - actions = {"create": {"method": "POST", "url": "post.php?dir=example"}} - - -# http://blog.henrycipolla.com/2011/12/testing-multipartform-data-uploads-with-post-test-server/ -files = {"file": open("github.py", "rb")} -post_test_server_api = API(api_root_url="http://posttestserver.com/", timeout=10) -post_test_server_api.add_resource(resource_name="file_upload", resource_class=FileUploadResource) -print( - "post_test_server_api.file_upload.create={!r}".format( - post_test_server_api.file_upload.create(files=files).body - ) -) diff --git a/examples/instagram.py b/examples/instagram.py deleted file mode 100644 index af27f76..0000000 --- a/examples/instagram.py +++ /dev/null @@ -1,26 +0,0 @@ -from simple_rest_client.api import API -from simple_rest_client.resource import Resource - - -class UserResource(Resource): - actions = { - "search": {"method": "GET", "url": "users/search"}, - "retrieve": {"method": "GET", "url": "users/{}"}, - "retrieve_media": {"method": "GET", "url": "users/{}/media/recent"}, - "retrieve_likes": {"method": "GET", "url": "users/self/media/recent"}, - } - - -# https://www.slickremix.com/docs/how-to-create-instagram-access-token/ -# get token with public_content scope -default_params = {"access_token": "valid-token"} -instagram_api = API( - api_root_url="https://api.instagram.com/v1/", params=default_params, json_encode_body=True -) -instagram_api.add_resource(resource_name="users", resource_class=UserResource) -print( - "instagram_api.users.search={!r}".format(instagram_api.users.search(params={"q": "allissonazevedo"}).body) -) -print("instagram_api.users.retrieve={!r}".format(instagram_api.users.retrieve("self").body)) -print("instagram_api.users.retrieve_media={!r}".format(instagram_api.users.retrieve_media("self").body)) -print("instagram_api.users.retrieve_likes={!r}".format(instagram_api.users.retrieve_likes().body)) diff --git a/pyproject.toml b/pyproject.toml index 1438261..f3cfbc2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,10 @@ [tool.black] line-length = 110 -target-version = ['py39'] +target-version = ['py310'] [tool.isort] profile = 'black' +line_length = 110 +force_alphabetical_sort_within_sections = true +sections = ["FUTURE", "STDLIB", "THIRDPARTY", "FIRSTPARTY", "LOCALFOLDER"] +default_section = "THIRDPARTY" diff --git a/requirements.txt b/requirements.txt index ccff7a1..0457d87 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ -httpx>=0.19.0 -python-slugify>=5.0.2 +httpx>=0.23.0 +python-slugify>=6.1.2 python-status>=1.0.1 diff --git a/setup.py b/setup.py index db96337..c2f1802 100644 --- a/setup.py +++ b/setup.py @@ -25,7 +25,7 @@ changelog = f.read() -install_requirements = ["python-status>=1.0.1", "httpx>=0.19.0", "python-slugify>=5.0.2"] +install_requirements = ["python-status>=1.0.1", "httpx>=0.23.0", "python-slugify>=6.1.2"] tests_requirements = ["pytest", "pytest-asyncio", "pytest-cov", "pytest-httpserver", "coveralls"] @@ -46,7 +46,7 @@ def run(self): setup( name="simple-rest-client", version=version, - description="Simple REST client for python 3.6+", + description="Simple REST client for python 3.7+", long_description=long_description, url="https://github.com/allisson/python-simple-rest-client", author="Allisson Azevedo", diff --git a/simple_rest_client/api.py b/simple_rest_client/api.py index ac9894d..783fab7 100644 --- a/simple_rest_client/api.py +++ b/simple_rest_client/api.py @@ -1,6 +1,6 @@ from slugify import slugify -from .resource import Resource +from simple_rest_client.resource import Resource class API: diff --git a/simple_rest_client/decorators.py b/simple_rest_client/decorators.py index a0bd729..9cfa808 100644 --- a/simple_rest_client/decorators.py +++ b/simple_rest_client/decorators.py @@ -4,7 +4,7 @@ import httpx import status -from .exceptions import ( +from simple_rest_client.exceptions import ( AuthError, ClientConnectionError, ClientError, diff --git a/simple_rest_client/request.py b/simple_rest_client/request.py index 4fd8150..c49ac10 100644 --- a/simple_rest_client/request.py +++ b/simple_rest_client/request.py @@ -1,7 +1,7 @@ import logging -from .decorators import handle_async_request_error, handle_request_error -from .models import Response +from simple_rest_client.decorators import handle_async_request_error, handle_request_error +from simple_rest_client.models import Response logger = logging.getLogger(__name__) diff --git a/simple_rest_client/resource.py b/simple_rest_client/resource.py index f24ce0a..8c7803e 100644 --- a/simple_rest_client/resource.py +++ b/simple_rest_client/resource.py @@ -3,9 +3,9 @@ import httpx -from .exceptions import ActionNotFound, ActionURLMatchError -from .models import Request -from .request import make_async_request, make_request +from simple_rest_client.exceptions import ActionNotFound, ActionURLMatchError +from simple_rest_client.models import Request +from simple_rest_client.request import make_async_request, make_request logger = logging.getLogger(__name__) diff --git a/tests/test_decorators.py b/tests/test_decorators.py index 769e9e5..e93af57 100644 --- a/tests/test_decorators.py +++ b/tests/test_decorators.py @@ -5,11 +5,7 @@ import status 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,