Skip to content
Merged
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
43 changes: 43 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
default_language_version:
node: system
python: python3

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
hooks:
- id: check-added-large-files
- id: check-merge-conflict
- id: check-vcs-permalinks
- id: no-commit-to-branch
args: [--branch, main]
- id: end-of-file-fixer
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]
- id: check-executables-have-shebangs
- id: check-case-conflict
- id: mixed-line-ending
args: [--fix=lf]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.20
hooks:
- id: ruff-check
args: [--fix]
exclude: ^project_template/
- id: ruff-format
exclude: ^project_template/

- repo: local
hooks:
- id: poetry-check
name: poetry-check
language: system
entry: poetry check
pass_filenames: false
- id: poetry-lock
name: poetry-lock
language: system
entry: poetry lock
pass_filenames: false
files: ^pyproject.toml$
16 changes: 15 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,21 @@ all: ## Show the available make targets.

.PHONY: lint
lint: ## Run Python linter
echo "Not implemented yet"
poetry run ruff check .
poetry run ruff format --check .

.PHONY: format
format: ## Format and fix Python code.
poetry run ruff check . --fix
poetry run ruff format .

.PHONY: pre-commit
pre-commit: ## Run all pre-commit hooks across the repository.
poetry run pre-commit run --all-files

.PHONY: install-pre-commit
install-pre-commit: ## Install the local git pre-commit hooks.
poetry run pre-commit install

.PHONY: test
test: ## Run the tests
Expand Down
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ This template includes a number of features to help you get started developing y
- Type checking with [mypy](http://mypy-lang.org/).
- Testing with [pytest](https://docs.pytest.org/en/stable/)
- Code Coverage with [pytest-cov](https://pytest-cov.readthedocs.io/en/latest/)
- Git hook automation with [pre-commit](https://pre-commit.com/) for repository hygiene and Python checks.
- Continuous Integration using [GitHub Actions](https://docs.github.com/en/actions) with jobs to lint and test your
project.
- Security with:
Expand Down Expand Up @@ -421,7 +422,6 @@ There are many alternatives to the tools used in this template, and you may pref

- Extend test suite
- Add more documentation and developer guidance
- Add support for pre-commit hooks
- Update GitHub repo set up to use latest best practices - rulesets etc vs legacy branch protection.
- Further customisation options for the template:
- Ability to choose your own Linting/Formatting tools
Expand All @@ -442,6 +442,22 @@ Use `make update-template-packages` when you need to refresh the package-manager
This command regenerates the managed package files for Poetry, Pipenv, and uv, including the lockfiles copied into the
template. It requires the relevant package-manager CLIs to be installed locally: `poetry`, `pipenv`, and `uv`.

### Pre-commit hooks

This repository includes a `.pre-commit-config.yaml` for lightweight repository checks and Python linting with Ruff.

Install the hooks locally with:

```bash
make install-pre-commit
```

Run the full hook set on demand with:

```bash
make pre-commit
```

## Contributing

See [CONTRIBUTING.md](CONTRIBUTING.md) for details.
Expand Down
408 changes: 264 additions & 144 deletions poetry.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions project_template/.gitignore.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ cython_debug/
# Ruff
.ruff_cache/

# pre-commit
.pre-commit-cache/

megalinter-reports/

# Copier helpers
Expand Down
72 changes: 72 additions & 0 deletions project_template/.pre-commit-config.yaml.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
default_language_version:
node: system
python: python3

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
hooks:
- id: check-added-large-files
- id: check-merge-conflict
- id: check-vcs-permalinks
- id: no-commit-to-branch
args: [--branch, main]
- id: end-of-file-fixer
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]
- id: check-executables-have-shebangs
- id: check-case-conflict
- id: mixed-line-ending
args: [--fix=lf]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.20
hooks:
- id: ruff-check
args: [--fix]
- id: ruff-format

- repo: local
hooks:
{% if package_manager == "poetry" -%}
- id: poetry-check
name: poetry-check
language: system
entry: poetry check
pass_filenames: false
- id: poetry-lock
name: poetry-lock
language: system
entry: poetry lock
pass_filenames: false
files: ^pyproject.toml$
{%- elif package_manager == "uv" -%}
- id: uv-lock-check
name: uv-lock-check
language: system
entry: uv lock --check
pass_filenames: false
- id: uv-lock
name: uv-lock
language: system
entry: uv lock
pass_filenames: false
files: ^pyproject.toml$
{%- elif package_manager == "pipenv" -%}
- id: pipenv-verify
name: pipenv-verify
language: system
entry: pipenv verify
pass_filenames: false
- id: pipenv-lock
name: pipenv-lock
language: system
entry: pipenv lock
pass_filenames: false
files: ^Pipfile$
{%- endif %}
- id: mypy
name: mypy
language: system
entry: make mypy
pass_filenames: false
8 changes: 8 additions & 0 deletions project_template/Makefile.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ lint: ## Run all linters (black/ruff/pylint/mypy).
{{ package_manager }} run ruff check .
make mypy

.PHONY: pre-commit
pre-commit: ## Run all pre-commit hooks across the repository.
{{ package_manager }} run pre-commit run --all-files

.PHONY: install-pre-commit
install-pre-commit: ## Install the local git pre-commit hooks.
{{ package_manager }} run pre-commit install

.PHONY: test
test: ## Run the tests and check coverage.
{{ package_manager }} run pytest -n auto --cov={{ module_name }} --cov-report term-missing --cov-fail-under=100
Expand Down
12 changes: 12 additions & 0 deletions project_template/README.md.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ Ensure you have the following installed:
make install-dev
```

Install the Git hooks used for local validation:

```bash
make install-pre-commit
```

To install only production dependencies, run:

```bash
Expand Down Expand Up @@ -136,6 +142,12 @@ To auto-format the Python code, and correct fixable linting issues, run:
make format
```

To run the configured pre-commit hooks across the repository, run:

```bash
make pre-commit
```

#### MegaLinter (Lint/Format non-python files)

[MegaLinter](https://github.com/oxsecurity/megalinter) is utilised to lint the non-python files in the project.
Expand Down
2 changes: 1 addition & 1 deletion project_template/copier_scripts/linter-configs.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ ignore = [
convention = "google"

[tool.ruff.lint.per-file-ignores]
"tests/*" = [
"**/tests/**/*.py" = [
# Allow use of assert statements in tests
"S101",
]
Expand Down
2 changes: 1 addition & 1 deletion project_template/copier_scripts/setup_git_repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ if [[ $(git status --porcelain) ]] && create_repo; then
git add .

if ! commit_status=$(
git commit -m "Update contents from base template" 2>&1
git commit -m "Update contents from base template" --no-verify 2>&1
); then
error "Commit Failure: $commit_status"
fi
Expand Down
Loading
Loading