Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove raising of path exists error in cli #50

Merged
merged 1 commit into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 18 additions & 22 deletions openeo_fastapi/cli.py
Original file line number Diff line number Diff line change
@@ -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,
)


Expand All @@ -18,61 +18,57 @@ 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"

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()
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
readme = "README.md"
Expand Down
Loading