Development Standards
This document outlines the development standards and practices for contributing to PC2Products.
Coding Standards
When writing code, follow PEP8 (style guide) and PEP257 (docstring conventions) guidelines. This project uses ruff for linting and mypy for type checking, as configured in pyproject.toml ([tool.ruff] and [tool.mypy]). Some rules are ignored or customized; see the configuration for details. When in doubt, match the formatting of existing code.
PEP8 Summary
- Use 4 spaces per indentation level.
- Limit lines to 110 characters.
- Use blank lines to separate functions and classes.
- Use spaces around operators and after commas.
- Use
snake_casefor function and variable names,PascalCasefor class names. - Use docstrings to document all public modules, functions, classes, and methods.
PEP257 Summary
- Use triple double quotes for docstrings.
- The first line should be a short summary of the object's purpose.
- For multi-line docstrings, the second line should be blank, followed by a more detailed description.
- Use imperative mood for function and method docstrings.
Running Linters and Type Checkers
Ruff is recommended for linting. pyproject.toml has configuration for Ruff. Ruff can be run directly via the command line from the root of the project:
ruff check .
MyPy is used for static type checking. Type hints should be added to functions and methods where appropriate.
Mypy can be run with:
mypy .
R Code
The processing for every PC2Products tool lives in beratools/tools/r_scripts_collection.r.
- Keep one R function per algorithm variant (for example
dtm_by_tin,dtm_by_knnidw,dtm_by_kriging), and call it from the tool's Python wrapper. - Take the worker count as an argument from Python (
r_common.r_processes) rather than detecting cores in R. - Use the shared helpers (
detect_normalized,detect_ground_classified,mosaic_catalog_outputs) instead of copying their logic. - List every R package a function needs in the wrapper's
check_r_packages_installationcall, and add new packages to the R package table in the README and the installation page.