Skip to content

Commit

Permalink
Merge pull request #45 from bento-platform/lint/black
Browse files Browse the repository at this point in the history
lint: add black auto-formatter
  • Loading branch information
davidlougheed authored May 28, 2024
2 parents c2549b7 + f213a8d commit a369edf
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ jobs:
run: python -m pip install poetry
- name: Install dependencies
run: python -m poetry install --only dev
- name: Run black
run: python -m poetry run black --check bento_service_registry tests
- name: Run linter
run: python -m poetry run flake8 ./bento_service_registry ./tests
- name: Run type checker
Expand Down
3 changes: 2 additions & 1 deletion bento_service_registry/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def create_app(config_override: Callable[[], Config] | None = None) -> FastAPI:
authz_middleware.attach(app)

app.exception_handler(StarletteHTTPException)(
http_exception_handler_factory(get_logger(config_for_setup), authz_middleware))
http_exception_handler_factory(get_logger(config_for_setup), authz_middleware)
)
app.exception_handler(RequestValidationError)(validation_exception_handler_factory(authz_middleware))

return app
2 changes: 1 addition & 1 deletion bento_service_registry/bento_services_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async def get_bento_services_by_compose_id(config: ConfigDependency) -> BentoSer


async def get_bento_services_by_kind(
bento_services_by_compose_id: BentoServicesByComposeIDDependency
bento_services_by_compose_id: BentoServicesByComposeIDDependency,
) -> BentoServicesByKind:
services_by_kind: BentoServicesByKind = {}

Expand Down
3 changes: 2 additions & 1 deletion bento_service_registry/data_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ async def get_data_types_from_service(
async with http_session.get(urljoin(service_url_norm, "data-types"), headers=authz_header) as res:
if res.status != status.HTTP_200_OK:
logger.error(
f"Got non-200 response from data type service ({service_url=}): {res.status=}; body={await res.json()}")
f"Got non-200 response from data type service ({service_url=}): {res.status=}; body={await res.json()}"
)
return ()

dts: list[DataTypeWithServiceURL] = []
Expand Down
3 changes: 2 additions & 1 deletion bento_service_registry/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ async def get_service_by_id(
if service_data is None:
raise HTTPException(
status.HTTP_500_INTERNAL_SERVER_ERROR,
f"An internal error was encountered with service with ID {service_id}")
f"An internal error was encountered with service with ID {service_id}",
)

return service_data

Expand Down
13 changes: 8 additions & 5 deletions bento_service_registry/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ async def get_service(
# TypeError can happen if None is received
self._logger.error(
f"{service_info_url}: Encountered invalid response ({str(e)}) - {await r.text()} "
f"(Took {(datetime.now() - dt).total_seconds():.1f}s)")
f"(Took {(datetime.now() - dt).total_seconds():.1f}s)"
)

except asyncio.TimeoutError:
self._logger.error(f"Encountered timeout with {service_info_url}")
Expand All @@ -109,10 +110,12 @@ async def get_services(
service_info: GA4GHServiceInfo,
) -> tuple[dict, ...]:
if not self._co:
self._co = asyncio.gather(*(
self.get_service(authz_header, http_session, service_info, s)
for s in bento_services_by_kind.values()
))
self._co = asyncio.gather(
*(
self.get_service(authz_header, http_session, service_info, s)
for s in bento_services_by_kind.values()
)
)

service_list: list[dict | None] = await self._co
self._co = None
Expand Down
1 change: 1 addition & 0 deletions bento_service_registry/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

# TODO: py3.11(?): optional TypedDict props


# required props for chord_services.json entries
class BaseBentoService(TypedDict):
url_template: str
Expand Down
6 changes: 4 additions & 2 deletions bento_service_registry/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ async def get_workflows_from_service(
if res.status != status.HTTP_200_OK:
logger.error(
f"Got non-200 response from data type service ({service_url=}): {res.status=}; body={data}; "
f"took {time_taken:.1f}s")
f"took {time_taken:.1f}s"
)
return {}

logger.debug(f"{workflows_url}: took {time_taken:.1f}s")
Expand All @@ -70,7 +71,8 @@ async def get_workflows(
logger.debug("Collecting workflows from workflow-providing services")

workflow_services = [
s for s in services_tuple
s
for s in services_tuple
if (b := s.get("bento", {})).get("dataService", False) or b.get("workflowProvider", False)
]

Expand Down
59 changes: 58 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@ pytest-asyncio = "^0.23.6"
pytest-cov = "^4.1.0"
tox = "^4.15.0"
types-aiofiles = "^23.2.0"
black = "^24.4.2"

[tool.black]
line_length = 120
3 changes: 3 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def get_config_inner():
def client():
tgc = test_get_config(debug_mode=False)
from bento_service_registry.app import create_app

app = create_app(tgc)
yield TestClient(app)

Expand All @@ -43,12 +44,14 @@ def client():
def client_debug_mode():
tgc = test_get_config(debug_mode=True)
from bento_service_registry.app import create_app

app = create_app(tgc)
yield TestClient(app)


async def _service_info_fixt(config: Config):
from bento_service_registry.service_info import get_service_info

return await get_service_info(config, test_logger)


Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ allowlist_externals =
commands =
poetry install --sync
poetry run pytest -svv --cov=bento_service_registry --cov-branch {posargs}
poetry run black --check bento_service_registry tests
poetry run flake8 ./bento_service_registry ./tests
poetry run mypy bento_service_registry

0 comments on commit a369edf

Please sign in to comment.