This document provides guidelines for coding agents (such as yourself) working in this repository. It outlines commands for building, linting, and testing, as well as code style conventions to ensure consistency and quality.
Always use Context7 MCP when I need library/API documentation, code generation, setup or configuration steps without me having to explicitly ask.
This project is a Python-based CLI tool. There is no compilation step, but we use tools for linting and testing.
- Python 3.8+ required (3.11+ recommended for built-in
tomllib). - Install dependencies:
pip install -r requirements.txt(if present; otherwise, core dependencies liketomlifor Python <3.11). - For linting: Install
flake8,black,isort,mypy(e.g.,pip install flake8 black isort mypy).
- No build required: Run scripts directly with
python. - Example:
python server_pack_builder.py --source mods --destination server_mods
- Full Lint:
flake8 .(checks style, errors, complexity). - Format Code:
black .(auto-format Python files). - Sort Imports:
isort .(organize import statements). - Type Check:
mypy .(static type analysis; run after formatting). - Combined Lint+Format:
black . && isort . && flake8 . && mypy .
- Use
pytestfor unit tests (install viapip install pytest). - Run All Tests:
pytest - Run Tests in Verbose Mode:
pytest -v - Run a Single Test:
pytest tests/test_file.py::test_function_name(e.g.,pytest tests/test_mod_filter.py::test_fabric_client_only) - Run Tests with Coverage:
pytest --cov=server_pack_builder --cov-report=html - Run Specific Module Tests:
pytest tests/ -k "fabric"(filters tests by keyword). - If no tests exist yet, create them in a
tests/directory usingpytestconventions (e.g.,test_*.pyfiles).
- For automated checks, run:
black . && isort . && flake8 . && mypy . && pytest - Ensure all commands pass before committing.
Follow PEP 8 (Python Enhancement Proposal 8) as the baseline, with additions for this project. Aim for readable, maintainable, and type-safe code. Use tools like black and isort for enforcement.
- Write code for humans first: Prioritize clarity over brevity.
- Use descriptive names; avoid abbreviations unless widely understood (e.g.,
jarfor JAR file is acceptable). - Keep functions short (under 50 lines); break into smaller helpers if needed.
- Add docstrings to all public functions/classes using Google-style (brief description + args/returns).
- Comments: Explain why (not what), especially for complex logic. Avoid redundant comments.
- Logging: Use
loggingmodule for output; avoidprintin production code. - Security: Never hardcode secrets; validate inputs to prevent path traversal (e.g., use
os.path.joinsafely).
- Use absolute imports:
from modpacktoserver.utils import helper(notfrom .utils). - Group imports: Standard library, third-party, local (separated by blank lines).
- Use
isortto sort alphabetically within groups. - Avoid wildcard imports (
from module import *). - Lazy imports in functions if needed for performance.
- Line length: 88 characters (Black default).
- Indentation: 4 spaces (never tabs).
- Blank lines: 1 between functions/classes, 2 between top-level definitions.
- Trailing commas: Always in multi-line structures for consistency.
- String quotes: Double quotes for consistency (e.g.,
"hello"), single for contractions (e.g.,don't). - Use
blackto auto-format; do not manually adjust spacing.
- Use type hints everywhere: For functions, variables, and classes.
- Import from
typing:List,Dict,Optional,Tuple, etc. - Enable
mypystrict mode if possible (inmypy.inior pyproject.toml). - Avoid
Any; use unions or generics instead. - Example:
def process_mods(mods: List[str]) -> Dict[str, bool]:
- Variables/Functions:
snake_case(e.g.,is_client_only). - Constants:
UPPER_SNAKE_CASE(e.g.,DEFAULT_TIMEOUT = 120). - Classes:
PascalCase(e.g.,ModProcessor). - Modules:
snake_case(e.g.,mod_filter.py). - Private: Prefix with
_(e.g.,_helper_function). - Boolean variables: Start with
is_,has_,can_(e.g.,is_fabric_mod). - Avoid single-letter names except in loops (e.g.,
for mod in mods:).
- Use exceptions over return codes for errors.
- Catch specific exceptions (e.g.,
FileNotFoundError, notException). - Provide meaningful error messages; log at appropriate levels (
errorfor fatal,warningfor recoverable). - Use
try/except/else/finallyblocks; avoid bareexcept. - For CLI tools, exit with codes: 0 (success), 1 (error).
- Example: Raise
ValueErrorfor invalid inputs; handle at top level.
- Functions: Pure where possible; side effects in docstrings.
- Classes: Use for stateful logic (e.g., a
ModPackBuilderclass if expanded). - Avoid global state; pass dependencies explicitly.
- Use
@staticmethodor@classmethodfor utility methods.
- Main script:
server_pack_builder.py(entry point). - Tests:
tests/directory withtest_*.pyfiles mirroring source structure. - Config: Use
pyproject.tomlorsetup.cfgfor tool configs (e.g., Black, Flake8). - Keep flat structure until >10 files.
- DRY (Don't Repeat Yourself): Extract common logic into functions.
- SOLID Principles: Single responsibility per function/class.
- Testing: Write tests first (TDD); cover happy path, edge cases, and errors.
- Performance: Profile with
cProfileif needed; avoid premature optimization. - Dependencies: Minimize; pin versions in
requirements.txt. - Git: Commit often; use conventional commits (e.g.,
feat: add forge support).
- This is a CLI tool for Minecraft mod filtering; keep it simple and CLI-focused for future GUI integration.
- Handle JAR files safely: Use
zipfilefor reading; validate paths. - Extensibility: Design for easy addition of new mod loaders (e.g., via strategy pattern).
No Cursor rules found (.cursor/rules/ or .cursorrules).
No Copilot rules found (.github/copilot-instructions.md).
- PEP 8: https://peps.python.org/pep-0008/
- Black: https://black.readthedocs.io/
- MyPy: https://mypy.readthedocs.io/
- Pytest: https://docs.pytest.org/