mafia/pythonrules icon
public
Published on 6/9/2025
PythonRules

PythonRules

Rules

Build & Development Commands

Use virtual environments (e.g., venv or virtualenv) to isolate project dependencies. Manage dependencies with requirements.txt or modern tools like Poetry via pyproject.toml. Automate build and deployment commands using scripts (Makefile, bash scripts) or CI/CD pipelines. Utilize tools like Sphinx for automated documentation generation. For projects with compiled extensions (e.g., Cython), run appropriate build commands such as python setup.py build_ext --inplace. Ensure all development commands are clearly documented and easily repeatable.

Testing Guidelines

Employ pytest or unittest frameworks for writing and executing tests. Ensure all new features are accompanied by unit tests with at least 80% code coverage. Tests should be isolated, independent, and avoid reliance on external resources without mocks. Integrate automated test execution in CI/CD workflows on every commit or pull request. Cover both positive and negative test cases comprehensively. For integration tests, use isolated environments such as test databases or mock services.

Code Style & Guidelines

Adhere strictly to PEP 8 as the baseline style guide. Use meaningful and descriptive names for variables, functions, and classes. Document all public methods and classes with docstrings, preferably in reStructuredText or Google Style formats. Avoid code duplication by applying DRY and SOLID design principles. Leverage Python 3.6+ type annotations to enhance readability and support static analysis. Prioritize clean, readable, and efficient code, favoring simplicity and maintainability. Regularly perform code reviews to ensure consistent adherence to standards.

Documentation Guidelines

Maintain comprehensive, up-to-date, and clear documentation. Utilize automated documentation generation tools such as Sphinx with autodoc extensions. Document all modules, classes, and functions with usage examples where applicable. Include dependency descriptions, environment requirements, and detailed installation instructions. Provide clear guides for running, testing, and deploying the project. Version documentation alongside the source code to maintain consistency.