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
33 changes: 7 additions & 26 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
repos:
# Prevents committing directly branches named 'main' and 'master'.
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v6.0.0
hooks:
- id: no-commit-to-branch
name: Prevent main branch commits
Expand All @@ -12,20 +12,20 @@ repos:
args: ['--maxkb=500']
# Verify that pyproject.toml is well formed
- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.12.1
rev: v0.24.1
hooks:
- id: validate-pyproject
name: Validate pyproject.toml
description: Verify that pyproject.toml adheres to the established schema.
# Verify that GitHub workflows are well formed
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.28.0
rev: 0.36.1
hooks:
- id: check-github-workflows
args: ["--verbose"]
# Automatically sort the imports used in .py files
- repo: https://github.com/pycqa/isort
rev: 5.12.0
rev: 7.0.0
hooks:
- id: isort
name: Run isort
Expand All @@ -44,10 +44,11 @@ repos:
[
"-rn", # Only display messages
"-sn", # Don't display the score
"--max-line-length=120",
]
# Analyze the code style and report code that doesn't adhere.
- repo: https://github.com/psf/black
rev: 23.7.0
rev: 26.1.0
hooks:
- id: black-jupyter
name: Format code using black
Expand All @@ -56,27 +57,7 @@ repos:
# supported by your project here, or alternatively use
# pre-commit's default_language_version, see
# https://pre-commit.com/#top_level-default_language_version
language_version: python3.10
# Make sure Sphinx can build the documentation without issues.
- repo: local
hooks:
- id: sphinx-build
name: Build documentation with Sphinx
entry: sphinx-build
language: system
always_run: true
exclude_types: [file, symlink]
args:
[
"-T", # Show full trace back on exception
"-E", # Don't use saved env. always read all files.
"-b", # Flag to select which builder to use
"html", # Use the HTML builder
"-d", # Flag for cached environment and doctrees
"./docs/_build/doctrees", # directory
"./docs", # Source directory of documents
"./_readthedocs", # Output directory for rendered documents.
]
language_version: python3.12
# Run unit tests, verify that they pass. Note that coverage is run against
# the ./src directory here because that is what will be committed. In the
# github workflow script, the coverage is run against the installed package
Expand Down
13 changes: 12 additions & 1 deletion python-project-template/.pre-commit-config.yaml.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repos:
# This hook should always pass. It will print a message if the local version
# is out of date.
- repo: https://github.com/lincc-frameworks/pre-commit-hooks
rev: v0.1.2
rev: v0.2.2
hooks:
- id: check-lincc-frameworks-template-version
name: Check template version
Expand Down Expand Up @@ -139,6 +139,17 @@ repos:
"--strict", # Use mypy strict mode to enforce type hints
{%- endif %}
]
{%- endif %}
{%- if include_docs and include_notebooks %}
- repo: https://github.com/lincc-frameworks/pre-commit-hooks
rev: v0.2.2
hooks:
- id: pre-executed-nb-never-execute
name: Check pre-executed notebooks
files: ^docs/pre_executed/.*\.ipynb$
verbose: true
args:
["docs/pre_executed/"]
{%- endif %}
# Run unit tests, verify that they pass. Note that coverage is run against
# the ./src directory here because that is what will be committed. In the
Expand Down
6 changes: 6 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
"""Common testing fixtures"""

import pytest

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


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


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


# pylint: disable=redefined-outer-name
@pytest.fixture
def default_answers(python_version):
"""Python version(s) to use in the hydrated python project."""
return {"python_versions": [python_version]}
16 changes: 8 additions & 8 deletions tests/test_package_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def test_code_style_combinations(copie, enforce_style, default_answers):
extra_answers = default_answers | {
"enforce_style": enforce_style,
}
result = create_project_with_basic_checks(copie, extra_answers)
create_project_with_basic_checks(copie, extra_answers)


@pytest.mark.parametrize(
Expand All @@ -149,11 +149,11 @@ def test_smoke_test_notification(copie, notification, default_answers):
"failure_notification": notification,
}

result = create_project_with_basic_checks(copie, extra_answers)
create_project_with_basic_checks(copie, extra_answers)


@pytest.mark.parametrize(
"license",
"license_option",
[
[],
["MIT"],
Expand All @@ -162,11 +162,11 @@ def test_smoke_test_notification(copie, notification, default_answers):
["none"],
],
)
def test_license(copie, license, default_answers):
def test_license(copie, license_option, default_answers):
"""Confirm we get a valid project for different license options."""
extra_answers = default_answers | {"license": license}
extra_answers = default_answers | {"license": license_option}

result = create_project_with_basic_checks(copie, extra_answers)
create_project_with_basic_checks(copie, extra_answers)


@pytest.mark.parametrize(
Expand Down Expand Up @@ -220,7 +220,7 @@ def test_test_lowest_version(copie, test_lowest_version, default_answers):
"test_lowest_version": test_lowest_version,
}

result = create_project_with_basic_checks(copie, extra_answers)
create_project_with_basic_checks(copie, extra_answers)


def test_github_workflows_schema(copie, default_answers):
Expand All @@ -229,4 +229,4 @@ def test_github_workflows_schema(copie, default_answers):
"include_benchmarks": True,
"include_docs": True,
}
result = create_project_with_basic_checks(copie, extra_answers)
create_project_with_basic_checks(copie, extra_answers)
7 changes: 6 additions & 1 deletion tests/test_questions.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
"""Test basic validation of questions and answers."""


def test_questions_default_answers(copie):
"""Create the project directory using copier"""
# run copier to hydrate a temporary project
result = copie.copy()
assert result.exit_code == 0

answer_dict = result.answers
assert answer_dict["enforce_style"] != ''
assert answer_dict["enforce_style"] != ""
assert answer_dict["create_example_module"]


def test_questions_retrofit_answers(copie):
"""Create the project directory using copier"""
# run copier to hydrate a temporary project
Expand All @@ -18,6 +22,7 @@ def test_questions_retrofit_answers(copie):
assert "enforce_style" not in answer_dict
assert "create_example_module" not in answer_dict


def test_questions_invalid_project_name(copie):
"""Create the project directory using copier"""
# run copier to hydrate a temporary project
Expand Down