Pre-commit Hooks & Formatting
Relevant source files
The following files were used as context for generating this wiki page:
The cron-ext project utilizes a standardized development workflow to maintain code quality, consistency, and type safety. This system relies on pre-commit hooks to automate linting and formatting tasks, ensuring that all contributions adhere to the project's technical standards before being merged.
The primary goal of these hooks is to keep development dependencies light and avoid conflicts by running tools within isolated virtual environments. By enforcing universal formatting and type hinting, the project reduces "minutiae" during code reviews and focuses on functional content.
Sources: CONTRIBUTING.md:40-45, CONTRIBUTING.md:52-57
Pre-commit Framework
The project uses the pre-commit framework to manage and execute multi-language hooks. It is included as a development dependency and is configured via a .pre-commit-config.yaml file.
Execution Flow
Developers interact with pre-commit through a Python-based CLI. By default, hooks run only on files staged in the git index, but they can be executed against the entire codebase.
The diagram shows the lifecycle of a code change from staging to successful commit through the validation pipeline.
Sources: CONTRIBUTING.md:40-50, pyproject.toml:28-44
Universal Code Formatting
The project enforces a "Universal Code Formatting" policy using Black. This ensures a deterministic code style across the entire repository, which produces smaller diffs and simplifies the code review process.
Formatting Standards
- Black: Used for primary code formatting to eliminate hand-formatting variations.
- isort: Configured to work in compatibility with Black, using a vertical hanging indent style (multi-line output 3).
| Tool | Profile/Style | Configuration File |
|---|---|---|
| Black | Default | pyproject.toml |
| isort | black | pyproject.toml |
Sources: CONTRIBUTING.md:52-57, pyproject.toml:44-46
Static Analysis and Type Hinting
Pervasive Python type hints are required throughout the codebase to improve maintainability and developer productivity. This is enforced through mypy.
Mypy Configuration
The project uses strict type checking settings as defined in pyproject.toml:
[tool.mypy]
disallow_untyped_defs = true
check_untyped_defs = true
no_implicit_optional = true
warn_return_any = true
warn_unused_ignores = true
show_error_codes = true
exclude = ['tests']
Sources: CONTRIBUTING.md:59-61, pyproject.toml:48-57
Documentation and Commit Standards
Beyond code style, the project enforces standards for documentation and version control history.
Docstring Convention
All public modules, classes, and functions must include docstrings following the Google Style convention. This requires a detailed description of every argument and the return value.
Sources: CONTRIBUTING.md:63-66
Semantic Pull Requests
The repository uses the semantic-prs GitHub app. All Pull Request titles must follow the conventional commit syntax (<type>: <desc>) to facilitate automated changelog generation.
| Type | Description |
|---|---|
feat | A new feature |
fix | A bug fix |
docs | Documentation only changes |
style | Changes that do not affect the meaning of the code (formatting) |
refactor | A code change that neither fixes a bug nor adds a feature |
ci | Changes to CI configuration files and scripts |
Sources: CONTRIBUTING.md:14-36
Summary
The pre-commit and formatting system in cron-ext ensures that the Meltano utility remains robust and readable. By automating tools like Black, mypy, and isort, the project maintains a high standard of code quality while minimizing the manual overhead for contributors.
Sources: CONTRIBUTING.md:40-45, README.md:1-5