Skip to content

Commit e2e3229

Browse files
committed
Add new pre-commit entry
1 parent d2e1e19 commit e2e3229

File tree

5 files changed

+39
-36
lines changed

5 files changed

+39
-36
lines changed

.pre-commit-config.yaml

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
repos:
22
# Prevents committing directly branches named 'main' and 'master'.
33
- repo: https://github.com/pre-commit/pre-commit-hooks
4-
rev: v4.4.0
4+
rev: v6.0.0
55
hooks:
66
- id: no-commit-to-branch
77
name: Prevent main branch commits
@@ -12,20 +12,20 @@ repos:
1212
args: ['--maxkb=500']
1313
# Verify that pyproject.toml is well formed
1414
- repo: https://github.com/abravalheri/validate-pyproject
15-
rev: v0.12.1
15+
rev: v0.24.1
1616
hooks:
1717
- id: validate-pyproject
1818
name: Validate pyproject.toml
1919
description: Verify that pyproject.toml adheres to the established schema.
2020
# Verify that GitHub workflows are well formed
2121
- repo: https://github.com/python-jsonschema/check-jsonschema
22-
rev: 0.28.0
22+
rev: 0.36.1
2323
hooks:
2424
- id: check-github-workflows
2525
args: ["--verbose"]
2626
# Automatically sort the imports used in .py files
2727
- repo: https://github.com/pycqa/isort
28-
rev: 5.12.0
28+
rev: 7.0.0
2929
hooks:
3030
- id: isort
3131
name: Run isort
@@ -44,10 +44,11 @@ repos:
4444
[
4545
"-rn", # Only display messages
4646
"-sn", # Don't display the score
47+
"--max-line-length=120",
4748
]
4849
# Analyze the code style and report code that doesn't adhere.
4950
- repo: https://github.com/psf/black
50-
rev: 23.7.0
51+
rev: 26.1.0
5152
hooks:
5253
- id: black-jupyter
5354
name: Format code using black
@@ -56,27 +57,7 @@ repos:
5657
# supported by your project here, or alternatively use
5758
# pre-commit's default_language_version, see
5859
# https://pre-commit.com/#top_level-default_language_version
59-
language_version: python3.10
60-
# Make sure Sphinx can build the documentation without issues.
61-
- repo: local
62-
hooks:
63-
- id: sphinx-build
64-
name: Build documentation with Sphinx
65-
entry: sphinx-build
66-
language: system
67-
always_run: true
68-
exclude_types: [file, symlink]
69-
args:
70-
[
71-
"-T", # Show full trace back on exception
72-
"-E", # Don't use saved env. always read all files.
73-
"-b", # Flag to select which builder to use
74-
"html", # Use the HTML builder
75-
"-d", # Flag for cached environment and doctrees
76-
"./docs/_build/doctrees", # directory
77-
"./docs", # Source directory of documents
78-
"./_readthedocs", # Output directory for rendered documents.
79-
]
60+
language_version: python3.12
8061
# Run unit tests, verify that they pass. Note that coverage is run against
8162
# the ./src directory here because that is what will be committed. In the
8263
# github workflow script, the coverage is run against the installed package

python-project-template/.pre-commit-config.yaml.jinja

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ repos:
44
# This hook should always pass. It will print a message if the local version
55
# is out of date.
66
- repo: https://github.com/lincc-frameworks/pre-commit-hooks
7-
rev: v0.1.2
7+
rev: v0.2.1
88
hooks:
99
- id: check-lincc-frameworks-template-version
1010
name: Check template version
@@ -139,6 +139,17 @@ repos:
139139
"--strict", # Use mypy strict mode to enforce type hints
140140
{%- endif %}
141141
]
142+
{%- endif %}
143+
{%- if include_docs and include_notebooks %}
144+
- repo: https://github.com/lincc-frameworks/pre-commit-hooks
145+
rev: v0.2.1
146+
hooks:
147+
- id: pre-executed-nb-never-execute
148+
name: Check pre-executed notebooks
149+
files: ^docs/pre_executed/.*\.ipynb$
150+
verbose: true
151+
args:
152+
["docs/pre_executed/"]
142153
{%- endif %}
143154
# Run unit tests, verify that they pass. Note that coverage is run against
144155
# the ./src directory here because that is what will be committed. In the

