Skip to content

Commit 97bbcf1

Browse files
authored
fix: delete unused files and folders (#13)
1 parent e3dbabf commit 97bbcf1

8 files changed

Lines changed: 50 additions & 48 deletions

File tree

fastapi_forge/project_io.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def _load_project_to_dict(self) -> dict[str, Any]:
5757

5858
def load_project_spec(self) -> ProjectSpec:
5959
project_dict = self._load_project_to_dict()
60-
models = [Model(**model) for model in project_dict.get("models", [])]
60+
models = [Model(**model) for model in project_dict.get("models", []) or []]
6161
project_dict.pop("models")
6262
return ProjectSpec(**project_dict, models=models)
6363

fastapi_forge/template/cookiecutter.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@
1717
"use_rabbitmq": {
1818
"default": true
1919
},
20-
"create_routes": {
21-
"default": true
22-
},
23-
"create_tests": {
24-
"default": true
25-
},
2620
"models": {
2721
"models": []
2822
},

fastapi_forge/template/hooks/post_gen_project.py

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,48 +7,20 @@
77

88

99
def git_init() -> None:
10-
subprocess.run(
11-
[
12-
"git",
13-
"init",
14-
]
15-
)
16-
17-
subprocess.run(
18-
[
19-
"git",
20-
"add",
21-
".",
22-
]
23-
)
10+
subprocess.run(["git", "init"])
11+
subprocess.run(["git", "add", "."])
2412

2513

2614
def uv_init() -> None:
27-
subprocess.run(
28-
[
29-
"uv",
30-
"lock",
31-
]
32-
)
15+
subprocess.run(["uv", "lock"])
3316

3417

3518
def lint() -> None:
36-
subprocess.run(
37-
[
38-
"make",
39-
"lint",
40-
]
41-
)
19+
subprocess.run(["make", "lint"])
4220

4321

4422
def make_env() -> None:
45-
subprocess.run(
46-
[
47-
"cp",
48-
".env.example",
49-
".env",
50-
]
51-
)
23+
subprocess.run(["cp", ".env.example", ".env"])
5224

5325

5426
def _get_delete_flagged() -> tuple[list[str], list[str]]:
@@ -80,6 +52,37 @@ def _get_delete_flagged() -> tuple[list[str], list[str]]:
8052
return files, folders
8153

8254

55+
def delete_empty_init_folders(root_dir: str = "src") -> None:
56+
"""Delete folders that only contain empty __init__.py files."""
57+
for dirpath, dirnames, filenames in os.walk(root_dir, topdown=False):
58+
# Skip the root directory itself
59+
if dirpath == root_dir:
60+
continue
61+
62+
if set(filenames) == {"__init__.py"} and not dirnames:
63+
init_file = os.path.join(dirpath, "__init__.py")
64+
65+
try:
66+
with open(init_file, "r") as f:
67+
content = f.read()
68+
has_code = any(
69+
line.strip() and not line.strip().startswith("#")
70+
for line in content.splitlines()
71+
)
72+
if "__all__ = []" in content:
73+
print(45747457745)
74+
else:
75+
print(123123123)
76+
if not has_code:
77+
os.remove(init_file)
78+
os.rmdir(dirpath)
79+
logger.info(f"Deleted empty package: {dirpath}")
80+
else:
81+
logger.info(f"Keeping package with code: {dirpath}")
82+
except OSError as exc:
83+
logger.info(f"Error processing package {dirpath}: {exc}")
84+
85+
8386
def cleanup():
8487
files, folders = _get_delete_flagged()
8588

@@ -97,6 +100,8 @@ def cleanup():
97100
except OSError as exc:
98101
logger.info(f"Error deleting folder {folder_path}: {exc}")
99102

103+
delete_empty_init_folders()
104+
100105

101106
if __name__ == "__main__":
102107
cleanup()

fastapi_forge/template/{{cookiecutter.project_name}}/forge-config.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ config:
2121
- src/dtos/auth_dtos.py
2222
- src/routes/auth_routes.py
2323
- src/utils/auth_utils.py
24+
- src/constants.py
2425

2526
use_redis:
2627
value: {{cookiecutter.use_redis | lower}}
@@ -33,3 +34,5 @@ config:
3334
type: bool
3435
paths:
3536
- src/services/rabbitmq
37+
- src/routes/demo_routes.py
38+

fastapi_forge/template/{{cookiecutter.project_name}}/pyproject.toml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
[project]
2+
name = "{{cookiecutter.project_name}}"
3+
version = "0.1.0"
4+
description = "Add your description here"
5+
readme = "README.md"
6+
requires-python = ">=3.12"
27
dependencies = [
38
"fastapi>=0.115.8",
49
"uvicorn>=0.34.0",
@@ -30,11 +35,7 @@ dependencies = [
3035
{%- if cookiecutter.use_rabbitmq -%}
3136
"aio-pika>=9.5.5",
3237
{%- endif %}
33-
]name = "{{cookiecutter.project_name}}"
34-
version = "0.1.0"
35-
description = "Add your description here"
36-
readme = "README.md"
37-
requires-python = ">=3.12"
38+
]
3839

3940
[tool.pytest.ini_options]
4041
env = [
@@ -63,6 +64,7 @@ ignore = [
6364
#### specific rules
6465
"A001",
6566
"A002",
67+
"ARG001",
6668
"B904",
6769
"BLE001",
6870
"D100",

fastapi_forge/template/{{cookiecutter.project_name}}/src/routes/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
from src.routes.health_routes import router as health_router
2-
{% if cookiecutter.create_routes %}
32
{% for model in cookiecutter.models.models if model.metadata.create_endpoints -%}
43
from src.routes.{{ model.name }}_routes import router as {{ model.name }}_router
54
{% endfor %}
6-
{% endif %}
75
{% if cookiecutter.use_builtin_auth %}
86
from src.routes.auth_routes import router as auth_router
97
{% endif %}

fastapi_forge/template/{{cookiecutter.project_name}}/tests/unit_tests/__init__.py

Whitespace-only changes.

uv.lock

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

0 commit comments

Comments
 (0)