Skip to content

Commit 338ed9e

Browse files
committed
fix: replace print statements with proper logging
- Remove ruff: noqa comment and fix properly - Add structured logging with clean output format - Replace all print() calls with logger.info() for proper code quality - Configure logging to output to stdout for user feedback
1 parent f5d4981 commit 338ed9e

File tree

1 file changed

+37
-28
lines changed

1 file changed

+37
-28
lines changed

setup_project.py

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env python3
2-
# ruff: noqa: T201
32
"""Setup a new Python project from the template.
43
54
This script copies template files from .opencode/templates/ to the project root,
@@ -14,12 +13,22 @@
1413
python setup_project.py detect-fields
1514
"""
1615

16+
import logging
1717
import shutil
18+
import sys
1819
from datetime import datetime
1920
from pathlib import Path
2021

2122
import fire
2223

24+
# Configure logging for user feedback
25+
logging.basicConfig(
26+
level=logging.INFO,
27+
format="%(message)s",
28+
handlers=[logging.StreamHandler(sys.stdout)],
29+
)
30+
logger = logging.getLogger(__name__)
31+
2332
TEMPLATES_DIR = Path(__file__).parent / ".opencode" / "templates"
2433
ROOT_DIR = Path(__file__).parent
2534

@@ -48,28 +57,28 @@ def copy_and_rename_package(src_name: str, dst_name: str) -> None:
4857
if dst_dir.exists():
4958
shutil.rmtree(dst_dir)
5059
shutil.copytree(src_dir, dst_dir, dirs_exist_ok=True)
51-
print(f"Copied package: {src_name} -> {dst_name}")
60+
logger.info("Copied package: %s -> %s", src_name, dst_name)
5261

5362
for py_file in dst_dir.rglob("*.py"):
5463
content = py_file.read_text(encoding="utf-8")
5564
content = content.replace(src_name, dst_name)
5665
py_file.write_text(content, encoding="utf-8")
57-
print(f" Renamed in: {py_file.relative_to(ROOT_DIR)}")
66+
logger.info(" Renamed in: %s", py_file.relative_to(ROOT_DIR))
5867

5968

6069
def detect_fields() -> None:
6170
"""Show what fields would need changing."""
6271
today = datetime.now().strftime("%Y%m%d")
63-
print("\nFields that would need to be changed in templates:")
64-
print("-" * 50)
65-
print(f" 1. GitHub Username: {ORIGINAL_GITHUB_USERNAME}")
66-
print(f" 2. Project Name: {ORIGINAL_PROJECT_NAME}")
67-
print(" 3. Project Description: 'Python template...'")
68-
print(f" 4. Author Name: {ORIGINAL_AUTHOR_NAME}")
69-
print(f" 5. Author Email: {ORIGINAL_AUTHOR_EMAIL}")
70-
print(f" 6. Package Name: {ORIGINAL_PACKAGE_NAME}")
71-
print(f" 7. Module Name: {ORIGINAL_MODULE_NAME}")
72-
print(f" 8. Version: starts with 0.1.{today}")
72+
logger.info("\nFields that would need to be changed in templates:")
73+
logger.info("-" * 50)
74+
logger.info(" 1. GitHub Username: %s", ORIGINAL_GITHUB_USERNAME)
75+
logger.info(" 2. Project Name: %s", ORIGINAL_PROJECT_NAME)
76+
logger.info(" 3. Project Description: 'Python template...'")
77+
logger.info(" 4. Author Name: %s", ORIGINAL_AUTHOR_NAME)
78+
logger.info(" 5. Author Email: %s", ORIGINAL_AUTHOR_EMAIL)
79+
logger.info(" 6. Package Name: %s", ORIGINAL_PACKAGE_NAME)
80+
logger.info(" 7. Module Name: %s", ORIGINAL_MODULE_NAME)
81+
logger.info(" 8. Version: starts with 0.1.%s", today)
7382

7483

7584
def copy_directory_structure(src_dir: Path, dst_dir: Path, replacements: dict) -> None:
@@ -92,11 +101,11 @@ def copy_directory_structure(src_dir: Path, dst_dir: Path, replacements: dict) -
92101
# Remove .template extension
93102
dst_path = dst_path.with_suffix("")
94103
dst_path.write_text(content, encoding="utf-8")
95-
print(f"Created: {dst_path.relative_to(ROOT_DIR)}")
104+
logger.info("Created: %s", dst_path.relative_to(ROOT_DIR))
96105
else:
97106
# Copy non-template files as-is
98107
shutil.copy2(item, dst_path)
99-
print(f"Copied: {dst_path.relative_to(ROOT_DIR)}")
108+
logger.info("Copied: %s", dst_path.relative_to(ROOT_DIR))
100109

101110

102111
def run(
@@ -129,12 +138,12 @@ def run(
129138
"Python template with some awesome tools to quickstart any Python project"
130139
] = project_description
131140

132-
print(f"\nSetting up project: {project_name}")
133-
print(f"Description: {project_description}")
134-
print(f"GitHub: github.com/{github_username}/{project_name}")
135-
print(f"Package: {package_name}")
136-
print(f"Module: {module_name}")
137-
print()
141+
logger.info("\nSetting up project: %s", project_name)
142+
logger.info("Description: %s", project_description)
143+
logger.info("GitHub: github.com/%s/%s", github_username, project_name)
144+
logger.info("Package: %s", package_name)
145+
logger.info("Module: %s", module_name)
146+
logger.info("")
138147

139148
# Process root-level template files
140149
for template_file in TEMPLATES_DIR.glob("*.template"):
@@ -144,7 +153,7 @@ def run(
144153
dst_name = template_file.stem
145154
dst_path = ROOT_DIR / dst_name
146155
dst_path.write_text(content, encoding="utf-8")
147-
print(f"Created: {dst_path.relative_to(ROOT_DIR)}")
156+
logger.info("Created: %s", dst_path.relative_to(ROOT_DIR))
148157

149158
# Process .github directory structure
150159
github_templates_dir = TEMPLATES_DIR / ".github"
@@ -156,12 +165,12 @@ def run(
156165
if package_name != ORIGINAL_PACKAGE_NAME:
157166
copy_and_rename_package(ORIGINAL_PACKAGE_NAME, package_name)
158167

159-
print("\nProject setup complete!")
160-
print("\nNext steps:")
161-
print(" 1. Review and update README.md with project-specific content")
162-
print(" 2. Run: uv venv && uv pip install -e '.[dev]'")
163-
print(" 3. Run: task test && task lint && task static-check")
164-
print(
168+
logger.info("\nProject setup complete!")
169+
logger.info("\nNext steps:")
170+
logger.info(" 1. Review and update README.md with project-specific content")
171+
logger.info(" 2. Run: uv venv && uv pip install -e '.[dev]'")
172+
logger.info(" 3. Run: task test && task lint && task static-check")
173+
logger.info(
165174
" 4. Initialize secrets baseline: uv run detect-secrets scan --baseline .secrets.baseline"
166175
)
167176

0 commit comments

Comments
 (0)