tests/conftest.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
1+
"""Common testing fixtures"""
2+
13
import pytest
24

35
PYTHON_VERSIONS = ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
46

57

68
def pytest_addoption(parser):
9+
"""Command line option for python version(s) to use in the hydrated project."""
710
parser.addoption("--python_version", action="store", default="3.12", choices=PYTHON_VERSIONS)
811

912

1013
@pytest.fixture(scope="session", name="python_version")
1114
def python_version(request):
15+
"""Python version(s) to use in the hydrated python project."""
1216
yield request.config.getoption("--python_version")
1317

1418

19+
# pylint: disable=redefined-outer-name
1520
@pytest.fixture
1621
def default_answers(python_version):
22+
"""Python version(s) to use in the hydrated python project."""
1723
return {"python_versions": [python_version]}

tests/test_package_creation.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def test_code_style_combinations(copie, enforce_style, default_answers):
130130
extra_answers = default_answers | {
131131
"enforce_style": enforce_style,
132132
}
133-
result = create_project_with_basic_checks(copie, extra_answers)
133+
create_project_with_basic_checks(copie, extra_answers)
134134

135135

136136
@pytest.mark.parametrize(
@@ -149,11 +149,11 @@ def test_smoke_test_notification(copie, notification, default_answers):
149149
"failure_notification": notification,
150150
}
151151

152-
result = create_project_with_basic_checks(copie, extra_answers)
152+
create_project_with_basic_checks(copie, extra_answers)
153153

154154

155155
@pytest.mark.parametrize(
156-
"license",
156+
"license_option",
157157
[
158158
[],
159159
["MIT"],
@@ -162,11 +162,11 @@ def test_smoke_test_notification(copie, notification, default_answers):
162162
["none"],
163163
],
164164
)
165-
def test_license(copie, license, default_answers):
165+
def test_license(copie, license_option, default_answers):
166166
"""Confirm we get a valid project for different license options."""
167-
extra_answers = default_answers | {"license": license}
167+
extra_answers = default_answers | {"license": license_option}
168168

169-
result = create_project_with_basic_checks(copie, extra_answers)
169+
create_project_with_basic_checks(copie, extra_answers)
170170

171171

172172
@pytest.mark.parametrize(
@@ -220,7 +220,7 @@ def test_test_lowest_version(copie, test_lowest_version, default_answers):
220220
"test_lowest_version": test_lowest_version,
221221
}
222222

223-
result = create_project_with_basic_checks(copie, extra_answers)
223+
create_project_with_basic_checks(copie, extra_answers)
224224

225225

226226
def test_github_workflows_schema(copie, default_answers):
@@ -229,4 +229,4 @@ def test_github_workflows_schema(copie, default_answers):
229229
"include_benchmarks": True,
230230
"include_docs": True,
231231
}
232-
result = create_project_with_basic_checks(copie, extra_answers)
232+
create_project_with_basic_checks(copie, extra_answers)

tests/test_questions.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1+
"""Test basic validation of questions and answers."""
2+
3+
14
def test_questions_default_answers(copie):
25
"""Create the project directory using copier"""
36
# run copier to hydrate a temporary project
47
result = copie.copy()
58
assert result.exit_code == 0
69

710
answer_dict = result.answers
8-
assert answer_dict["enforce_style"] != ''
11+
assert answer_dict["enforce_style"] != ""
912
assert answer_dict["create_example_module"]
1013

14+
1115
def test_questions_retrofit_answers(copie):
1216
"""Create the project directory using copier"""
1317
# run copier to hydrate a temporary project
@@ -18,6 +22,7 @@ def test_questions_retrofit_answers(copie):
1822
assert "enforce_style" not in answer_dict
1923
assert "create_example_module" not in answer_dict
2024

25+
2126
def test_questions_invalid_project_name(copie):
2227
"""Create the project directory using copier"""
2328
# run copier to hydrate a temporary project

0 commit comments

Comments
 (0)