pre-commit-terraform icon indicating copy to clipboard operation
pre-commit-terraform copied to clipboard

chore: Backpush to main changes to skeleton of python hooks

Open MaxymVlasov opened this issue 10 months ago β€’ 4 comments

Put an x into the box if that apply:

  • [ ] This PR introduces breaking change.
  • [ ] This PR fixes a bug.
  • [x] This PR adds new functionality.
  • [x] This PR enhances existing functionality.

Description of your changes

This PR includes only changes to skeleton of python hooks, w/o addition of hooks itself, as it will be required a new release.

Changes includes but not limited to:

  • Addition of basic tests in Pytest (mostly generated by GH Copilot, so could be not very useful, but at least they catch basic issues)
  • Rename basic skeleton things to more usual in bash (like CLI_SUBCOMMAND_NAME to HOOK_ID)
  • Dropping of support of Python 2 in python package definition - it was never supported - terraform_docs_replace using python 3 syntax here from hook addition
  • Addition of linters and fix most of found issues
    • Would be nice to support relative imports of submodules, but I didn't find solution that will be pass linters, especially mypy - error: No parent module -- cannot perform relative import - Found 1 error in 1 file (errors prevented further checking)
  • Reimplementation of _common.sh functionality. Located mostly in _common.py, _run_on_whole_repo.py and _logger.py. common::parse_cmdline function was fully reworked by @webknjaz in prev PRs and now populated with common functionality in _cli_parsing.py

This PR DOES NOT include any hooks additions or breaking changes for existing hooks. In branch with hooks exist a bunch of TODOs part of which could result in rework of functional in this PR. But there are already many changes, and this could block @webknjaz to implement testing best practices, so I checkout to new branch, dropped everything which could end in new release and created this PR to merge non-user-faced changes to master

How can we test changes

You can

repos:
  - repo: https://github.com/antonbabenko/pre-commit-terraform
    rev: a278a04b257f82ee86c84410e7f462fb357a9810
    hooks:
      - id: terraform_docs_replace

or play around using updated CONTIBUTING.md notes

Additional references

This PR includes and based on work of @webknjaz who set all these best-practice CLI structure in pre PRs and fixed essential bug of accessing .pre-commit-hooks.yaml values in not-yet-released python hooks (https://github.com/antonbabenko/pre-commit-terraform/pull/740 (included in this PR)) and initial work of @ericfrederich who shown us in https://github.com/antonbabenko/pre-commit-terraform/pull/652 that reimplementation in Python can be done relatively easy

Summary by CodeRabbit

  • New Features  - Expanded pre-commit hook support with new linting, formatting, and static analysis checks.  - Improved CLI argument parsing that offers clearer usage instructions and more robust error handling.

  • Improvements  - Updated CI/CD to run on Python 3.10 for enhanced compatibility.  - Enhanced IDE configuration for improved module resolution.  - Refined build and package settings to ensure essential configuration files are included.  - Updated project metadata and dependencies for better alignment with current standards.

  • Tests  - Extended test coverage to bolster stability and validate command-line behavior.

MaxymVlasov avatar Jan 03 '25 10:01 MaxymVlasov