diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index dcc385e..4a646cd 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/python-project-template/.pre-commit-config.yaml.jinja b/python-project-template/.pre-commit-config.yaml.jinja index fbc4d2e..64956f6 100644 --- a/python-project-template/.pre-commit-config.yaml.jinja +++ b/python-project-template/.pre-commit-config.yaml.jinja @@ -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 @@ -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 diff --git a/tests/conftest.py b/tests/conftest.py index 898727f..2875eaf 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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]} diff --git a/tests/test_package_creation.py b/tests/test_package_creation.py index e19e104..5620df5 100644 --- a/tests/test_package_creation.py +++ b/tests/test_package_creation.py @@ -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( @@ -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"], @@ -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( @@ -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): @@ -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) diff --git a/tests/test_questions.py b/tests/test_questions.py index b85712e..dbe900e 100644 --- a/tests/test_questions.py +++ b/tests/test_questions.py @@ -1,3 +1,6 @@ +"""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 @@ -5,9 +8,10 @@ def test_questions_default_answers(copie): 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 @@ -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