·
Last changedVersion:
This version passed the hardening gate. Hardening updated the skill content and independently checked the resulting changes. Classified findings before hardening: 0. Classified findings closed: 0. Classified findings remaining: 0. Unclassified scanner findings remaining: 0. Review findings closed: 4. Review findings remaining: 1.
None
None
Expand | File | Group | Subtype | Severity | Status |
|---|
No findings available
0 findings
Design well-organized Python projects with clear module boundaries, explicit public interfaces, and maintainable directory structures. Good organization makes code discoverable and changes predictable.
__all__When reorganizing an existing codebase, first propose the target layout and the list of file moves and renames. Get the user's confirmation before moving or renaming anything. Then restructure in small, reviewable steps, update imports and packaging configuration, and run the project's tests after each step.
Group related code that changes together. A module should have a single, clear purpose.
Define what's public with __all__. Everything not listed is an internal implementation detail.
Prefer shallow directory structures. Add depth only for genuine sub-domains.
Apply naming and organization patterns uniformly across the project.
Each file should focus on a single concept or closely related set of functions. Consider splitting when a file:
__all__Define the public interface for every module. Unlisted members are internal implementation details.
Prefer minimal nesting. Deep hierarchies make imports verbose and navigation difficult.
Add sub-packages only when there's a genuine sub-domain requiring isolation.
Choose one approach and apply it consistently throughout the project.
Option A: Colocated Tests
Benefits: Tests live next to the code they verify. Easy to see coverage gaps.
Caution: colocated test files and their fixtures can end up in built and distributed packages. Exclude them in the build configuration in pyproject.toml. Keep real credentials and secrets out of test files. Prefer Option B for published libraries.
Option B: Parallel Test Directory
Benefits: Clean separation between production and test code. Standard for larger projects.
Use __init__.py to provide a clean public interface for package consumers.
Keep the version in a single place, usually pyproject.toml, or read it from the installed package metadata. That way the version cannot drift from a value hardcoded in the source, like the one shown here.
Consumers can then import directly from the package:
Organize code by architectural layer for clear separation of concerns.
Each layer should only depend on layers below it, never above.
For complex applications, organize by business domain rather than technical layer.
snake_case for all file and module names: user_repository.pyuser_repository.py not usr_repo.pyUserService in user_service.pyUse absolute imports for clarity and reliability:
Relative imports can break when modules are moved or reorganized.
One exception applies: relative imports are acceptable inside the __init__.py of a package when it re-exports its own submodules, as shown in Patterns 2 and 5. Imports across packages should stay absolute.
__all__ explicitly - Make public interfaces clear__init__.py of a packageGet started with chainctlchainctl skill install public/wshobson/python-project-structure:latest
Bring Chainguard's hardening pipeline to your first-party skills — custom rulesets, automated remediation, full audit trail.
skills.cgr.dev/public/github.com/wshobson/plugins/python-development/skills/python-project-structure:latest
MIT
HARDENING.md
LICENSE
SKILL.md