Add CLI script to gridify all cities

- reorganize `urban_meal_delivery.console` into a sub-package
- move `tests.db.conftest` fixtures into `tests.conftest`
  => some integration tests regarding CLI scripts need a database
- add `urban_meal_delivery.console.decorators.db_revision` decorator
  to ensure the database is at a certain state before a CLI script runs
- refactor the `urban_meal_delivery.db.grids.Grid.gridify()` constructor:
  - bug fix: even empty `Pixel`s end up in the database temporarily
    => create `Pixel` objects only if an `Address` is to be assigned
       to it
  - streamline code and docstring
  - add further test cases
This commit is contained in:
Alexander Hess 2021-01-06 16:17:05 +01:00
commit 54ff377579
Signed by: alexander
GPG key ID: 344EA5AB10D868E0
15 changed files with 372 additions and 160 deletions

View file

@ -0,0 +1,37 @@
"""The entry point for all CLI scripts in the project."""
from typing import Any
import click
from click import core as cli_core
import urban_meal_delivery
def show_version(ctx: cli_core.Context, _param: Any, value: bool) -> None:
"""Show the package's version."""
# If --version / -V is NOT passed in,
# continue with the command.
if not value or ctx.resilient_parsing:
return
# Mimic the colors of `poetry version`.
pkg_name = click.style(urban_meal_delivery.__pkg_name__, fg='green') # noqa:WPS609
version = click.style(urban_meal_delivery.__version__, fg='blue') # noqa:WPS609
# Include a warning for development versions.
warning = click.style(' (development)', fg='red') if '.dev' in version else ''
click.echo(f'{pkg_name}, version {version}{warning}')
ctx.exit()
@click.group()
@click.option(
'--version',
'-V',
is_flag=True,
callback=show_version,
is_eager=True,
expose_value=False,
)
def entry_point() -> None:
"""The urban-meal-delivery research project."""