From 39fdc81e862f720f44fa8d0482e56e7b852d4b06 Mon Sep 17 00:00:00 2001 From: Ben Falk Date: Fri, 18 Oct 2024 00:20:28 -0400 Subject: [PATCH] update deps, ruff lint/formatting --- dev-requirements.txt | 16 ++++++++-------- requirements.txt | 10 +++++----- scripts/uploader.py | 2 +- steam2sqlite/handler.py | 17 +++++++---------- steam2sqlite/navigator.py | 1 - steam2sqlite/utils.py | 2 +- tests/test_handler.py | 15 +++++---------- tests/test_main.py | 2 +- tests/test_util.py | 1 + 9 files changed, 29 insertions(+), 37 deletions(-) diff --git a/dev-requirements.txt b/dev-requirements.txt index 690f216..82f58a6 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -10,7 +10,7 @@ alembic==1.13.3 # steam2sqlite (pyproject.toml) aniso8601==9.0.1 # via graphene -anyio==4.6.0 +anyio==4.6.2.post1 # via # -c requirements.txt # httpx @@ -28,7 +28,7 @@ certifi==2024.8.30 # httpcore # httpx # requests -charset-normalizer==3.3.2 +charset-normalizer==3.4.0 # via # -c requirements.txt # requests @@ -44,7 +44,7 @@ click-default-group==1.2.4 # -c requirements.txt # datasette # sqlite-utils -coverage==7.6.1 +coverage==7.6.3 # via pytest-cov datasette==0.65 # via @@ -75,7 +75,7 @@ flexparser==0.3.1 # datasette graphene==3.3 # via datasette-graphql -graphql-core==3.2.4 +graphql-core==3.2.5 # via # datasette-graphql # graphene @@ -194,9 +194,9 @@ requests==2.32.3 # via # -c requirements.txt # dropbox -ruff==0.6.9 +ruff==0.7.0 # via steam2sqlite (pyproject.toml) -setuptools==75.1.0 +setuptools==75.2.0 # via # -c requirements.txt # datasette @@ -249,11 +249,11 @@ urllib3==2.2.3 # via # -c requirements.txt # requests -uvicorn==0.31.0 +uvicorn==0.32.0 # via # -c requirements.txt # datasette -uvloop==0.20.0 +uvloop==0.21.0 # via # -c requirements.txt # steam2sqlite (pyproject.toml) diff --git a/requirements.txt b/requirements.txt index b053975..a733588 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,7 +4,7 @@ aiofiles==24.1.0 # via datasette alembic==1.13.3 # via steam2sqlite (pyproject.toml) -anyio==4.6.0 +anyio==4.6.2.post1 # via httpx asgi-csrf==0.10 # via datasette @@ -15,7 +15,7 @@ certifi==2024.8.30 # httpcore # httpx # requests -charset-normalizer==3.3.2 +charset-normalizer==3.4.0 # via requests click==8.1.7 # via @@ -93,7 +93,7 @@ pyyaml==6.0.2 # via datasette requests==2.32.3 # via dropbox -setuptools==75.1.0 +setuptools==75.2.0 # via datasette six==1.16.0 # via @@ -125,7 +125,7 @@ typing-extensions==4.12.2 # sqlalchemy2-stubs urllib3==2.2.3 # via requests -uvicorn==0.31.0 +uvicorn==0.32.0 # via datasette -uvloop==0.20.0 +uvloop==0.21.0 # via steam2sqlite (pyproject.toml) diff --git a/scripts/uploader.py b/scripts/uploader.py index 28a4908..360ff83 100644 --- a/scripts/uploader.py +++ b/scripts/uploader.py @@ -51,7 +51,7 @@ def main(argv: Sequence[str] | None = None) -> int: parser.add_argument( "--token", default=TOKEN, - help="Access token " "(see https://www.dropbox.com/developers/apps)", + help="Access token (see https://www.dropbox.com/developers/apps)", ) args = parser.parse_args(argv) diff --git a/steam2sqlite/handler.py b/steam2sqlite/handler.py index 3672bf6..94e36d6 100644 --- a/steam2sqlite/handler.py +++ b/steam2sqlite/handler.py @@ -22,11 +22,10 @@ def get_or_create(session, model, **kwargs): instance = session.query(model).filter_by(**kwargs).first() if instance: return instance - else: - instance = model(**kwargs) - session.add(instance) - session.flush() - return instance + instance = model(**kwargs) + session.add(instance) + session.flush() + return instance def update_or_create(session, model, filterargs, **kwargs): @@ -152,7 +151,7 @@ def load_app_into_db(session: Session, data: dict) -> SteamApp: if release_date_str: release_date = datetime.strptime(release_date_str, "%b %d, %Y").date() except ValueError: - # todo: log this error + # TODO: log this error pass initial_price = current_price = None @@ -224,9 +223,7 @@ def get_error_appids(session: Session) -> list[int]: def record_appid_error( session, appid: int, name: str | None = None, reason: str | None = None ): - get_or_create( - session, AppidError, **{"appid": appid, "name": name, "reason": reason} - ) + get_or_create(session, AppidError, appid=appid, name=name, reason=reason) session.commit() @@ -239,7 +236,7 @@ def get_apps_data( responses = asyncio.run(navigator.make_requests(urls)) apps_data = [] - for appid, resp in zip(appids, responses): + for appid, resp in zip(appids, responses, strict=False): # make_requests inserts exceptions into the responses list if isinstance(resp, navigator.NavigatorError): logger.error(f"Error getting app data for {appid}") diff --git a/steam2sqlite/navigator.py b/steam2sqlite/navigator.py index 66d2b6a..4d0e2bb 100644 --- a/steam2sqlite/navigator.py +++ b/steam2sqlite/navigator.py @@ -33,7 +33,6 @@ async def get( async def make_requests(urls: list[str]) -> list[httpx.Response]: """List of urls to a list of responses using asyncio""" - limits = httpx.Limits(max_connections=10, max_keepalive_connections=5) async with httpx.AsyncClient( headers={"accept": "application/json"}, timeout=10, limits=limits diff --git a/steam2sqlite/utils.py b/steam2sqlite/utils.py index 771c319..d72a968 100644 --- a/steam2sqlite/utils.py +++ b/steam2sqlite/utils.py @@ -4,7 +4,7 @@ def grouper(iterable, n, fillvalue=None): - "Collect data into non-overlapping fixed-length chunks or blocks" + """Collect data into non-overlapping fixed-length chunks or blocks""" # https://docs.python.org/3/library/itertools.html#itertools-recipes # grouper('ABCDEFG', 3, 'x') --> ABC DEF Gxx args = [iter(iterable)] * n diff --git a/tests/test_handler.py b/tests/test_handler.py index 4abdf64..e7624e6 100644 --- a/tests/test_handler.py +++ b/tests/test_handler.py @@ -19,8 +19,7 @@ def session(): def get_apps_data(appids: list[str]): """'mocks' the handler.get_apps_data function""" - - # todo: actually mock the handler function replacing the url requests w/ static data + # TODO: actually mock the handler function replacing the url requests w/ static data apps_data = [] for appid in appids: @@ -33,8 +32,7 @@ def get_apps_achievements( apps: list[models.SteamApp], ) -> list[tuple[models.SteamApp, list[dict]]]: """'mocks' handler.get_apps_achievements function""" - - # todo: actually mock the handler function replacing the url requests w/ static data + # TODO: actually mock the handler function replacing the url requests w/ static data apps_achievements_data = [] for app in apps: @@ -60,11 +58,10 @@ def portal_achievements(session, portal_app): def test_app_with_duplicated_appid(session): - """portal 2 is listed more than once with different appids (620, 659) + """Portal 2 is listed more than once with different appids (620, 659) However the preorder (659) has an internal appid of 620 We want to assert that we don't ingest dup items """ - dup_appid = "659" dup_app_data = get_apps_data([dup_appid])[0] @@ -114,8 +111,7 @@ def test_ingest_item_twice(session: Session): def test_updates_on_diff_app_data(session: Session, portal_app: models.SteamApp): - """assert updates on new app data""" - + """Assert updates on new app data""" appid = "620" app_data = get_apps_data([appid])[0] @@ -131,7 +127,7 @@ def test_updates_on_diff_app_data(session: Session, portal_app: models.SteamApp) def test_updates_on_diff_achievement_data( session: Session, portal_app: models.SteamApp, portal_achievements ): - """assert updates on diff achievement data""" + """Assert updates on diff achievement data""" apps_achievements_data = get_apps_achievements([portal_app]) portal_achievements_data = apps_achievements_data[0] modified_achievement_name = portal_achievements_data[1][0]["name"] @@ -156,7 +152,6 @@ def test_duplicate_achievements_on_app( """App with duplicated achievements assert clear out achievements with updates """ - # duplicate the first achievement first_achievement = portal_app.achievements[0] a = models.Achievement( diff --git a/tests/test_main.py b/tests/test_main.py index 79bd3e1..1a6eec9 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -2,6 +2,6 @@ def test_main(): - """runs the script for a brief time""" + """Runs the script for a brief time""" result = main.main(("--limit", "0.1")) assert result == 0 diff --git a/tests/test_util.py b/tests/test_util.py index e22fcbc..56fb1c1 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -1,6 +1,7 @@ import time import pytest + from steam2sqlite import utils