From b0bcb0c2ecdf86757e8aa3209188cbc52cb45e2d Mon Sep 17 00:00:00 2001 From: Pymetheus Date: Tue, 16 Jun 2026 20:37:46 +0200 Subject: [PATCH] refactor: rename utils package to core and update refs Move package_name/utils -> package_name/core (__init__.py, config.py, logger.py) and update all references. Adjust imports in src/package_name/main.py and tests, and update docs (CHECKLIST.md, INSTRUCTIONS.md) to reference the new core module. This standardizes the utilities package name. --- docs/CHECKLIST.md | 2 +- docs/INSTRUCTIONS.md | 8 ++++---- src/package_name/{utils => core}/__init__.py | 0 src/package_name/{utils => core}/config.py | 0 src/package_name/{utils => core}/logger.py | 0 src/package_name/main.py | 4 ++-- tests/test_config.py | 2 +- tests/test_logger.py | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) rename src/package_name/{utils => core}/__init__.py (100%) rename src/package_name/{utils => core}/config.py (100%) rename src/package_name/{utils => core}/logger.py (100%) diff --git a/docs/CHECKLIST.md b/docs/CHECKLIST.md index a53a489..76b0592 100644 --- a/docs/CHECKLIST.md +++ b/docs/CHECKLIST.md @@ -81,7 +81,7 @@ Otherwise, delete the commented-out lines. ### Configuration Management - [ ] **USER:** Rename `.config/.env.example` to `.config/.env.dev` and update required secrets. - [ ] **USER:** Update required application settings in `.config/config.dev.toml`. -- [ ] **USER:** Update values to match your `.env.dev` and `.config/config.dev.toml` settings in `src//utils/config.py`. +- [ ] **USER:** Update values to match your `.env.dev` and `.config/config.dev.toml` settings in `src//core/config.py`. ### Project Documents - [ ] **USER:** Delete `.gitkeep` in `data/`, `notebooks/` and `res/` if applicable, empty directories will disappear from GitHub. diff --git a/docs/INSTRUCTIONS.md b/docs/INSTRUCTIONS.md index 0372693..3e008af 100644 --- a/docs/INSTRUCTIONS.md +++ b/docs/INSTRUCTIONS.md @@ -98,7 +98,7 @@ python-project-blueprint/ ├── res/ # Static resources (images, etc.) ├── src/ │ └── package_name # Core logic -│ ├── utils/ # Shared utilities +│ ├── core/ # Core utilities │ │ ├── __init__.py │ │ ├── config.py │ │ └── logger.py @@ -135,7 +135,7 @@ strict naming conventions are enforced. This directory orchestrates the application's configuration using a **Layered Configuration Strategy**. This ensures a clean separation between structural application settings (TOML) and sensitive credentials (.env). -The configuration loading logic (found in `src/package_name/utils/config.py`) follows this hierarchy, where lower layers override upper ones: +The configuration loading logic (found in `src/package_name/core/config.py`) follows this hierarchy, where lower layers override upper ones: 1. **Pydantic Defaults:** Defined in the code (failsafe values). 2. **`config.{APP_ENV}.toml`:** Structural configuration (ports, hosts, feature flags). **Committed to Git.** @@ -179,7 +179,7 @@ This directory is strictly ignored by Git to prevent accidental leakage of logs, - **`mypy_cache/`**: Stores incremental type-checking data to significantly speed up subsequent `mypy` runs by only analyzing changed files. ### Advanced Logging Features -The logger (configured in `src/package_name/utils/logger.py`) includes several production-grade processors: +The logger (configured in `src/package_name/core/logger.py`) includes several production-grade processors: * **Security Masking:** An automated `mask_sensitive_data` processor scans log events for keys like `password` and replaces them with `********` to prevent credential leakage. * **Environment Context:** Every log entry is automatically tagged with the current `APP_ENV` via a dedicated processor, making it easy to filter logs. @@ -486,7 +486,7 @@ By using the **src-layout**, we ensure that the code is only importable when pro The internal structure follows a modular design to keep the source code of your application organized: * **`main.py`**: The central entry point for the application. It orchestrates the startup, including configuration loading and logger initialization. -* **`utils/`**: A dedicated subdirectory for utilities: +* **`core/`**: A dedicated subdirectory for utilities: * **`config.py`**: Contains the Pydantic-based configuration logic that implements the layered loading strategy. * **`logger.py`**: Defines the `structlog` integrated with the standard `logging` module, including security masking. diff --git a/src/package_name/utils/__init__.py b/src/package_name/core/__init__.py similarity index 100% rename from src/package_name/utils/__init__.py rename to src/package_name/core/__init__.py diff --git a/src/package_name/utils/config.py b/src/package_name/core/config.py similarity index 100% rename from src/package_name/utils/config.py rename to src/package_name/core/config.py diff --git a/src/package_name/utils/logger.py b/src/package_name/core/logger.py similarity index 100% rename from src/package_name/utils/logger.py rename to src/package_name/core/logger.py diff --git a/src/package_name/main.py b/src/package_name/main.py index 2de60b2..11a30c4 100644 --- a/src/package_name/main.py +++ b/src/package_name/main.py @@ -10,8 +10,8 @@ import structlog -from package_name.utils.config import Settings -from package_name.utils.logger import setup_logging +from package_name.core.config import Settings +from package_name.core.logger import setup_logging logger: structlog.stdlib.BoundLogger = structlog.get_logger(__name__) diff --git a/tests/test_config.py b/tests/test_config.py index 511fb82..852ed42 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -1,7 +1,7 @@ import tomllib from unittest.mock import MagicMock, patch -from src.package_name.utils.config import Settings +from src.package_name.core.config import Settings def test_settings_load_from_toml(clean_env): diff --git a/tests/test_logger.py b/tests/test_logger.py index 05022f6..3725283 100644 --- a/tests/test_logger.py +++ b/tests/test_logger.py @@ -3,7 +3,7 @@ import structlog -from src.package_name.utils.logger import setup_logging +from src.package_name.core.logger import setup_logging def test_logging_masking_and_env(capsys):