Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ It can be run:
* For the entire repository or just for change-related files (e.g., local git stash, last commit, or all changes in a Pull Request)

Want to contribute?
Check [open issues](https://github.com/antonbabenko/pre-commit-terraform/issues?q=label%3A%22good+first+issue%22+is%3Aopen+sort%3Aupdated-desc)
Check [open issues](https://github.com/antonbabenko/pre-commit-terraform/issues?q=label%3A%22good+first+issue%22+is%3Aopen+sort%3Aupdated-desc),
[project structure](docs/project_structure.md),
and [contributing notes](/.github/CONTRIBUTING.md).

[Latest Github tag]: https://img.shields.io/github/tag/antonbabenko/pre-commit-terraform.svg
Expand All @@ -42,6 +43,7 @@ If you want to support the development of `pre-commit-terraform` and [many other

* [Sponsors](#sponsors)
* [Table of content](#table-of-content)
* [Project structure](#project-structure)
* [How to install](#how-to-install)
* [1. Install dependencies](#1-install-dependencies)
* [1.1 Custom Terraform binaries and OpenTofu support](#11-custom-terraform-binaries-and-opentofu-support)
Expand Down Expand Up @@ -85,6 +87,10 @@ If you want to support the development of `pre-commit-terraform` and [many other
* [License](#license)
* [Additional information for users from Russia and Belarus](#additional-information-for-users-from-russia-and-belarus)

## Project structure

See [docs/project_structure.md](docs/project_structure.md) for the directory layout, the two hook types (shell vs Python), and where tests live.

## How to install

### 1. Install dependencies
Expand Down
36 changes: 36 additions & 0 deletions docs/project_structure.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Project structure

This is a map of the repository for contributors. Hook *usage* stays in the [README](../README.md). How to add a hook, run tests, and open a PR is in [`.github/CONTRIBUTING.md`](../.github/CONTRIBUTING.md).

## Layout

| Path | Role |
| --- | --- |
| `hooks/` | Bash entry points (`<hook_name>.sh`) and shared `_common.sh` |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
| `hooks/` | Bash entry points (`<hook_name>.sh`) and shared `_common.sh` |
| `hooks/` | Bash hooks entry points (`<hook_name>.sh`). Shared internal files starts from the undersore, e.g. `_common.sh` |

| `src/pre_commit_terraform/` | Python package: CLI parsing, env expansion, `__GIT_WORKING_DIR__`, `terraform_docs_replace` |
| `tests/pytest/` | Python unit tests (`pytest`) |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may make sense to specify that we use pytest also as black-box testing for shell hooks functionality

| `tools/entrypoint.sh` | Docker image entrypoint |
| `tools/install/` | Per-tool install scripts used when building the Docker image |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is also used in the recently added --hooks-config=--tool-version=X.Y.Z functionality.

https://github.com/antonbabenko/pre-commit-terraform#most-hooks-pin-a-specific-tool-version
#1002

| `dependencies/lock-files/` | Pinned Python constraints for reproducible image builds |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, not sure that we need to document this 🤔

You know what - let's split this table in a few:

  1. Bash-related
  2. Python-related
  3. Used by both & other

There may be more tables. Some entities may appear in multiple tables as well.
I, as contributor, would be like to understand what to touch and what to not during work with some part of project. So would be nice to decompose this table into a few groups.

| `.pre-commit-hooks.yaml` | Hook definitions consumed by the [pre-commit framework](https://pre-commit.com/) |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's mention here https://prek.j178.dev/ as well

| `pyproject.toml` / `hatch.toml` | Python project and build config |
| `tox.ini` | Test environment matrix |
| `.github/workflows/ci-cd.yml` | PR checks, tox, image build; release on merge to `master` |

## Hook types

**Shell hooks** (most of them) live in `hooks/<hook_name>.sh`:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**Shell hooks** (most of them) live in `hooks/<hook_name>.sh`:
**Shell hooks** live in `hooks/<hook_name>.sh`:


- Source `_common.sh` for `--args`, `--hook-config`, `--env-vars`, env expansion, `__GIT_WORKING_DIR__`, parallelism, and `terraform init`
- Define `per_dir_hook_unique_part()` for per-directory work
- Call `common::per_dir_hook` instead of splitting arguments by hand

**Python hooks** run as `python -m pre_commit_terraform <subcommand>`:

- Modules live under `src/pre_commit_terraform/`
- Each subcommand implements `invoke_cli_app()`, `populate_argument_parser()`, and `CLI_SUBCOMMAND_NAME`
- Register new subcommands in `_cli_subcommands.py` and add a hook entry in `.pre-commit-hooks.yaml`

## Local checks

Install pre-commit and run the repo's own hooks before you push. Python tests run with `tox`. Do not hand-edit `CHANGELOG.md`; releases own that file.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Install pre-commit and run the repo's own hooks before you push. Python tests run with `tox`. Do not hand-edit `CHANGELOG.md`; releases own that file.
Install pre-commit and run the repo's own hooks before you push. Python tests run with `tox -qq`. Do not hand-edit `CHANGELOG.md`; releases own that file.

Loading