diff --git a/openeo_fastapi/cli.py b/openeo_fastapi/cli.py index eeaded4..f63ab88 100644 --- a/openeo_fastapi/cli.py +++ b/openeo_fastapi/cli.py @@ -1,15 +1,15 @@ """CLI to support quick initialisation of the project source directory.""" +from pathlib import Path + import click import fsspec - from alembic import command from alembic.config import Config -from pathlib import Path from openeo_fastapi.templates import ( get_app_template, get_models_template, - get_revision_template + get_revision_template, ) @@ -18,26 +18,24 @@ def cli(): """Defining group for executor CLI.""" pass + @click.command() -@click.option('--path', default=None, type=str) +@click.option("--path", default=None, type=str) def new(path): """Initialize a source directory for an openeo_fastapi api project at the specified location.""" fs = fsspec.filesystem(protocol="file") - + if path: path = Path(path) - if not path.exists(): - raise ValueError("Provided path does not exist.") else: path = Path(fs.get_mapper("").root) - + openeo_dir = path db_dir = openeo_dir / "psql" init_file = openeo_dir / "__init__.py" app_file = openeo_dir / "app.py" revise_file = openeo_dir / "revise.py" - alembic_dir = db_dir / "alembic" alembic_models = db_dir / "models.py" alembic_ini = db_dir / "alembic.ini" @@ -45,34 +43,32 @@ def new(path): fs.mkdir(openeo_dir) fs.mkdir(db_dir) - + fs.mkdir(alembic_dir) fs.touch(alembic_models) - with fs.open(alembic_models, 'w') as f: + with fs.open(alembic_models, "w") as f: f.write(get_models_template()) - + alembic_cfg = Config(alembic_ini) - - command.init( - alembic_cfg, - directory=alembic_dir - ) - + + command.init(alembic_cfg, directory=alembic_dir) + fs.touch(init_file) - + fs.touch(app_file) - with fs.open(app_file, 'w') as f: + with fs.open(app_file, "w") as f: f.write(get_app_template()) revise_file = openeo_dir / "revise.py" fs.touch(revise_file) - with fs.open(revise_file, 'w') as f: + with fs.open(revise_file, "w") as f: f.write(get_revision_template()) pass + cli.add_command(new) -if __name__ == '__main__': +if __name__ == "__main__": cli() diff --git a/pyproject.toml b/pyproject.toml index 05f43a2..6bc98f4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "openeo-fastapi" -version = "2024.5.1" +version = "2024.5.2" description = "FastApi implementation conforming to the OpenEO Api specification." authors = ["Sean Hoyal "] readme = "README.md"