Skip to content
Closed
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
16 changes: 11 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,17 @@ init: ## Initialize project (usage: make init name=my-project description="my de
echo "Usage: make init name=<project_name> description=<project_description>"; \
exit 1; \
fi
@echo "$(YELLOW)πŸš€ Initializing project $(name)...$(RESET)"
@sed -i.bak "s/name = \"python-template\"/name = \"$(name)\"/" pyproject.toml && rm pyproject.toml.bak
@sed -i.bak "s/description = \"Add your description here\"/description = \"$(description)\"/" pyproject.toml && rm pyproject.toml.bak
@sed -i.bak "s/# Python-Template/# $(name)/" README.md && rm README.md.bak
@sed -i.bak "s/<b>Opinionated Python project stack. πŸ”‹ Batteries included. <\/b>/<b>$(description)<\/b>/" README.md && rm README.md.bak
@CURRENT_NAME=$$(sed -n 's/^name = "\(.*\)"/\1/p' pyproject.toml | head -1); \
CURRENT_DESC=$$(sed -n 's/^description = "\(.*\)"/\1/p' pyproject.toml | head -1); \
Comment on lines +46 to +47
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Silent failure when extraction returns empty

If pyproject.toml is missing, or if either field isn't present in the exact format ^name = "…" (e.g., TOML allows name="…" without spaces), CURRENT_NAME and/or CURRENT_DESC will be empty strings. The downstream sed commands will then attempt to match name = "" or description = "", find nothing, exit 0, and leave the files silently unchanged β€” with no indication to the user that the rename failed.

Consider adding an explicit guard after each extraction:

CURRENT_NAME=$$(sed -n 's/^name = "\(.*\)"/\1/p' pyproject.toml | head -1); \
if [ -z "$$CURRENT_NAME" ]; then echo "$(RED)Error: could not read current name from pyproject.toml$(RESET)"; exit 1; fi; \
CURRENT_DESC=$$(sed -n 's/^description = "\(.*\)"/\1/p' pyproject.toml | head -1); \
if [ -z "$$CURRENT_DESC" ]; then echo "$(RED)Error: could not read current description from pyproject.toml$(RESET)"; exit 1; fi; \
Prompt To Fix With AI
This is a comment left during a code review.
Path: Makefile
Line: 46-47

Comment:
**Silent failure when extraction returns empty**

If `pyproject.toml` is missing, or if either field isn't present in the exact format `^name = "…"` (e.g., TOML allows `name="…"` without spaces), `CURRENT_NAME` and/or `CURRENT_DESC` will be empty strings. The downstream sed commands will then attempt to match `name = ""` or `description = ""`, find nothing, exit 0, and leave the files silently unchanged β€” with no indication to the user that the rename failed.

Consider adding an explicit guard after each extraction:

```
CURRENT_NAME=$$(sed -n 's/^name = "\(.*\)"/\1/p' pyproject.toml | head -1); \
if [ -z "$$CURRENT_NAME" ]; then echo "$(RED)Error: could not read current name from pyproject.toml$(RESET)"; exit 1; fi; \
CURRENT_DESC=$$(sed -n 's/^description = "\(.*\)"/\1/p' pyproject.toml | head -1); \
if [ -z "$$CURRENT_DESC" ]; then echo "$(RED)Error: could not read current description from pyproject.toml$(RESET)"; exit 1; fi; \
```

How can I resolve this? If you propose a fix, please make it concise.

ESC_NAME=$$(printf '%s\n' "$$CURRENT_NAME" | sed 's/[.[\*^$$\/]/\\&/g'); \
ESC_DESC=$$(printf '%s\n' "$$CURRENT_DESC" | sed 's/[.[\*^$$\/]/\\&/g'); \
ESC_NEW_NAME=$$(printf '%s\n' "$(name)" | sed 's/[&/\\]/\\&/g'); \
ESC_NEW_DESC=$$(printf '%s\n' "$(description)" | sed 's/[&/|\\]/\\&/g'); \
echo "$(YELLOW)πŸš€ Initializing project $(name)...$(RESET)"; \
sed -i.bak "s/name = \"$$ESC_NAME\"/name = \"$$ESC_NEW_NAME\"/" pyproject.toml && rm pyproject.toml.bak; \
sed -i.bak "s/description = \"$$ESC_DESC\"/description = \"$$ESC_NEW_DESC\"/" pyproject.toml && rm pyproject.toml.bak; \
sed -i.bak "1s/^# .*/# $$ESC_NEW_NAME/" README.md && rm README.md.bak; \
sed -i.bak "1,10s|<b>.*</b>|<b>$$ESC_NEW_DESC</b>|" README.md && rm README.md.bak
@echo "$(GREEN)βœ… Updated project name and description.$(RESET)"

banner: check_uv ## Generate project banner image
Expand Down
6 changes: 3 additions & 3 deletions common/global_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ class Config(BaseSettings):
default_factory=lambda: os.getenv("GITHUB_ACTIONS") != "true"
)
running_on: str = Field(
default_factory=lambda: "πŸ–₯️ local"
if os.getenv("GITHUB_ACTIONS") != "true"
else "☁️ CI"
default_factory=lambda: (
"πŸ–₯️ local" if os.getenv("GITHUB_ACTIONS") != "true" else "☁️ CI"
)
)

@classmethod
Expand Down
Loading