diff --git a/python-project-template/.github/workflows/code_style.yml.jinja b/python-project-template/.github/workflows/code_style.yml.jinja deleted file mode 100644 index babfce9..0000000 --- a/python-project-template/.github/workflows/code_style.yml.jinja +++ /dev/null @@ -1,67 +0,0 @@ -# This workflow will install Python dependencies, then perform static analysis for code style and type checking. -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions - -name: Code Style analysis - -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] - -concurrency: - group: {% raw %}${{ github.workflow }}-${{ github.ref }}{% endraw %} - cancel-in-progress: true - -jobs: - build: - runs-on: ubuntu-latest - strategy: - matrix: - python-version: {{ python_versions }} - - steps: - - uses: actions/checkout@v4 - - name: Set up Python {% raw %}${{ matrix.python-version }}{% endraw %} - uses: actions/setup-python@v5 - with: - python-version: {% raw %}${{ matrix.python-version }}{% endraw %} - - name: Install dependencies - run: | - sudo apt-get update - python -m pip install --upgrade pip - pip install .[dev] - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi -{%- if mypy_type_checking == 'basic' %} - - name: Analyze code with mypy - run: | - mypy ./src ./tests --ignore-missing-imports -{%- elif mypy_type_checking == 'strict' %} - - name: Analyze code with mypy - run: | - mypy ./src ./tests --strict -{%- endif -%} -{%- if 'black' in enforce_style %} - - name: Analyze code for black formatting - run: | - black --check . -{%- endif -%} -{%- if 'pylint' in enforce_style %} - - name: Analyze code with pylint - run: | - pylint -rn -sn --recursive=y ./src --rcfile=./src/.pylintrc - pylint -rn -sn --recursive=y ./tests --rcfile=./tests/.pylintrc -{%- if include_benchmarks %} - pylint -rn -sn --recursive=y ./benchmarks --rcfile=./tests/.pylintrc -{%- endif -%} -{%- endif -%} -{%- if 'ruff_lint' in enforce_style %} - - name: Analyze code with ruff formatter - run: | - ruff format --check -{%- endif -%} -{%- if 'ruff_format' in enforce_style %} - - name: Analyze code with ruff linter - run: | - ruff check -{%- endif -%} \ No newline at end of file diff --git a/python-project-template/.github/workflows/pre-commit-ci.yml.jinja b/python-project-template/.github/workflows/pre-commit-ci.yml.jinja index 99b2492..a57e221 100644 --- a/python-project-template/.github/workflows/pre-commit-ci.yml.jinja +++ b/python-project-template/.github/workflows/pre-commit-ci.yml.jinja @@ -1,17 +1,17 @@ -# This workflow runs pre-commit hooks on pull requests to enforce coding style. -# To ensure correct configuration, please refer to: -# https://lincc-ppt.readthedocs.io/en/latest/practices/ci_precommit.html - +# This workflow runs pre-commit hooks on pushes and pull requests to main +# to enforce coding style. To ensure correct configuration, please refer to: +# https://lincc-ppt.readthedocs.io/en/latest/practices/ci_precommit.html name: Run pre-commit hooks on: + push: + branches: [ main ] pull_request: + branches: [ main ] jobs: pre-commit-ci: runs-on: ubuntu-latest - env: - SKIP: "check-lincc-frameworks-template-version,pytest-check,no-commit-to-branch,validate-pyproject,check-added-large-files,sphinx-build" steps: - uses: actions/checkout@v4 with: @@ -28,6 +28,8 @@ jobs: if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - uses: pre-commit/action@v3.0.1 with: - extra_args: --from-ref {% raw %}${{ github.event.pull_request.base.sha }}{% endraw %} --to-ref {% raw %}${{ github.event.pull_request.head.sha }}{% endraw %} + extra_args: --all-files --verbose + env: + SKIP: "check-lincc-frameworks-template-version,no-commit-to-branch,check-added-large-files,validate-pyproject,sphinx-build,pytest-check" - uses: pre-commit-ci/lite-action@v1.0.2 - if: always() \ No newline at end of file + if: failure() && github.event_name == 'pull_request' && github.event.pull_request.draft == false \ No newline at end of file diff --git a/python-project-template/.pre-commit-config.yaml.jinja b/python-project-template/.pre-commit-config.yaml.jinja index d86bd75..fdc2069 100644 --- a/python-project-template/.pre-commit-config.yaml.jinja +++ b/python-project-template/.pre-commit-config.yaml.jinja @@ -1,4 +1,3 @@ -fail_fast: true repos: # Compare the local template version to the latest remote template version # This hook should always pass. It will print a message if the local version @@ -132,20 +131,6 @@ repos: {%- endif %} ] {%- 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 - # github workflow script, the coverage is run against the installed package - # and uploaded to Codecov by calling pytest like so: - # `python -m pytest --cov= --cov-report=xml` - - repo: local - hooks: - - id: pytest-check - name: Run unit tests - description: Run unit tests with pytest. - entry: bash -c "if python -m pytest --co -qq; then python -m pytest --cov=./src --cov-report=html; fi" - language: system - pass_filenames: false - always_run: true {%- if include_notebooks %} # Make sure Sphinx can build the documentation while explicitly omitting # notebooks from the docs, so users don't have to wait through the execution @@ -195,3 +180,17 @@ repos: "./_readthedocs", # Output directory for rendered documents. ] {%- 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 + # github workflow script, the coverage is run against the installed package + # and uploaded to Codecov by calling pytest like so: + # `python -m pytest --cov= --cov-report=xml` + - repo: local + hooks: + - id: pytest-check + name: Run unit tests + description: Run unit tests with pytest. + entry: bash -c "if python -m pytest --co -qq; then python -m pytest --cov=./src --cov-report=html; fi" + language: system + pass_filenames: false + always_run: true