Skip to content

Commit ddcdff2

Browse files
committed
[ADD] implemented deleteproject operation & add mypy and isort, add type def
1 parent 0f24543 commit ddcdff2

File tree

9 files changed

+128
-16
lines changed

9 files changed

+128
-16
lines changed

pdm.lock

Lines changed: 49 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ dependencies = [
1212
"black>=24.10.0",
1313
"pre-commit>=4.0.1",
1414
"pytest-cov>=5.0.0",
15+
"mypy>=1.12.0",
16+
"isort>=5.13.2",
1517
]
1618
requires-python = ">=3.12"
1719
readme = "README.md"
@@ -32,3 +34,15 @@ distribution = true
3234
[tool.pytest.ini_options]
3335
testpaths = ["test"]
3436
python_files = "test_*.py"
37+
38+
[tool.mypy]
39+
strict = true
40+
41+
[[tool.mypy.overrides]]
42+
module = "fastapi_fastkit.cli"
43+
disable_error_code = ["func-returns-value"]
44+
45+
[[tool.mypy.overrides]]
46+
module = "fastapi_fastkit.core"
47+
ignore_missing_imports = true
48+
check_untyped_defs = false

scripts/format.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
set -x
3+
4+
# shellcheck disable=SC2046
5+
base_dir=$(dirname $(dirname $0))
6+
7+
black --config "${base_dir}/pyproject.toml" --check .
8+
black .

scripts/lint.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
set -x
3+
4+
# shellcheck disable=SC2046
5+
base_dir=$(dirname $(dirname $0))
6+
7+
isort --sp "${base_dir}/pyproject.toml" --check .
8+
9+
black --config "${base_dir}/pyproject.toml" --check .
10+
11+
mypy --config-file "${base_dir}/pyproject.toml" src

src/fastapi_fastkit/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
#
44
# @author bnbong
55
# --------------------------------------------------------------------------
6-
from cli import fastkit_cli
6+
from fastapi_fastkit.cli import fastkit_cli
77

88
fastkit_cli()

src/fastapi_fastkit/cli.py

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import os
99
import click
1010

11-
from typing import Union
11+
from typing import Union, Any
1212

1313
from logging import getLogger
1414

@@ -22,6 +22,7 @@
2222
from fastapi_fastkit.core.settings import FastkitConfig
2323
from fastapi_fastkit.core.exceptions import CLIExceptions, TemplateExceptions
2424
from fastapi_fastkit.utils.transducer import copy_and_convert_template
25+
from fastapi_fastkit.utils.inspector import delete_project
2526

2627

2728
logger = getLogger(__name__)
@@ -33,7 +34,7 @@
3334
REGEX = r"\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,7}\b"
3435

3536

36-
def validate_email(ctx, param, value):
37+
def validate_email(ctx: Context, param: Any, value: Any) -> Any:
3738
"""
3839
Check if the provided email is in a valid format.
3940
This will recursively loop until a valid email input entry is given.
@@ -131,7 +132,7 @@ def fastkit_cli(ctx: Context, debug: bool) -> Union["BaseCommand", None]:
131132

132133
setup_logging(settings=settings)
133134

134-
return
135+
return None
135136

136137

137138
@fastkit_cli.command()
@@ -239,8 +240,6 @@ def startproject(
239240

240241
copy_and_convert_template(target_template, project_dir, project_name)
241242

242-
# _new_user_local = os.path.join(user_local, template)
243-
244243
_inject_project_metadata(
245244
project_dir, project_name, author, author_email, description
246245
)
@@ -253,10 +252,34 @@ def startproject(
253252

254253

255254
@fastkit_cli.command()
255+
@click.argument("project_name")
256256
@click.pass_context
257-
def deleteproject(ctx: Context) -> None:
258-
# TODO : implement this
259-
pass
257+
def deleteproject(ctx: Context, project_name: str) -> None:
258+
settings = ctx.obj["settings"]
259+
260+
user_local = settings.USER_WORKSPACE
261+
project_dir = os.path.join(user_local, project_name)
262+
263+
if not os.path.exists(project_dir):
264+
click.echo(f"Error: Project '{project_name}' does not exist at '{user_local}'.")
265+
return
266+
267+
confirm = click.confirm(
268+
f"\nAre you sure you want to delete the project '{project_name}' at '{project_dir}'?",
269+
default=False,
270+
)
271+
if not confirm:
272+
click.echo("Project deletion aborted!")
273+
return
274+
275+
try:
276+
# TODO : adjust this
277+
delete_project(project_dir)
278+
click.echo(
279+
f"Project '{project_name}' has been successfully deleted from '{user_local}'."
280+
)
281+
except Exception as e:
282+
click.echo(f"Error during project deletion: {e}")
260283

261284

262285
@fastkit_cli.command()

src/fastapi_fastkit/core/settings.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212

1313
class FastkitConfig:
1414
# Overridable values
15-
FASTKIT_PROJECT_ROOT: str = None # default : None (will be overridden)
16-
FASTKIT_TEMPLATE_ROOT: str = None # default : None (will be overridden)
17-
LOG_FILE_PATH: str = None # default : None (will be overridden)
18-
USER_WORKSPACE: str = None # default : None (will be overridden)
15+
FASTKIT_PROJECT_ROOT: str = "" # default : None (will be overridden)
16+
FASTKIT_TEMPLATE_ROOT: str = "" # default : None (will be overridden)
17+
LOG_FILE_PATH: str = "" # default : None (will be overridden)
18+
USER_WORKSPACE: str = "" # default : None (will be overridden)
1919

2020
# Default Options
2121
DEBUG_MODE: bool = False
@@ -38,7 +38,7 @@ def __get_fastapi_fastkit_root() -> Path:
3838
return Path(__file__).parent.parent.parent.parent
3939

4040
@classmethod
41-
def __init__(cls):
41+
def __init__(cls) -> None:
4242
"""
4343
Initialize the configuration by performing important checks and setups.
4444
Override directories to correct position.

src/fastapi_fastkit/utils/inspector.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,9 @@
44
#
55
# @author bnbong
66
# --------------------------------------------------------------------------
7+
import shutil
8+
9+
10+
def delete_project(project_dir: str) -> None:
11+
# TODO : add checking step -> preventing 'template' folder deletion.
12+
shutil.rmtree(project_dir)

src/fastapi_fastkit/utils/transducer.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ def _convert_tpl_to_real_extension(file_path: str) -> str:
2626
return file_path
2727

2828

29-
def copy_and_convert_template(template_dir: str, target_dir: str, project_name: str = None) -> None:
29+
def copy_and_convert_template(
30+
template_dir: str, target_dir: str, project_name: str = ""
31+
) -> None:
3032
"""
3133
Copies all files from the template directory to the target directory,
3234
converting any files ending in `.*-tpl` during the copy process.

0 commit comments

Comments
 (0)