From 1a0931a01e74b31df5cce044e5f57353235d63db Mon Sep 17 00:00:00 2001 From: Hannes Feldt <feldt@astron.nl> Date: Tue, 10 Dec 2024 10:13:10 +0100 Subject: [PATCH 01/28] Add pre-commit hook and improve with better linting --- hooks/post_gen_project.py | 3 + hooks/pre_gen_project.py | 6 ++ .../.pre-commit-config.yaml | 43 ++++++++++++++ .../bin/install-hooks/pre-commit.sh | 8 +++ {{cookiecutter.project_slug}}/pyproject.toml | 2 +- .../requirements.txt | 1 - {{cookiecutter.project_slug}}/setup.cfg | 4 +- {{cookiecutter.project_slug}}/setup.sh | 30 ++++++++++ {{cookiecutter.project_slug}}/tox.ini | 56 +++++++++++-------- 9 files changed, 127 insertions(+), 26 deletions(-) create mode 100644 hooks/post_gen_project.py create mode 100644 hooks/pre_gen_project.py create mode 100644 {{cookiecutter.project_slug}}/.pre-commit-config.yaml create mode 100755 {{cookiecutter.project_slug}}/bin/install-hooks/pre-commit.sh create mode 100755 {{cookiecutter.project_slug}}/setup.sh diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py new file mode 100644 index 0000000..75b6103 --- /dev/null +++ b/hooks/post_gen_project.py @@ -0,0 +1,3 @@ +import os + +#os.rename("gitlab-ci.yml", ".gitlab-ci.yml") diff --git a/hooks/pre_gen_project.py b/hooks/pre_gen_project.py new file mode 100644 index 0000000..5596d97 --- /dev/null +++ b/hooks/pre_gen_project.py @@ -0,0 +1,6 @@ + + + +import os +cwd = os.getcwd() +print(dir(cwd)) diff --git a/{{cookiecutter.project_slug}}/.pre-commit-config.yaml b/{{cookiecutter.project_slug}}/.pre-commit-config.yaml new file mode 100644 index 0000000..47c0182 --- /dev/null +++ b/{{cookiecutter.project_slug}}/.pre-commit-config.yaml @@ -0,0 +1,43 @@ +default_stages: [ commit, push ] +default_language_version: + python: python3 +exclude: '^docs/.*\.py$' + +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: end-of-file-fixer + - id: trailing-whitespace + - id: check-yaml + - id: check-toml + - id: detect-private-key + - repo: https://github.com/tox-dev/tox-ini-fmt + rev: "1.4.1" + hooks: + - id: tox-ini-fmt + args: ["-p", "fix"] + - repo: local + hooks: + - id: tox-black + name: tox-black (local) + entry: tox + language: python + types: [file, python] + args: ["-e", "black", "--"] + - repo: local + hooks: + - id: tox-pep8 + name: tox-pep8 (local) + entry: tox + language: python + types: [file, python] + args: ["-e", "pep8", "--"] + - repo: local + hooks: + - id: tox-pylint + name: tox-pylint (local) + entry: tox + language: python + types: [file, python] + args: ["-e", "pylint", "--"] diff --git a/{{cookiecutter.project_slug}}/bin/install-hooks/pre-commit.sh b/{{cookiecutter.project_slug}}/bin/install-hooks/pre-commit.sh new file mode 100755 index 0000000..792a3aa --- /dev/null +++ b/{{cookiecutter.project_slug}}/bin/install-hooks/pre-commit.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +if [ ! -f "setup.sh" ]; then + echo "pre-commit.sh must be executed with repository root as working directory!" + exit 1 +fi + +pre-commit install --hook-type pre-push diff --git a/{{cookiecutter.project_slug}}/pyproject.toml b/{{cookiecutter.project_slug}}/pyproject.toml index 063c6b8..1b3c578 100644 --- a/{{cookiecutter.project_slug}}/pyproject.toml +++ b/{{cookiecutter.project_slug}}/pyproject.toml @@ -1,6 +1,6 @@ [build-system] requires = [ - "setuptools>=62.6", + "setuptools>=70.0", "setuptools_scm[toml]>=8.0", "wheel" ] diff --git a/{{cookiecutter.project_slug}}/requirements.txt b/{{cookiecutter.project_slug}}/requirements.txt index 8f81bc2..24ce15a 100644 --- a/{{cookiecutter.project_slug}}/requirements.txt +++ b/{{cookiecutter.project_slug}}/requirements.txt @@ -1,2 +1 @@ -importlib-metadata>=0.12, <5.0;python_version<"3.8" numpy diff --git a/{{cookiecutter.project_slug}}/setup.cfg b/{{cookiecutter.project_slug}}/setup.cfg index ac0ae10..a5fbebf 100644 --- a/{{cookiecutter.project_slug}}/setup.cfg +++ b/{{cookiecutter.project_slug}}/setup.cfg @@ -15,11 +15,11 @@ classifiers = Programming Language :: Python Programming Language :: Python :: 3 Programming Language :: Python :: 3 :: Only - Programming Language :: Python :: 3.8 Programming Language :: Python :: 3.9 Programming Language :: Python :: 3.10 Programming Language :: Python :: 3.11 Programming Language :: Python :: 3.12 + Programming Language :: Python :: 3.13 Topic :: Internet :: WWW/HTTP Topic :: Internet :: WWW/HTTP :: Dynamic Content Topic :: Scientific/Engineering @@ -28,7 +28,7 @@ classifiers = [options] include_package_data = true packages = find: -python_requires = >=3.8 +python_requires = >=3.9 install_requires = file: requirements.txt [flake8] diff --git a/{{cookiecutter.project_slug}}/setup.sh b/{{cookiecutter.project_slug}}/setup.sh new file mode 100755 index 0000000..4548910 --- /dev/null +++ b/{{cookiecutter.project_slug}}/setup.sh @@ -0,0 +1,30 @@ +#! /usr/bin/env bash +# +# Copyright (C) 2023 ASTRON (Netherlands Institute for Radio Astronomy) +# SPDX-License-Identifier: Apache-2.0 +# + +# This file's directory is used to determine the station control directory +# location. +if [ -z ${BASH_SOURCE} ]; then + BASH_SOURCE=${(%):-%x} +fi + +ABSOLUTE_PATH=$(realpath $(dirname ${BASH_SOURCE})) + +# Create a virtual environment directory if it doesn't exist +VENV_DIR="${ABSOLUTE_PATH}/.venv" +if [ ! -d "$VENV_DIR" ]; then + echo "Creating virtual environment..." + python3 -m venv "$VENV_DIR" +fi + +# Activate the virtual environment +source "$VENV_DIR/bin/activate" +python -m pip install pre-commit +python -m pip install "tox>=4.21.0" + +# Install git pre-commit pre-push hook +if [ ! -f "${ABSOLUTE_PATH}/.git/hooks/pre-push.legacy" ]; then + source "${ABSOLUTE_PATH}/bin/install-hooks/pre-commit.sh" +fi diff --git a/{{cookiecutter.project_slug}}/tox.ini b/{{cookiecutter.project_slug}}/tox.ini index 871b5de..52ca16f 100644 --- a/{{cookiecutter.project_slug}}/tox.ini +++ b/{{cookiecutter.project_slug}}/tox.ini @@ -1,24 +1,36 @@ [tox] # Generative environment list to test all supported Python versions -envlist = py3{8,9,10,11,12},black,pep8,pylint -minversion = 3.18.0 +requires = + tox>=4.21 +env_list = + fix + pep8 + black + pylint + py3{13, 12, 11, 10, 9} [testenv] -usedevelop = True -package = wheel +package = editable wheel_build_env = .pkg - -setenv = - LANGUAGE=en_US - LC_ALL=en_US.UTF-8 - PYTHONWARNINGS=default::DeprecationWarning deps = -r{toxinidir}/requirements.txt -r{toxinidir}/tests/requirements.txt +setenv = + LANGUAGE = en_US + LC_ALL = en_US.UTF-8 + PYTHONWARNINGS = default::DeprecationWarning commands = {envpython} --version {envpython} -m pytest +[testenv:fix] +description = format the code base to adhere to our styles, and complain about what we cannot do automatically +skip_install = true +deps = + pre-commit-uv>=4.1.1 +commands = + pre-commit run --all-files --show-diff-on-failure + [testenv:coverage] commands = {envpython} --version @@ -27,31 +39,31 @@ commands = # Use generative name and command prefixes to reuse the same virtualenv # for all linting jobs. [testenv:{pep8,black,pylint,format}] -usedevelop = False -envdir = {toxworkdir}/linting commands = pep8: {envpython} -m flake8 --version - pep8: {envpython} -m flake8 {{cookiecutter.project_slug}} tests + pep8: {envpython} -m flake8 {posargs:{{cookiecutter.project_slug}} tests} black: {envpython} -m black --version - black: {envpython} -m black --check --diff {{cookiecutter.project_slug}} tests + black: {envpython} -m black --check --diff {posargs:{{cookiecutter.project_slug}} tests} pylint: {envpython} -m pylint --version - pylint: {envpython} -m pylint {{cookiecutter.project_slug}} tests - format: {envpython} -m autopep8 -v -aa --in-place --recursive {{cookiecutter.project_slug}} - format: {envpython} -m autopep8 -v -aa --in-place --recursive tests - format: {envpython} -m black -v {{cookiecutter.project_slug}} tests + pylint: {envpython} -m pylint {posargs:{{cookiecutter.project_slug}} tests} + format: {envpython} -m autopep8 -v -aa --in-place --recursive {posargs:{{cookiecutter.project_slug}}} + format: {envpython} -m autopep8 -v -aa --in-place --recursive {posargs:tests} + format: {envpython} -m black -v {posargs:{{cookiecutter.project_slug}} tests} +envdir = {toxworkdir}/linting [testenv:docs] -; unset LC_ALL / LANGUAGE from testenv, would fail sphinx otherwise -setenv = deps = -r{toxinidir}/requirements.txt -r{toxinidir}/docs/requirements.txt +; unset LC_ALL / LANGUAGE from testenv, would fail sphinx otherwise +setenv = changedir = {toxinidir} commands = {envpython} docs/cleanup.py sphinx-build -b html docs/source docs/build/html [testenv:build] -usedevelop = False -deps = build -commands = {envpython} -m build +deps = + build +commands = + {envpython} -m build -- GitLab From e2f40c21f1afb7b0c2835d50dd0680608a46cc02 Mon Sep 17 00:00:00 2001 From: Hannes Feldt <feldt@astron.nl> Date: Tue, 10 Dec 2024 10:15:02 +0100 Subject: [PATCH 02/28] oopsie --- hooks/post_gen_project.py | 3 --- hooks/pre_gen_project.py | 6 ------ 2 files changed, 9 deletions(-) delete mode 100644 hooks/post_gen_project.py delete mode 100644 hooks/pre_gen_project.py diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py deleted file mode 100644 index 75b6103..0000000 --- a/hooks/post_gen_project.py +++ /dev/null @@ -1,3 +0,0 @@ -import os - -#os.rename("gitlab-ci.yml", ".gitlab-ci.yml") diff --git a/hooks/pre_gen_project.py b/hooks/pre_gen_project.py deleted file mode 100644 index 5596d97..0000000 --- a/hooks/pre_gen_project.py +++ /dev/null @@ -1,6 +0,0 @@ - - - -import os -cwd = os.getcwd() -print(dir(cwd)) -- GitLab From 0a5ffeb1c10d596c49a8ab2f1e5837e740000515 Mon Sep 17 00:00:00 2001 From: Hannes Feldt <feldt@astron.nl> Date: Tue, 10 Dec 2024 10:34:36 +0100 Subject: [PATCH 03/28] Update readme --- {{cookiecutter.project_slug}}/README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/{{cookiecutter.project_slug}}/README.md b/{{cookiecutter.project_slug}}/README.md index 12a816d..f8de07d 100644 --- a/{{cookiecutter.project_slug}}/README.md +++ b/{{cookiecutter.project_slug}}/README.md @@ -29,8 +29,16 @@ from {{cookiecutter.project_slug}} import cool_module cool_module.greeter() # prints "Hello World" ``` -## Contributing +## Development +### Development environment + +To setup and activte the develop environment run ```source ./setup.sh``` from within the source directory. + +If PyCharm is used, this only needs to be done once. +Afterward the Python virtual env can be setup within PyCharm. + +### Contributing To contribute, please create a feature branch and a "Draft" merge request. Upon completion, the merge request should be marked as ready and a reviewer should be assigned. -- GitLab From 890e3b619f7126681867bdd4fc54891f4bb61810 Mon Sep 17 00:00:00 2001 From: Hannes Feldt <feldt@astron.nl> Date: Tue, 10 Dec 2024 10:53:24 +0100 Subject: [PATCH 04/28] update python versions --- .gitlab-ci.yml | 2 ++ {{cookiecutter.project_slug}}/.gitlab-ci.yml | 2 +- {{cookiecutter.project_slug}}/docker/ci-runner/Dockerfile | 2 +- .../docker/{{cookiecutter.project_slug}}/Dockerfile | 6 +++--- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2416143..2036984 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -19,6 +19,8 @@ build-template: - cookiecutter --no-input --overwrite-if-exists --output-dir . . - cd my_awesome_app - git init + - source ./setup.sh + - git commit -m 'Test' # cannot use needs, for artifacts on child pipeline so must regenerate template! artifacts: paths: diff --git a/{{cookiecutter.project_slug}}/.gitlab-ci.yml b/{{cookiecutter.project_slug}}/.gitlab-ci.yml index 93fffac..aa5bf08 100644 --- a/{{cookiecutter.project_slug}}/.gitlab-ci.yml +++ b/{{cookiecutter.project_slug}}/.gitlab-ci.yml @@ -89,7 +89,7 @@ run_unit_tests: - tox -e py3${PY_VERSION} parallel: matrix: # use the matrix for testing - - PY_VERSION: [8, 9, 10, 11] + - PY_VERSION: [9, 10, 11, 12, 13] # Run code coverage on the base image thus also performing unit tests run_unit_tests_coverage: diff --git a/{{cookiecutter.project_slug}}/docker/ci-runner/Dockerfile b/{{cookiecutter.project_slug}}/docker/ci-runner/Dockerfile index 6cb4643..6063354 100644 --- a/{{cookiecutter.project_slug}}/docker/ci-runner/Dockerfile +++ b/{{cookiecutter.project_slug}}/docker/ci-runner/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.12 +FROM python:3.13 RUN python -m pip install --upgrade pip RUN python -m pip install --upgrade tox twine diff --git a/{{cookiecutter.project_slug}}/docker/{{cookiecutter.project_slug}}/Dockerfile b/{{cookiecutter.project_slug}}/docker/{{cookiecutter.project_slug}}/Dockerfile index ceea7e7..1f7eb27 100644 --- a/{{cookiecutter.project_slug}}/docker/{{cookiecutter.project_slug}}/Dockerfile +++ b/{{cookiecutter.project_slug}}/docker/{{cookiecutter.project_slug}}/Dockerfile @@ -1,6 +1,6 @@ ARG BUILD_ENV=no_copy -FROM python:3.11 AS build_no_copy +FROM python:3.13 AS build_no_copy ADD ../../requirements.txt . COPY ../.. /work RUN rm -r /work/dist | true @@ -8,11 +8,11 @@ RUN python -m pip install --user tox WORKDIR /work RUN python -m tox -e build -FROM python:3.11 AS build_copy +FROM python:3.13 AS build_copy COPY dist /work/dist FROM build_${BUILD_ENV} AS build -FROM python:3.11-slim +FROM python:3.13-slim COPY --from=build /work/dist /dist RUN python -m pip install /dist/*.whl -- GitLab From 1902f7a8f6355f3072ed78be64e9f02358741443 Mon Sep 17 00:00:00 2001 From: Hannes Feldt <feldt@astron.nl> Date: Tue, 10 Dec 2024 10:55:46 +0100 Subject: [PATCH 05/28] fix pipeline --- .gitlab-ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2036984..4e87101 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -20,6 +20,8 @@ build-template: - cd my_awesome_app - git init - source ./setup.sh + - git config user.email "ci-runner@example.com" + - git config user.name "CI Runner" - git commit -m 'Test' # cannot use needs, for artifacts on child pipeline so must regenerate template! artifacts: -- GitLab From 22391970228eadcbf6b03ed6f2dec13ff3107a61 Mon Sep 17 00:00:00 2001 From: Hannes Feldt <feldt@astron.nl> Date: Tue, 10 Dec 2024 11:01:24 +0100 Subject: [PATCH 06/28] fixes --- .gitlab-ci.yml | 3 ++- {{cookiecutter.project_slug}}/.dockerignore | 4 ++++ {{cookiecutter.project_slug}}/.gitignore | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 {{cookiecutter.project_slug}}/.dockerignore diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4e87101..fbe26e7 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -18,10 +18,11 @@ build-template: - python --version # For debugging - cookiecutter --no-input --overwrite-if-exists --output-dir . . - cd my_awesome_app - - git init - source ./setup.sh + - git init - git config user.email "ci-runner@example.com" - git config user.name "CI Runner" + - git add . - git commit -m 'Test' # cannot use needs, for artifacts on child pipeline so must regenerate template! artifacts: diff --git a/{{cookiecutter.project_slug}}/.dockerignore b/{{cookiecutter.project_slug}}/.dockerignore new file mode 100644 index 0000000..141f90d --- /dev/null +++ b/{{cookiecutter.project_slug}}/.dockerignore @@ -0,0 +1,4 @@ +.tox +build +*.egg-info +.venv diff --git a/{{cookiecutter.project_slug}}/.gitignore b/{{cookiecutter.project_slug}}/.gitignore index d5c650e..3f64dc5 100644 --- a/{{cookiecutter.project_slug}}/.gitignore +++ b/{{cookiecutter.project_slug}}/.gitignore @@ -2,6 +2,7 @@ dist/* *.egg-info *.pyc .tox +.venv .coverage coverage.xml -- GitLab From 2d812004501180861f1c2eb070056f9cc05cd071 Mon Sep 17 00:00:00 2001 From: Hannes Feldt <feldt@astron.nl> Date: Tue, 10 Dec 2024 11:04:29 +0100 Subject: [PATCH 07/28] fix --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index fbe26e7..aea67cb 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -18,10 +18,10 @@ build-template: - python --version # For debugging - cookiecutter --no-input --overwrite-if-exists --output-dir . . - cd my_awesome_app - - source ./setup.sh - git init - git config user.email "ci-runner@example.com" - git config user.name "CI Runner" + - source ./setup.sh - git add . - git commit -m 'Test' # cannot use needs, for artifacts on child pipeline so must regenerate template! -- GitLab From 3b88141760d7fe1e656ab7598fbfbbe2c2594930 Mon Sep 17 00:00:00 2001 From: Hannes Feldt <feldt@astron.nl> Date: Tue, 10 Dec 2024 11:05:51 +0100 Subject: [PATCH 08/28] fix --- .gitlab-ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index aea67cb..07b6368 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -29,6 +29,9 @@ build-template: paths: - my_awesome_app/* - project.gitlab-ci.yml + exclude: + - my_awesome_app/.venv + - my_awesome_app/.git # Spawn pipeline using the gitlab-ci.yml from generated template instance # use project.gitlab.ci.yml for necessary job overrides from this template instance -- GitLab From 12bb8298a1b6d36dfeac4f2842173870bb108a40 Mon Sep 17 00:00:00 2001 From: Hannes Feldt <feldt@astron.nl> Date: Tue, 10 Dec 2024 11:08:18 +0100 Subject: [PATCH 09/28] fix --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 07b6368..e6bdf6b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -24,6 +24,7 @@ build-template: - source ./setup.sh - git add . - git commit -m 'Test' + - git push --dry-run -u origin test # cannot use needs, for artifacts on child pipeline so must regenerate template! artifacts: paths: -- GitLab From c9fade4220c0e42ae52d857be682d80c57cdccb3 Mon Sep 17 00:00:00 2001 From: Hannes Feldt <feldt@astron.nl> Date: Tue, 10 Dec 2024 11:09:34 +0100 Subject: [PATCH 10/28] fix artifact size --- .gitlab-ci.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e6bdf6b..4ec5520 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -25,14 +25,13 @@ build-template: - git add . - git commit -m 'Test' - git push --dry-run -u origin test + - rm -r .venv + - rm -r .git # cannot use needs, for artifacts on child pipeline so must regenerate template! artifacts: paths: - my_awesome_app/* - project.gitlab-ci.yml - exclude: - - my_awesome_app/.venv - - my_awesome_app/.git # Spawn pipeline using the gitlab-ci.yml from generated template instance # use project.gitlab.ci.yml for necessary job overrides from this template instance -- GitLab From 1e2f45fa4dc80ecfe4b411847b8a52cc7cd3614e Mon Sep 17 00:00:00 2001 From: Hannes Feldt <feldt@astron.nl> Date: Tue, 10 Dec 2024 11:12:19 +0100 Subject: [PATCH 11/28] fix --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4ec5520..4869303 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -24,6 +24,7 @@ build-template: - source ./setup.sh - git add . - git commit -m 'Test' + - git remote add origin git@git.astron.nl:templates/python-package-test - git push --dry-run -u origin test - rm -r .venv - rm -r .git -- GitLab From 20786bbd0c467921d8f53e93ad2e01dcf30cbe2a Mon Sep 17 00:00:00 2001 From: Hannes Feldt <feldt@astron.nl> Date: Tue, 10 Dec 2024 12:52:26 +0100 Subject: [PATCH 12/28] migrate tox.ini to toml --- .gitlab-ci.yml | 2 +- .../.pre-commit-config.yaml | 5 -- {{cookiecutter.project_slug}}/pyproject.toml | 66 ++++++++++++++++++ {{cookiecutter.project_slug}}/setup.py | 4 ++ {{cookiecutter.project_slug}}/tox.ini | 69 ------------------- 5 files changed, 71 insertions(+), 75 deletions(-) delete mode 100644 {{cookiecutter.project_slug}}/tox.ini diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4869303..31a1737 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -25,7 +25,7 @@ build-template: - git add . - git commit -m 'Test' - git remote add origin git@git.astron.nl:templates/python-package-test - - git push --dry-run -u origin test + - git push --dry-run -u origin main - rm -r .venv - rm -r .git # cannot use needs, for artifacts on child pipeline so must regenerate template! diff --git a/{{cookiecutter.project_slug}}/.pre-commit-config.yaml b/{{cookiecutter.project_slug}}/.pre-commit-config.yaml index 47c0182..2980237 100644 --- a/{{cookiecutter.project_slug}}/.pre-commit-config.yaml +++ b/{{cookiecutter.project_slug}}/.pre-commit-config.yaml @@ -12,11 +12,6 @@ repos: - id: check-yaml - id: check-toml - id: detect-private-key - - repo: https://github.com/tox-dev/tox-ini-fmt - rev: "1.4.1" - hooks: - - id: tox-ini-fmt - args: ["-p", "fix"] - repo: local hooks: - id: tox-black diff --git a/{{cookiecutter.project_slug}}/pyproject.toml b/{{cookiecutter.project_slug}}/pyproject.toml index 1b3c578..9d1c2ea 100644 --- a/{{cookiecutter.project_slug}}/pyproject.toml +++ b/{{cookiecutter.project_slug}}/pyproject.toml @@ -11,3 +11,69 @@ version_file = "{{cookiecutter.project_slug}}/_version.py" [tool.pylint] ignore = "_version.py" + +[tool.tox] +# Generative environment list to test all supported Python versions +requires = ["tox>=4.21"] +env_list = ["fix", "pep8", "black", "pylint", "py{13, 12, 11, 10, 9}"] + +[tool.tox.env_run_base] +package = "editable" +deps = [ + "-r{toxinidir}/requirements.txt", + "-r{toxinidir}/tests/requirements.txt"] +set_env = { LANGUAGE = "en_US", LC_ALL = "en_US.UTF-8", PYTHONWARNINGS = "default::DeprecationWarning" } +commands = [["python", "--version"], ["python", "-m", "pytest"]] + +[tool.tox.env.fix] +description = "format the code base to adhere to our styles, and complain about what we cannot do automatically" +skip_install = true +deps = ["pre-commit-uv>=4.1.1"] +commands = [["pre-commit", "run", "--all-files", "--show-diff-on-failure"]] + +[tool.tox.env.coverage] +commands = [ + ["python", "--version"], + ["python", "-m", "pytest", "--cov-report", "term", "--cov-report", "xml", "--cov-report", "html", "--cov={{cookiecutter.project_slug}}"]] + +# Command prefixes to reuse the same virtualenv for all linting jobs. +[tool.tox.env.pep8] +commands = [ + ["python", "-m", "flake8", "--version"], + ["python", "-m", "flake8", { replace = "posargs", default = ["{{cookiecutter.project_slug}}", "tests"], extend = true }] +] + +[tool.tox.env.black] +commands = [ + ["python", "-m", "black", "--version"], + ["python", "-m", "black", "--check", "--diff", { replace = "posargs", default = ["{{cookiecutter.project_slug}}", "tests"], extend = true }] +] + +[tool.tox.env.pylint] +commands = [ + ["python", "-m", "pylint", "--version"], + ["python", "-m", "pylint", { replace = "posargs", default = ["{{cookiecutter.project_slug}}", "tests"], extend = true }] +] + +[tool.tox.env.format] +commands = [ + ["python", "-m", "autopep8", "-v", "-aa", "--in-place", "--recursive", { replace = "posargs", default = ["{{cookiecutter.project_slug}}", "tests"], extend = true }], + ["python", "-m", "black", "-v", { replace = "posargs", default = ["{{cookiecutter.project_slug}}", "tests"], extend = true }] +] + +[tool.tox.env.docs] +deps = [ + "-r{toxinidir}/requirements.txt", + "-r{toxinidir}/docs/requirements.txt"] +# unset LC_ALL / LANGUAGE from testenv, would fail sphinx otherwise +set_env = "" +changedir = "{tox_root}" +commands = [ + ["python", "docs/cleanup.py"], + ["sphinx-build", "-b", "html", "docs/source", "docs/build/html"] +] + +[tool.tox.env.build] +package = "wheel" +deps = ["build"] +commands = [["python", "-m", "build"]] diff --git a/{{cookiecutter.project_slug}}/setup.py b/{{cookiecutter.project_slug}}/setup.py index b908cbe..10fdaec 100644 --- a/{{cookiecutter.project_slug}}/setup.py +++ b/{{cookiecutter.project_slug}}/setup.py @@ -1,3 +1,7 @@ +# Copyright (C) 2023 ASTRON (Netherlands Institute for Radio Astronomy) +# SPDX-License-Identifier: Apache-2.0 + +""" Setuptools entry point """ import setuptools setuptools.setup() diff --git a/{{cookiecutter.project_slug}}/tox.ini b/{{cookiecutter.project_slug}}/tox.ini deleted file mode 100644 index 52ca16f..0000000 --- a/{{cookiecutter.project_slug}}/tox.ini +++ /dev/null @@ -1,69 +0,0 @@ -[tox] -# Generative environment list to test all supported Python versions -requires = - tox>=4.21 -env_list = - fix - pep8 - black - pylint - py3{13, 12, 11, 10, 9} - -[testenv] -package = editable -wheel_build_env = .pkg -deps = - -r{toxinidir}/requirements.txt - -r{toxinidir}/tests/requirements.txt -setenv = - LANGUAGE = en_US - LC_ALL = en_US.UTF-8 - PYTHONWARNINGS = default::DeprecationWarning -commands = - {envpython} --version - {envpython} -m pytest - -[testenv:fix] -description = format the code base to adhere to our styles, and complain about what we cannot do automatically -skip_install = true -deps = - pre-commit-uv>=4.1.1 -commands = - pre-commit run --all-files --show-diff-on-failure - -[testenv:coverage] -commands = - {envpython} --version - {envpython} -m pytest --cov-report term --cov-report xml --cov-report html --cov={{cookiecutter.project_slug}} - -# Use generative name and command prefixes to reuse the same virtualenv -# for all linting jobs. -[testenv:{pep8,black,pylint,format}] -commands = - pep8: {envpython} -m flake8 --version - pep8: {envpython} -m flake8 {posargs:{{cookiecutter.project_slug}} tests} - black: {envpython} -m black --version - black: {envpython} -m black --check --diff {posargs:{{cookiecutter.project_slug}} tests} - pylint: {envpython} -m pylint --version - pylint: {envpython} -m pylint {posargs:{{cookiecutter.project_slug}} tests} - format: {envpython} -m autopep8 -v -aa --in-place --recursive {posargs:{{cookiecutter.project_slug}}} - format: {envpython} -m autopep8 -v -aa --in-place --recursive {posargs:tests} - format: {envpython} -m black -v {posargs:{{cookiecutter.project_slug}} tests} -envdir = {toxworkdir}/linting - -[testenv:docs] -deps = - -r{toxinidir}/requirements.txt - -r{toxinidir}/docs/requirements.txt -; unset LC_ALL / LANGUAGE from testenv, would fail sphinx otherwise -setenv = -changedir = {toxinidir} -commands = - {envpython} docs/cleanup.py - sphinx-build -b html docs/source docs/build/html - -[testenv:build] -deps = - build -commands = - {envpython} -m build -- GitLab From 388a11b0e213db59c8a228e549f611660f962036 Mon Sep 17 00:00:00 2001 From: Hannes Feldt <feldt@astron.nl> Date: Tue, 10 Dec 2024 12:54:56 +0100 Subject: [PATCH 13/28] test --- .gitlab-ci.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 31a1737..511da4f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -22,10 +22,11 @@ build-template: - git config user.email "ci-runner@example.com" - git config user.name "CI Runner" - source ./setup.sh + - git checkout -b test - git add . - git commit -m 'Test' - - git remote add origin git@git.astron.nl:templates/python-package-test - - git push --dry-run -u origin main + - git remote add origin git@git.astron.nl:templates/python-package + - git push --dry-run -u origin test - rm -r .venv - rm -r .git # cannot use needs, for artifacts on child pipeline so must regenerate template! -- GitLab From 7bb6f1c423a38017f7ed4b68fa51aa6090cc13b0 Mon Sep 17 00:00:00 2001 From: Hannes Feldt <feldt@astron.nl> Date: Tue, 10 Dec 2024 12:58:06 +0100 Subject: [PATCH 14/28] fix --- .gitlab-ci.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 511da4f..2096105 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -22,11 +22,7 @@ build-template: - git config user.email "ci-runner@example.com" - git config user.name "CI Runner" - source ./setup.sh - - git checkout -b test - - git add . - - git commit -m 'Test' - - git remote add origin git@git.astron.nl:templates/python-package - - git push --dry-run -u origin test + - tox -e fix - rm -r .venv - rm -r .git # cannot use needs, for artifacts on child pipeline so must regenerate template! -- GitLab From c9476a276249477ca96ab76f2aa5a4223357a074 Mon Sep 17 00:00:00 2001 From: Hannes Feldt <feldt@astron.nl> Date: Tue, 10 Dec 2024 14:09:04 +0100 Subject: [PATCH 15/28] test --- {{cookiecutter.project_slug}}/pyproject.toml | 7 ++++++- {{cookiecutter.project_slug}}/tests/requirements.txt | 5 ----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/{{cookiecutter.project_slug}}/pyproject.toml b/{{cookiecutter.project_slug}}/pyproject.toml index 9d1c2ea..a19fe44 100644 --- a/{{cookiecutter.project_slug}}/pyproject.toml +++ b/{{cookiecutter.project_slug}}/pyproject.toml @@ -38,24 +38,29 @@ commands = [ # Command prefixes to reuse the same virtualenv for all linting jobs. [tool.tox.env.pep8] +deps = ["flake8"] commands = [ ["python", "-m", "flake8", "--version"], ["python", "-m", "flake8", { replace = "posargs", default = ["{{cookiecutter.project_slug}}", "tests"], extend = true }] ] [tool.tox.env.black] +deps = ["black"] commands = [ ["python", "-m", "black", "--version"], ["python", "-m", "black", "--check", "--diff", { replace = "posargs", default = ["{{cookiecutter.project_slug}}", "tests"], extend = true }] ] [tool.tox.env.pylint] +deps = ["pylint"] commands = [ ["python", "-m", "pylint", "--version"], ["python", "-m", "pylint", { replace = "posargs", default = ["{{cookiecutter.project_slug}}", "tests"], extend = true }] ] [tool.tox.env.format] +deps = ["autopep8"] +deps = ["black"] commands = [ ["python", "-m", "autopep8", "-v", "-aa", "--in-place", "--recursive", { replace = "posargs", default = ["{{cookiecutter.project_slug}}", "tests"], extend = true }], ["python", "-m", "black", "-v", { replace = "posargs", default = ["{{cookiecutter.project_slug}}", "tests"], extend = true }] @@ -75,5 +80,5 @@ commands = [ [tool.tox.env.build] package = "wheel" -deps = ["build"] +deps = ["build>=0.8.0"] commands = [["python", "-m", "build"]] diff --git a/{{cookiecutter.project_slug}}/tests/requirements.txt b/{{cookiecutter.project_slug}}/tests/requirements.txt index f14d0b9..b507faf 100644 --- a/{{cookiecutter.project_slug}}/tests/requirements.txt +++ b/{{cookiecutter.project_slug}}/tests/requirements.txt @@ -1,7 +1,2 @@ -autopep8 >= 1.7.0 # MIT -black >= 22.0.0 # MIT -build >= 0.8.0 # MIT -flake8 >= 5.0.0 # MIT -pylint >= 2.15.0 # GPLv2 pytest >= 7.0.0 # MIT pytest-cov >= 3.0.0 # MIT -- GitLab From 9ceeb7f674b3ca0542e39b031c2a947fe67396db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Corn=C3=A9=20Lukken?= <lukken@astron.nl> Date: Thu, 12 Dec 2024 13:47:51 +0000 Subject: [PATCH 16/28] Nani?! --- .gitlab-ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2096105..32539e2 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -22,6 +22,9 @@ build-template: - git config user.email "ci-runner@example.com" - git config user.name "CI Runner" - source ./setup.sh + - ls -lah + - tox --version + - pip install --upgrade tox - tox -e fix - rm -r .venv - rm -r .git -- GitLab From 2b4b2ea6f87277be302ad1d5be7db8867d408987 Mon Sep 17 00:00:00 2001 From: Jan David Mol <mol@astron.nl> Date: Thu, 6 Mar 2025 12:51:53 +0100 Subject: [PATCH 17/28] Fix syntax of pyproject.toml --- {{cookiecutter.project_slug}}/pyproject.toml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/{{cookiecutter.project_slug}}/pyproject.toml b/{{cookiecutter.project_slug}}/pyproject.toml index a19fe44..6b37726 100644 --- a/{{cookiecutter.project_slug}}/pyproject.toml +++ b/{{cookiecutter.project_slug}}/pyproject.toml @@ -59,8 +59,7 @@ commands = [ ] [tool.tox.env.format] -deps = ["autopep8"] -deps = ["black"] +deps = ["autopep8", "black"] commands = [ ["python", "-m", "autopep8", "-v", "-aa", "--in-place", "--recursive", { replace = "posargs", default = ["{{cookiecutter.project_slug}}", "tests"], extend = true }], ["python", "-m", "black", "-v", { replace = "posargs", default = ["{{cookiecutter.project_slug}}", "tests"], extend = true }] -- GitLab From c794fac67f57382af474e6f6692c6576ec653292 Mon Sep 17 00:00:00 2001 From: Hannes Feldt <feldt@astron.nl> Date: Tue, 11 Mar 2025 09:14:50 +0100 Subject: [PATCH 18/28] various fixes and migration to ruff --- cookiecutter.json | 1 + {{cookiecutter.project_slug}}/.gitlab-ci.yml | 16 +----- .../.pre-commit-config.yaml | 24 ++------- {{cookiecutter.project_slug}}/pyproject.toml | 49 ++++++++++--------- {{cookiecutter.project_slug}}/setup.cfg | 12 ++--- 5 files changed, 35 insertions(+), 67 deletions(-) diff --git a/cookiecutter.json b/cookiecutter.json index c142007..32a8bf6 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -1,6 +1,7 @@ { "project_name": "My Awesome App", "project_slug": "{{ cookiecutter.project_name.lower()|replace(' ', '_')|replace('-', '_')|replace('.', '_')|trim() }}", + "project_package": "{{ cookiecutter.project_name.lower()|replace(' ', '-')|replace('_', '-')|replace('.', '-')|trim() }}", "project_url": "git.astron.nl/{{ cookiecutter.project_slug }}", "description": "An example package for CI/CD working group" } diff --git a/{{cookiecutter.project_slug}}/.gitlab-ci.yml b/{{cookiecutter.project_slug}}/.gitlab-ci.yml index aa5bf08..d03ae6e 100644 --- a/{{cookiecutter.project_slug}}/.gitlab-ci.yml +++ b/{{cookiecutter.project_slug}}/.gitlab-ci.yml @@ -34,22 +34,10 @@ trigger_prepare: strategy: depend include: .prepare.gitlab-ci.yml -run_black: +run_lint: stage: lint script: - - tox -e black - allow_failure: true - -run_flake8: - stage: lint - script: - - tox -e pep8 - allow_failure: true - -run_pylint: - stage: lint - script: - - tox -e pylint + - tox -e lint allow_failure: true # build_extensions: diff --git a/{{cookiecutter.project_slug}}/.pre-commit-config.yaml b/{{cookiecutter.project_slug}}/.pre-commit-config.yaml index 2980237..ce46e64 100644 --- a/{{cookiecutter.project_slug}}/.pre-commit-config.yaml +++ b/{{cookiecutter.project_slug}}/.pre-commit-config.yaml @@ -1,4 +1,4 @@ -default_stages: [ commit, push ] +default_stages: [ pre-commit, pre-push ] default_language_version: python: python3 exclude: '^docs/.*\.py$' @@ -14,25 +14,9 @@ repos: - id: detect-private-key - repo: local hooks: - - id: tox-black - name: tox-black (local) + - id: tox-lint + name: tox-lint (local) entry: tox language: python types: [file, python] - args: ["-e", "black", "--"] - - repo: local - hooks: - - id: tox-pep8 - name: tox-pep8 (local) - entry: tox - language: python - types: [file, python] - args: ["-e", "pep8", "--"] - - repo: local - hooks: - - id: tox-pylint - name: tox-pylint (local) - entry: tox - language: python - types: [file, python] - args: ["-e", "pylint", "--"] + args: ["-e", "lint", "--"] diff --git a/{{cookiecutter.project_slug}}/pyproject.toml b/{{cookiecutter.project_slug}}/pyproject.toml index 6b37726..c9a684b 100644 --- a/{{cookiecutter.project_slug}}/pyproject.toml +++ b/{{cookiecutter.project_slug}}/pyproject.toml @@ -9,13 +9,25 @@ build-backend = "setuptools.build_meta" [tool.setuptools_scm] version_file = "{{cookiecutter.project_slug}}/_version.py" -[tool.pylint] -ignore = "_version.py" +[tool.ruff] +exclude = [ + ".venv", + ".git", + ".tox", + "dist", + "docs", + "*lib/python*", + "*egg", + "_version.py" +] + +[tool.ruff.lint] +ignore = ["E203"] [tool.tox] # Generative environment list to test all supported Python versions requires = ["tox>=4.21"] -env_list = ["fix", "pep8", "black", "pylint", "py{13, 12, 11, 10, 9}"] +env_list = ["fix", "coverage", "lint", "format", "py{13, 12, 11, 10}"] [tool.tox.env_run_base] package = "editable" @@ -37,32 +49,21 @@ commands = [ ["python", "-m", "pytest", "--cov-report", "term", "--cov-report", "xml", "--cov-report", "html", "--cov={{cookiecutter.project_slug}}"]] # Command prefixes to reuse the same virtualenv for all linting jobs. -[tool.tox.env.pep8] -deps = ["flake8"] -commands = [ - ["python", "-m", "flake8", "--version"], - ["python", "-m", "flake8", { replace = "posargs", default = ["{{cookiecutter.project_slug}}", "tests"], extend = true }] -] - -[tool.tox.env.black] -deps = ["black"] -commands = [ - ["python", "-m", "black", "--version"], - ["python", "-m", "black", "--check", "--diff", { replace = "posargs", default = ["{{cookiecutter.project_slug}}", "tests"], extend = true }] -] - -[tool.tox.env.pylint] -deps = ["pylint"] +[tool.tox.env.lint] +deps = [ + "ruff", + "-r{toxinidir}/tests/requirements.txt"] commands = [ - ["python", "-m", "pylint", "--version"], - ["python", "-m", "pylint", { replace = "posargs", default = ["{{cookiecutter.project_slug}}", "tests"], extend = true }] + ["python", "-m", "ruff", "--version"], + ["python", "-m", "ruff", "check", { replace = "posargs", default = ["{{cookiecutter.project_slug}}", "tests"], extend = true }] ] [tool.tox.env.format] -deps = ["autopep8", "black"] +deps = [ + "ruff", + "-r{toxinidir}/tests/requirements.txt"] commands = [ - ["python", "-m", "autopep8", "-v", "-aa", "--in-place", "--recursive", { replace = "posargs", default = ["{{cookiecutter.project_slug}}", "tests"], extend = true }], - ["python", "-m", "black", "-v", { replace = "posargs", default = ["{{cookiecutter.project_slug}}", "tests"], extend = true }] + ["python", "-m", "ruff", "format", "-v", { replace = "posargs", default = ["{{cookiecutter.project_slug}}", "tests"], extend = true }] ] [tool.tox.env.docs] diff --git a/{{cookiecutter.project_slug}}/setup.cfg b/{{cookiecutter.project_slug}}/setup.cfg index a5fbebf..593b4a2 100644 --- a/{{cookiecutter.project_slug}}/setup.cfg +++ b/{{cookiecutter.project_slug}}/setup.cfg @@ -1,6 +1,6 @@ [metadata] -name = {{cookiecutter.project_slug}} -description = An example package for CI/CD working group +name = {{cookiecutter.project_package}} +description = {{cookiecutter.description}} long_description = file: README.md long_description_content_type = text/markdown url = https://git.astron.nl/templates/python-package @@ -15,7 +15,6 @@ classifiers = Programming Language :: Python Programming Language :: Python :: 3 Programming Language :: Python :: 3 :: Only - Programming Language :: Python :: 3.9 Programming Language :: Python :: 3.10 Programming Language :: Python :: 3.11 Programming Language :: Python :: 3.12 @@ -28,10 +27,5 @@ classifiers = [options] include_package_data = true packages = find: -python_requires = >=3.9 +python_requires = >=3.10 install_requires = file: requirements.txt - -[flake8] -max-line-length = 88 -extend-ignore = E203 -exclude=.venv,.git,.tox,dist,docs,*lib/python*,*egg,_version.py -- GitLab From 36ee9a6ed12dc7d8bcdc98e3f2943bc3fc16f34f Mon Sep 17 00:00:00 2001 From: Hannes Feldt <feldt@astron.nl> Date: Tue, 11 Mar 2025 09:18:49 +0100 Subject: [PATCH 19/28] reduce artifact size --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 32539e2..701a4df 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -28,6 +28,7 @@ build-template: - tox -e fix - rm -r .venv - rm -r .git + - rm -r .tox # cannot use needs, for artifacts on child pipeline so must regenerate template! artifacts: paths: -- GitLab From 5395f761b45bf55c57cbe43bc6ea1d39cf1d2037 Mon Sep 17 00:00:00 2001 From: Hannes Feldt <feldt@astron.nl> Date: Tue, 11 Mar 2025 09:22:08 +0100 Subject: [PATCH 20/28] fix ci --- project.gitlab-ci.yml | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/project.gitlab-ci.yml b/project.gitlab-ci.yml index 2d6eb42..5e8736e 100644 --- a/project.gitlab-ci.yml +++ b/project.gitlab-ci.yml @@ -15,17 +15,7 @@ default: before_script: - cd my_awesome_app -run_black: - needs: - - pipeline: $PARENT_PIPELINE_ID - job: build-template - -run_flake8: - needs: - - pipeline: $PARENT_PIPELINE_ID - job: build-template - -run_pylint: +run_lint: needs: - pipeline: $PARENT_PIPELINE_ID job: build-template @@ -128,4 +118,4 @@ publish_to_readthedocs: release_job: needs: - pipeline: $PARENT_PIPELINE_ID - job: build-template \ No newline at end of file + job: build-template -- GitLab From 2e7267dfdb9aae209b8301e58600dbf37404ac3f Mon Sep 17 00:00:00 2001 From: Hannes Feldt <feldt@astron.nl> Date: Tue, 11 Mar 2025 09:23:39 +0100 Subject: [PATCH 21/28] fix --- {{cookiecutter.project_slug}}/setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/{{cookiecutter.project_slug}}/setup.cfg b/{{cookiecutter.project_slug}}/setup.cfg index 593b4a2..237668c 100644 --- a/{{cookiecutter.project_slug}}/setup.cfg +++ b/{{cookiecutter.project_slug}}/setup.cfg @@ -3,7 +3,7 @@ name = {{cookiecutter.project_package}} description = {{cookiecutter.description}} long_description = file: README.md long_description_content_type = text/markdown -url = https://git.astron.nl/templates/python-package +url = {{cookiecutter.project_url}} license = Apache License 2.0 classifiers = Development Status :: 3 - Alpha -- GitLab From ff832308070dd067d762ee416693cb0d24e00984 Mon Sep 17 00:00:00 2001 From: Hannes Feldt <feldt@astron.nl> Date: Tue, 11 Mar 2025 09:32:40 +0100 Subject: [PATCH 22/28] test --- project.gitlab-ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/project.gitlab-ci.yml b/project.gitlab-ci.yml index 5e8736e..aa64a0a 100644 --- a/project.gitlab-ci.yml +++ b/project.gitlab-ci.yml @@ -5,6 +5,9 @@ # The generated gitlab-ci.yml from this `build-template` job is used for the actual # trigger include to prevent including jobs that still contain template arguments +variables: + SETUPTOOLS_SCM_PRETEND_VERSION_FOR_my_awesome_app: "1.0.0" + trigger_prepare: rules: - if: $CI_PIPELINE_SOURCE == "parent_pipeline" -- GitLab From 20b5d323e48b0246d3e95d8c7602282311e95fbf Mon Sep 17 00:00:00 2001 From: Hannes Feldt <feldt@astron.nl> Date: Tue, 11 Mar 2025 09:37:33 +0100 Subject: [PATCH 23/28] test --- project.gitlab-ci.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/project.gitlab-ci.yml b/project.gitlab-ci.yml index aa64a0a..5e8736e 100644 --- a/project.gitlab-ci.yml +++ b/project.gitlab-ci.yml @@ -5,9 +5,6 @@ # The generated gitlab-ci.yml from this `build-template` job is used for the actual # trigger include to prevent including jobs that still contain template arguments -variables: - SETUPTOOLS_SCM_PRETEND_VERSION_FOR_my_awesome_app: "1.0.0" - trigger_prepare: rules: - if: $CI_PIPELINE_SOURCE == "parent_pipeline" -- GitLab From 07664ba80341bba41604a1d62f0908b806fbf41f Mon Sep 17 00:00:00 2001 From: Hannes Feldt <feldt@astron.nl> Date: Tue, 11 Mar 2025 09:42:15 +0100 Subject: [PATCH 24/28] test --- .gitlab-ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 701a4df..227fb9c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -29,11 +29,14 @@ build-template: - rm -r .venv - rm -r .git - rm -r .tox + - echo SETUPTOOLS_SCM_PRETEND_VERSION_FOR_my_awesome_app="1.0.0" >> $CI_PROJECT_DIR/build.env # cannot use needs, for artifacts on child pipeline so must regenerate template! artifacts: paths: - my_awesome_app/* - project.gitlab-ci.yml + reports: + dotenv: build.env # Spawn pipeline using the gitlab-ci.yml from generated template instance # use project.gitlab.ci.yml for necessary job overrides from this template instance -- GitLab From 1f64a5a2e31ba3677ca026970cf88483935e35e0 Mon Sep 17 00:00:00 2001 From: Hannes Feldt <feldt@astron.nl> Date: Tue, 11 Mar 2025 09:53:25 +0100 Subject: [PATCH 25/28] test --- project.gitlab-ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/project.gitlab-ci.yml b/project.gitlab-ci.yml index 5e8736e..2a48892 100644 --- a/project.gitlab-ci.yml +++ b/project.gitlab-ci.yml @@ -5,6 +5,7 @@ # The generated gitlab-ci.yml from this `build-template` job is used for the actual # trigger include to prevent including jobs that still contain template arguments + trigger_prepare: rules: - if: $CI_PIPELINE_SOURCE == "parent_pipeline" @@ -12,6 +13,9 @@ trigger_prepare: default: # Bootstrap Cookiecutter template to test provided ci pipeline template + variables: + SETUPTOOLS_SCM_PRETEND_VERSION: "1.0.0" + SETUPTOOLS_SCM_PRETEND_VERSION_FOR_my_awesome_app: "1.0.0" before_script: - cd my_awesome_app -- GitLab From 69b762ef66c0ae15a0b4f43e0c0d7e5270a14526 Mon Sep 17 00:00:00 2001 From: Hannes Feldt <feldt@astron.nl> Date: Tue, 11 Mar 2025 10:19:47 +0100 Subject: [PATCH 26/28] test --- .gitlab-ci.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 227fb9c..701a4df 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -29,14 +29,11 @@ build-template: - rm -r .venv - rm -r .git - rm -r .tox - - echo SETUPTOOLS_SCM_PRETEND_VERSION_FOR_my_awesome_app="1.0.0" >> $CI_PROJECT_DIR/build.env # cannot use needs, for artifacts on child pipeline so must regenerate template! artifacts: paths: - my_awesome_app/* - project.gitlab-ci.yml - reports: - dotenv: build.env # Spawn pipeline using the gitlab-ci.yml from generated template instance # use project.gitlab.ci.yml for necessary job overrides from this template instance -- GitLab From e5e6ea06aec5c5bec20ed1a8a637a3210fff0b09 Mon Sep 17 00:00:00 2001 From: Hannes Feldt <feldt@astron.nl> Date: Tue, 11 Mar 2025 10:28:11 +0100 Subject: [PATCH 27/28] test --- .gitlab-ci.yml | 1 - project.gitlab-ci.yml | 3 --- 2 files changed, 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 701a4df..20272ac 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -27,7 +27,6 @@ build-template: - pip install --upgrade tox - tox -e fix - rm -r .venv - - rm -r .git - rm -r .tox # cannot use needs, for artifacts on child pipeline so must regenerate template! artifacts: diff --git a/project.gitlab-ci.yml b/project.gitlab-ci.yml index 2a48892..740497a 100644 --- a/project.gitlab-ci.yml +++ b/project.gitlab-ci.yml @@ -13,9 +13,6 @@ trigger_prepare: default: # Bootstrap Cookiecutter template to test provided ci pipeline template - variables: - SETUPTOOLS_SCM_PRETEND_VERSION: "1.0.0" - SETUPTOOLS_SCM_PRETEND_VERSION_FOR_my_awesome_app: "1.0.0" before_script: - cd my_awesome_app -- GitLab From 90a0b4e03b291c126205286354bfcf1d070c5413 Mon Sep 17 00:00:00 2001 From: Hannes Feldt <feldt@astron.nl> Date: Tue, 11 Mar 2025 11:57:18 +0100 Subject: [PATCH 28/28] fix --- {{cookiecutter.project_slug}}/.gitlab-ci.yml | 2 +- {{cookiecutter.project_slug}}/pyproject.toml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/{{cookiecutter.project_slug}}/.gitlab-ci.yml b/{{cookiecutter.project_slug}}/.gitlab-ci.yml index 6be1618..b4e3610 100644 --- a/{{cookiecutter.project_slug}}/.gitlab-ci.yml +++ b/{{cookiecutter.project_slug}}/.gitlab-ci.yml @@ -79,7 +79,7 @@ run_unit_tests: - tox -e py3${PY_VERSION} parallel: matrix: # use the matrix for testing - - PY_VERSION: [9, 10, 11, 12, 13] + - PY_VERSION: [9, 10, 11, 12] # Run code coverage on the base image thus also performing unit tests run_unit_tests_coverage: diff --git a/{{cookiecutter.project_slug}}/pyproject.toml b/{{cookiecutter.project_slug}}/pyproject.toml index c9a684b..f9ef33d 100644 --- a/{{cookiecutter.project_slug}}/pyproject.toml +++ b/{{cookiecutter.project_slug}}/pyproject.toml @@ -35,7 +35,7 @@ deps = [ "-r{toxinidir}/requirements.txt", "-r{toxinidir}/tests/requirements.txt"] set_env = { LANGUAGE = "en_US", LC_ALL = "en_US.UTF-8", PYTHONWARNINGS = "default::DeprecationWarning" } -commands = [["python", "--version"], ["python", "-m", "pytest"]] +commands = [["python", "--version"], ["python", "-m", "pytest", "tests/{posargs}"]] [tool.tox.env.fix] description = "format the code base to adhere to our styles, and complain about what we cannot do automatically" @@ -46,7 +46,7 @@ commands = [["pre-commit", "run", "--all-files", "--show-diff-on-failure"]] [tool.tox.env.coverage] commands = [ ["python", "--version"], - ["python", "-m", "pytest", "--cov-report", "term", "--cov-report", "xml", "--cov-report", "html", "--cov={{cookiecutter.project_slug}}"]] + ["python", "-m", "pytest", "--cov-report", "term", "--cov-report", "xml", "--cov-report", "html", "--cov={{cookiecutter.project_slug}}", "tests/{posargs}"]] # Command prefixes to reuse the same virtualenv for all linting jobs. [tool.tox.env.lint] -- GitLab