diff --git a/.github/workflows/check_and_deploy.yml b/.github/workflows/check_and_deploy.yml index 199f0b6..7043cc0 100644 --- a/.github/workflows/check_and_deploy.yml +++ b/.github/workflows/check_and_deploy.yml @@ -43,12 +43,25 @@ jobs: - name: Run tests run: | - mkdir summary + set +e + mkdir summary > /dev/null 2>&1 || echo pytest --cov=python_ci_base --cov-report=markdown-append:summary/coverage.md --markdown-summary-file=summary/summary.md - echo -e "# Summary\n" >> $GITHUB_STEP_SUMMARY - cat summary/summary.md >> $GITHUB_STEP_SUMMARY - echo -e "\n# Coverage\n" >> $GITHUB_STEP_SUMMARY - cat summary/coverage.md >> $GITHUB_STEP_SUMMARY + EXIT_CODE=$? + + set -e + + if (( $EXIT_CODE == 5 )); then + echo "The test suite was empty. No summary generated." + echo -e "# Summary\n" >> $GITHUB_STEP_SUMMARY + echo -e "\n# Coverage\n" >> $GITHUB_STEP_SUMMARY + elif (( $EXIT_CODE == 0 )); then + echo -e "# Summary\n" >> $GITHUB_STEP_SUMMARY + cat summary/summary.md >> $GITHUB_STEP_SUMMARY + echo -e "\n# Coverage\n" >> $GITHUB_STEP_SUMMARY + cat summary/coverage.md >> $GITHUB_STEP_SUMMARY + else + exit $ExitCode + fi # TODO: uncomment if you want to automate deployment to TestPyPI and PyPI diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..c31a2cc --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,22 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v6.0.0 + hooks: + - id: check-yaml + + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.16.1 + hooks: + - id: ruff-check + args: [ --output-format=github, --target-version=py314 ] + - id: ruff-format + args: [ --diff, --target-version=py314 ] + + - repo: local + hooks: + - id: mypy + name: MyPy + language: python + entry: mypy + additional_dependencies: [ '.[pre_commit]' ] + types: [python] diff --git a/README.md b/README.md index a4ec1d0..4376203 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,11 @@ The template sets up a simple continuous integration-pipeline for Python 3.14. -For every push and pull request, linting, format checking, static type checking, and tests are invoked: +For every pre-commit, push and pull request, linting, format checking, and static type checking are invoked: * Ruff: Linting, Formatting * MyPy: Code checking + +Additionally, tests are run for pushes and pull requests (but not pre-hook): * Tests: PyTest (with coverage) The test summary and coverage are reported as an artifact. @@ -23,6 +25,11 @@ Deployment to PyPI and TestPyPI is optional (see below). pass * Replace ``python_ci_base`` with the name of your app on all files and ``AUTHOR`` with your name * Always use typing (if not, delete the py.typed file inside your package) +* Install pre-commit hooks: + ``` + pip install pre-commit + pre-commit install + ``` If you want to enable automatic deployment to PyPI, proceed with the following steps: diff --git a/docs/source/conf.py b/docs/source/conf.py index 78f6e29..c18e90a 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -53,7 +53,7 @@ def extract_info(*path: str, default: str = '') -> Any: autosummary_generate = True templates_path = ['_templates'] -exclude_patterns = [] +exclude_patterns: list[str] = [] # -- Options for HTML output ------------------------------------------------- diff --git a/python_ci_base/app.py b/python_ci_base/app.py deleted file mode 100644 index cdba318..0000000 --- a/python_ci_base/app.py +++ /dev/null @@ -1,10 +0,0 @@ -def main() -> None: - """ - The entry point of the application. - - """ - print('Hello world!') - - -if __name__ == '__main__': - main() diff --git a/scripts/build.sh b/scripts/build.sh deleted file mode 100644 index 18ac30c..0000000 --- a/scripts/build.sh +++ /dev/null @@ -1,8 +0,0 @@ -# install build script -python -m pip install build twine --upgrade --quiet - -# build package to dist-directory -python -m build - -# test built distribution for errors -twine check dist dist/* --strict diff --git a/scripts/doc.sh b/scripts/doc.sh deleted file mode 100644 index 56e40a3..0000000 --- a/scripts/doc.sh +++ /dev/null @@ -1,13 +0,0 @@ -# install requirements -pip install sphinx pydata-sphinx-theme --upgrade --quiet - -# delete previous versions -rm -rf docs/build -rm -rf docs/source/_autogen - -# build ReST from source -# TODO: replace python_ci_base -sphinx-apidoc -o docs/source/_autogen python_ci_base - -# build documentation from ReST -sphinx-build -M html docs/source docs/build diff --git a/scripts/lint.sh b/scripts/lint.sh deleted file mode 100644 index 54496a3..0000000 --- a/scripts/lint.sh +++ /dev/null @@ -1,14 +0,0 @@ -# install requirements -pip install ruff mypy --upgrade --quiet - -# run ruff and mypy - -echo Running Ruff/Check... -ruff check --output-format=github --target-version=py314 - -echo Running Ruff/Format Diff... -ruff format --diff --target-version=py314 - -echo Running MyPy... -# TODO: change "python_ci_base" -mypy python_ci_base diff --git a/tests/test_app.py b/tests/test_app.py deleted file mode 100644 index 74f5a8c..0000000 --- a/tests/test_app.py +++ /dev/null @@ -1,2 +0,0 @@ -def test_app(): - assert 1 + 1 == 2