From 3d7e6f29c5524165b8046c74054a25c16b71bdc8 Mon Sep 17 00:00:00 2001 From: androiddrew Date: Sat, 9 Nov 2019 21:01:36 -0500 Subject: [PATCH] Blacking that code. --- dev_requirements.in | 5 --- dev_requirements.txt | 32 ------------------- services/gears_api/gears_api/__init__.py | 1 + .../gears_api/api/welcome/__init__.py | 2 +- services/gears_api/gears_api/db.py | 2 +- services/gears_api/gears_api/index.py | 12 ++++--- services/gears_api/gears_api/manager.py | 7 ++-- services/gears_api/manage.py | 4 ++- services/gears_api/migrations/env.py | 6 ++-- .../versions/dc04b852fef5_initial_commit.py | 2 +- services/gears_api/setup.cfg | 10 ++++++ services/gears_api/tests/conftest.py | 8 +++-- services/gears_api/tests/test_app_routes.py | 8 +++-- services/gears_api/tests/test_renders.py | 2 +- 14 files changed, 43 insertions(+), 58 deletions(-) delete mode 100644 dev_requirements.in delete mode 100644 dev_requirements.txt create mode 100644 services/gears_api/setup.cfg diff --git a/dev_requirements.in b/dev_requirements.in deleted file mode 100644 index cbe692f..0000000 --- a/dev_requirements.in +++ /dev/null @@ -1,5 +0,0 @@ -black -flake8 -pytest -pytest-cov -pip-tools diff --git a/dev_requirements.txt b/dev_requirements.txt deleted file mode 100644 index 3ffec0b..0000000 --- a/dev_requirements.txt +++ /dev/null @@ -1,32 +0,0 @@ -# -# This file is autogenerated by pip-compile -# To update, run: -# -# pip-compile dev_requirements.in -# ---trusted-host pypi.python.org - -appdirs==1.4.3 # via black -atomicwrites==1.3.0 # via pytest -attrs==19.1.0 # via black, pytest -black==19.3b0 -click==7.0 # via black, pip-tools -coverage==4.5.4 # via pytest-cov -entrypoints==0.3 # via flake8 -flake8==3.7.8 -importlib-metadata==0.23 # via pluggy, pytest -mccabe==0.6.1 # via flake8 -more-itertools==7.2.0 # via pytest, zipp -packaging==19.2 # via pytest -pip-tools==4.1.0 -pluggy==0.13.0 # via pytest -py==1.8.0 # via pytest -pycodestyle==2.5.0 # via flake8 -pyflakes==2.1.1 # via flake8 -pyparsing==2.4.2 # via packaging -pytest-cov==2.7.1 -pytest==5.2.0 -six==1.12.0 # via packaging, pip-tools -toml==0.10.0 # via black -wcwidth==0.1.7 # via pytest -zipp==0.6.0 # via importlib-metadata diff --git a/services/gears_api/gears_api/__init__.py b/services/gears_api/gears_api/__init__.py index e69de29..3dc1f76 100644 --- a/services/gears_api/gears_api/__init__.py +++ b/services/gears_api/gears_api/__init__.py @@ -0,0 +1 @@ +__version__ = "0.1.0" diff --git a/services/gears_api/gears_api/api/welcome/__init__.py b/services/gears_api/gears_api/api/welcome/__init__.py index 813c05e..7d762b3 100644 --- a/services/gears_api/gears_api/api/welcome/__init__.py +++ b/services/gears_api/gears_api/api/welcome/__init__.py @@ -1 +1 @@ -from .views import welcome \ No newline at end of file +from .views import welcome diff --git a/services/gears_api/gears_api/db.py b/services/gears_api/gears_api/db.py index 7cff90f..bdc4e2e 100644 --- a/services/gears_api/gears_api/db.py +++ b/services/gears_api/gears_api/db.py @@ -17,7 +17,7 @@ def pg_utcnow(element, compiler, **kw): return "TIMEZONE('utc', CURRENT_TIMESTAMP)" -@compiles(CreateColumn, 'postgresql') +@compiles(CreateColumn, "postgresql") def use_identity(element, compiler, **kw): text = compiler.visit_create_column(element, **kw) text = text.replace("SERIAL", "INT GENERATED BY DEFAULT AS IDENTITY") diff --git a/services/gears_api/gears_api/index.py b/services/gears_api/gears_api/index.py index 24939eb..0d25995 100644 --- a/services/gears_api/gears_api/index.py +++ b/services/gears_api/gears_api/index.py @@ -3,7 +3,11 @@ from molten import App, Route, ResponseRendererMiddleware, Settings from molten.http import HTTP_404, Request from molten.openapi import Metadata, OpenAPIHandler, OpenAPIUIHandler from molten.settings import SettingsComponent -from molten.contrib.sqlalchemy import SQLAlchemyMiddleware, SQLAlchemyEngineComponent, SQLAlchemySessionComponent +from molten.contrib.sqlalchemy import ( + SQLAlchemyMiddleware, + SQLAlchemyEngineComponent, + SQLAlchemySessionComponent, +) from wsgicors import CORS from whitenoise import WhiteNoise @@ -15,9 +19,7 @@ from . import settings get_schema = OpenAPIHandler( metadata=Metadata( - title="gears_api", - description="API for the gears application", - version="0.0.0" + title="gears_api", description="API for the gears application", version="0.0.0" ) ) @@ -73,7 +75,7 @@ def create_app(_components=None, _middleware=None, _routes=None, _renderers=None components=_components or components, middleware=_middleware or middleware, routes=_routes or routes, - renderers=_renderers or renderers + renderers=_renderers or renderers, ) wrapped_app = CORS(wrapped_app, **settings.strict_get("wsgicors")) wrapped_app = WhiteNoise(wrapped_app, **settings.strict_get("whitenoise")) diff --git a/services/gears_api/gears_api/manager.py b/services/gears_api/gears_api/manager.py index 96ac713..91ac96f 100644 --- a/services/gears_api/gears_api/manager.py +++ b/services/gears_api/gears_api/manager.py @@ -20,13 +20,12 @@ class BaseManager(metaclass=ABCMeta): """Converts a SQLAlchemy results proxy into a Schema instance""" pass - def raise_409(self, id:int): + def raise_409(self, id: int): """Raises a 409 HTTP error response in the event of Conflict""" raise HTTPError( HTTP_409, { "status": 409, - "message": f"Entity {self.__class__.__name__} with id: {id} already exists" - } - + "message": f"Entity {self.__class__.__name__} with id: {id} already exists", + }, ) diff --git a/services/gears_api/manage.py b/services/gears_api/manage.py index 2f7fcdb..5683368 100644 --- a/services/gears_api/manage.py +++ b/services/gears_api/manage.py @@ -47,7 +47,9 @@ def initdb(): """ Initialize database """ - click.echo("This feature has been commented out. Please use alembic to manage your database initialization and changes.") + click.echo( + "This feature has been commented out. Please use alembic to manage your database initialization and changes." + ) # from gears_api.db import Base # # def _init(engine_data: EngineData): diff --git a/services/gears_api/migrations/env.py b/services/gears_api/migrations/env.py index e0e6be3..9eb9ec5 100644 --- a/services/gears_api/migrations/env.py +++ b/services/gears_api/migrations/env.py @@ -1,7 +1,9 @@ """isort:skip_file """ import os -import sys; sys.path.append(os.path.join(os.path.abspath(os.path.dirname(__file__)), "..")) # noqa +import sys + +sys.path.append(os.path.join(os.path.abspath(os.path.dirname(__file__)), "..")) # noqa from alembic import context from gears_api.index import create_app @@ -18,4 +20,4 @@ def run_migrations_online(engine_data: EngineData): context.run_migrations() -app.injector.get_resolver().resolve(run_migrations_online)() \ No newline at end of file +app.injector.get_resolver().resolve(run_migrations_online)() diff --git a/services/gears_api/migrations/versions/dc04b852fef5_initial_commit.py b/services/gears_api/migrations/versions/dc04b852fef5_initial_commit.py index c2dbe0d..1d6d195 100644 --- a/services/gears_api/migrations/versions/dc04b852fef5_initial_commit.py +++ b/services/gears_api/migrations/versions/dc04b852fef5_initial_commit.py @@ -10,7 +10,7 @@ import sqlalchemy as sa # revision identifiers, used by Alembic. -revision = 'dc04b852fef5' +revision = "dc04b852fef5" down_revision = None branch_labels = None depends_on = None diff --git a/services/gears_api/setup.cfg b/services/gears_api/setup.cfg new file mode 100644 index 0000000..f1af57c --- /dev/null +++ b/services/gears_api/setup.cfg @@ -0,0 +1,10 @@ +[bumpversion] +current_version = 0.1.0 + +[bumpversion:file:setup.py] +search = version='{current_version}' +replace = {new_version} + +[bumpversion:file:gears_api/__init__.py] +search = __version__ = '{current_version}' +replace = {new_version} \ No newline at end of file diff --git a/services/gears_api/tests/conftest.py b/services/gears_api/tests/conftest.py index a95abeb..434310a 100644 --- a/services/gears_api/tests/conftest.py +++ b/services/gears_api/tests/conftest.py @@ -7,12 +7,14 @@ from gears_api.index import create_app def truncate_all_tables(session: Session): - table_names = session.execute(""" + table_names = session.execute( + """ select table_name from information_schema.tables where table_schema = 'public' and table_type = 'BASE TABLE' and table_name != 'alembic_version' - """) + """ + ) for (table_name,) in table_names: # "truncate" can deadlock so we use delete which is guaranteed not to. session.execute(f"delete from {table_name}") @@ -47,5 +49,7 @@ def load_component(app): def load(annotation): def loader(c: annotation): return c + return app.injector.get_resolver().resolve(loader)() + return load diff --git a/services/gears_api/tests/test_app_routes.py b/services/gears_api/tests/test_app_routes.py index 0595ef6..b95b616 100644 --- a/services/gears_api/tests/test_app_routes.py +++ b/services/gears_api/tests/test_app_routes.py @@ -16,8 +16,8 @@ def test_insert_todo(client): response = client.post("/todos", data=payload) content = response.json() assert response.status_code == 201 - assert type(content['id']) == int - assert content['todo'] == payload['todo'] + assert type(content["id"]) == int + assert content["todo"] == payload["todo"] def test_get_individual_todo_by_href(client): @@ -34,7 +34,9 @@ def test_update_todo(client): payload = {"todo": "sample app"} response = client.post("/todos", json=payload) todo = response.json() - update_response = client.patch("{}".format(todo.get("href")), json={"complete": True, "todo": "sample app"}) + update_response = client.patch( + "{}".format(todo.get("href")), json={"complete": True, "todo": "sample app"} + ) updated_todo = update_response.json() assert updated_todo["complete"] == True diff --git a/services/gears_api/tests/test_renders.py b/services/gears_api/tests/test_renders.py index ef2c8a5..141ca17 100644 --- a/services/gears_api/tests/test_renders.py +++ b/services/gears_api/tests/test_renders.py @@ -11,5 +11,5 @@ def test_extended_encoder_date_parsing(): def test_extended_encoder_decimal_casting(): json_renderer = ExtJSONRenderer() - test_decimal = Decimal('1.0') + test_decimal = Decimal("1.0") assert 1.0 == json_renderer.default(test_decimal)