From d0746dd4346bfc3e49a02b861266859c5f70bb86 Mon Sep 17 00:00:00 2001 From: Clement Julia Date: Thu, 10 Oct 2024 08:36:30 +0200 Subject: [PATCH] v0.7.0 preparing version --- README.md | 3 +++ docs/source/conf.py | 2 +- modio/__init__.py | 2 +- modio/client.py | 14 ++++++++++---- modio/entities.py | 32 +++++++++++++++----------------- modio/utils.py | 7 +++++-- requirements.txt | 2 +- setup.py | 2 +- tests/test_client.py | 18 ++++++++++-------- tests/test_objects.py | 8 ++++---- 10 files changed, 51 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index 6105fc6..99cf4e1 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ # mod.io +> [!WARNING] +> This project is now archived, feel free to fork it. + ![mod.io Logo](https://static.mod.io/v1/images/branding/modio-color-dark.png "https://mod.io") [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) diff --git a/docs/source/conf.py b/docs/source/conf.py index 27949e3..7b04c27 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -27,7 +27,7 @@ # The short X.Y version version = "" # The full version, including alpha/beta/rc tags -release = "0.6.0" +release = "0.7.0" # -- General configuration --------------------------------------------------- diff --git a/modio/__init__.py b/modio/__init__.py index 1a1cefe..1817e53 100644 --- a/modio/__init__.py +++ b/modio/__init__.py @@ -8,4 +8,4 @@ from .errors import * from .mod import * -__version__ = "0.6.1" +__version__ = "0.7.0" diff --git a/modio/client.py b/modio/client.py index e4a7f6e..ea50062 100644 --- a/modio/client.py +++ b/modio/client.py @@ -23,10 +23,13 @@ MAX_TRIES = 2 + class Connection: """Class handling under the hood requests and ratelimits.""" - def __init__(self, api_path, api_key, access_token, lang, version, test, platform, portal, ratelimit_max_sleep): + def __init__( + self, api_path, api_key, access_token, lang, version, test, platform, portal, ratelimit_max_sleep + ): self.test = test self.version = version self.api_path = api_path @@ -262,6 +265,9 @@ class Client: Parameters ----------- + api_path: str + The api path is the "root" from which you will access the api. This has two format: "g-" + for a game root path or "u-" for a user root path. api_key : Optional[str] The api key that will be used to authenticate the bot while it makes most of its GET requests. This can be generated on the mod.io website. Optional if an access @@ -300,7 +306,7 @@ class Client: def __init__( self, *, - api_path=None, + api_path, api_key=None, access_token=None, lang="en", @@ -308,7 +314,7 @@ def __init__( test=False, platform=None, portal=None, - ratelimit_max_sleep=math.inf + ratelimit_max_sleep=math.inf, ): self.lang = lang self.version = version @@ -322,7 +328,7 @@ def __init__( lang=lang, platform=platform, portal=portal, - ratelimit_max_sleep=ratelimit_max_sleep + ratelimit_max_sleep=ratelimit_max_sleep, ) def __repr__(self): diff --git a/modio/entities.py b/modio/entities.py index 5d14a20..34c94ad 100644 --- a/modio/entities.py +++ b/modio/entities.py @@ -1,6 +1,6 @@ """Module for miscs objects.""" import time -import json +from typing import List from .mixins import OwnerMixin, RatingMixin, ReportMixin, StatsMixin from .errors import modioException @@ -406,23 +406,22 @@ async def async_delete(self): ) return resp - - def manage_platforms(self, approved:list[str]=None, denied:list[str]=None): + def manage_platforms(self, approved: List[str] = None, denied: List[str] = None): """Manage the platform status of this mod file. Returns an updated - instances of the file. + instances of the file. - Parameters - ----------- - approved : str - Change the release version of the file - denied : str - Change the changelog of this release + Parameters + ----------- + approved : str + Change the release version of the file + denied : str + Change the changelog of this release - Returns - -------- - ModFile - The updated file - """ + Returns + -------- + ModFile + The updated file + """ if approved is None: approved = [] @@ -446,7 +445,7 @@ def manage_platforms(self, approved:list[str]=None, denied:list[str]=None): return self.__class__(connection=self.connection, game_id=self.game_id, **file_json) - async def manage_platforms_async(self, approved:list[str]=None, denied:list[str]=None): + async def manage_platforms_async(self, approved: List[str] = None, denied: List[str] = None): if approved is None: approved = [] if denied is None: @@ -469,7 +468,6 @@ async def manage_platforms_async(self, approved:list[str]=None, denied:list[str] return self.__class__(connection=self.connection, game_id=self.game_id, **file_json) - def url_is_expired(self): """Check if the url is still valid for this modfile. diff --git a/modio/utils.py b/modio/utils.py index 7060806..4bd1edb 100644 --- a/modio/utils.py +++ b/modio/utils.py @@ -169,14 +169,16 @@ def retry_logic(*args, **kwargs): except modioException as e: if e.code != 429 or args[0].ratelimit_max_sleep == 0: raise e - + error = e raise error return retry_logic + return wrapper + def async_ratelimit_retry(max_retries): def wrapper(func): @wraps(func) @@ -187,10 +189,11 @@ async def retry_logic(*args, **kwargs): except modioException as e: if e.code != 429 or args[0].ratelimit_max_sleep == 0: raise e - + error = e raise error return retry_logic + return wrapper diff --git a/requirements.txt b/requirements.txt index 238426c..bba0915 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -aiohttp==3.8.1 +aiohttp==3.8.5 requests==2.31.0 typing-extensions==4.3.0 diff --git a/setup.py b/setup.py index afa7be2..7fef603 100644 --- a/setup.py +++ b/setup.py @@ -22,5 +22,5 @@ long_description_content_type="text/markdown", long_description=readme, packages=find_packages(include=["modio", "modio.*"]), - install_requires=["aiohttp==3.8.1", "requests==2.31.0", "typing-extensions==4.3.0"], + install_requires=["aiohttp==3.8.5", "requests==2.31.0", "typing-extensions==4.3.0"], ) diff --git a/tests/test_client.py b/tests/test_client.py index c717851..ff1a3d0 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -101,16 +101,18 @@ def test_portal(self): assert "X-Modio-Portal" in headers assert headers["X-Modio-Portal"] is modio.enums.TargetPortal.facebook.value - @pytest.mark.parametrize("retry_after, max_sleep, expected", [ - (60, 0, False), - (60, 60, True), - (0, 60, True), - (60, 3600, True) - ]) + @pytest.mark.parametrize( + "retry_after, max_sleep, expected", [(60, 0, False), (60, 60, True), (0, 60, True), (60, 3600, True)] + ) @mock.patch("time.sleep") def test_ratelimit(self, sleep_mock, retry_after, max_sleep, expected): client = modio.Client(access_token=access_token, test=use_test_env, ratelimit_max_sleep=max_sleep) with pytest.raises(modioException): - client.connection._post_process(FakeRequest(status_code=429, headers={"retry-after": retry_after}, json_data={"error": {"code": "", "message": "", "error_ref": ""}})) + client.connection._post_process( + FakeRequest( + status_code=429, + headers={"retry-after": retry_after}, + json_data={"error": {"code": "", "message": "", "error_ref": ""}}, + ) + ) assert sleep_mock.called == expected - diff --git a/tests/test_objects.py b/tests/test_objects.py index 7fd2a73..5f97efe 100644 --- a/tests/test_objects.py +++ b/tests/test_objects.py @@ -55,7 +55,7 @@ def test_comment(self): comments = self.mod.get_comments().results if not comments: return - + comment = comments[0] comment.edit("test edit") @@ -73,7 +73,7 @@ def test_async_comment(self): comments = run(self.mod.async_get_comments()).results if not comments: return - + comment = comments[0] run(comment.async_edit("test edit async")) @@ -198,13 +198,13 @@ def tearDown(self): def test_mute(self): with pytest.raises(modioException): self.member.mute() - + self.member.unmute() def test_async_mute(self): with pytest.raises(modioException): run(self.member.async_mute()) - + run(self.member.async_unmute())