From 4f25069ead6ed6ff0e3b5b8393e66f431b5b8da0 Mon Sep 17 00:00:00 2001 From: Tobias Raabe Date: Tue, 24 Dec 2024 20:46:55 +0100 Subject: [PATCH 1/5] Update infra. --- .github/workflows/main.yml | 19 +++- .gitignore | 1 + .pre-commit-config.yaml | 33 +++--- cookiecutter.json | 1 - hooks/pre_gen_project.py | 2 +- pyproject.toml | 15 ++- requirements-dev.lock | 80 -------------- requirements.lock | 52 --------- .../.github/workflows/main.yml | 17 ++- .../.pre-commit-config.yaml | 46 ++++---- {{cookiecutter.project_slug}}/pyproject.toml | 100 ++++++++++-------- 11 files changed, 129 insertions(+), 237 deletions(-) delete mode 100644 requirements-dev.lock delete mode 100644 requirements.lock diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6f5f62d..e73b29a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -15,6 +15,21 @@ on: jobs: + run-type-checking: + + name: Run tests for type-checking + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version-file: .python-version + allow-prereleases: true + cache: pip + - run: pip install tox-uv + - run: tox -e typing + run-tests: name: Run tests for ${{ matrix.os }} on ${{ matrix.python-version }} @@ -24,7 +39,7 @@ jobs: fail-fast: false matrix: os: ['ubuntu-latest', 'macos-latest', 'windows-latest'] - python-version: ['3.8', '3.9', '3.10', '3.11', '3.12'] + python-version: ['3.9', '3.10', '3.11', '3.12', '3.13'] steps: - uses: actions/checkout@v4 @@ -35,7 +50,7 @@ jobs: allow-prereleases: true - uses: prefix-dev/setup-pixi@v0.8.1 with: - pixi-version: v0.22.0 + pixi-version: v0.34.3 run-install: false - run: pip install tox-uv diff --git a/.gitignore b/.gitignore index 04dcee8..420289a 100644 --- a/.gitignore +++ b/.gitignore @@ -151,3 +151,4 @@ dist .ruff_cache .mypy_cache +uv.lock diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a35857b..87839e7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -15,7 +15,6 @@ repos: - id: check-yaml exclude: | (?x)^( - {{cookiecutter.project_slug}}/environment.yml| {{cookiecutter.project_slug}}/.pre-commit-config.yaml )$ - id: debug-statements @@ -34,10 +33,6 @@ repos: - id: python-no-log-warn - id: python-use-type-annotations - id: text-unicode-replacement-char -- repo: https://github.com/aio-libs/sort-all - rev: v1.3.0 - hooks: - - id: sort-all - repo: https://github.com/astral-sh/ruff-pre-commit rev: v0.8.4 hooks: @@ -46,18 +41,13 @@ repos: pass_filenames: false - id: ruff-format args: [--config, pyproject.toml] -- repo: https://github.com/dosisod/refurb - rev: v2.0.0 - hooks: - - id: refurb - exclude: ({{cookiecutter.project_slug}}) - repo: https://github.com/executablebooks/mdformat rev: 0.7.21 hooks: - id: mdformat additional_dependencies: [ mdformat-gfm, - mdformat-black, + mdformat-ruff, ] args: [--wrap, "88"] files: (README\.md) @@ -71,22 +61,23 @@ repos: - id: mdformat additional_dependencies: [ mdformat-myst, - mdformat-black, + mdformat-ruff, ] args: [--wrap, "88"] files: (docs/.) -- repo: https://github.com/codespell-project/codespell - rev: v2.3.0 - hooks: - - id: codespell - additional_dependencies: [tomli] -- repo: https://github.com/pre-commit/mirrors-mypy - rev: 'v1.14.0' +- repo: https://github.com/crate-ci/typos + rev: v1.28.4 hooks: - - id: mypy - pass_filenames: false + - id: typos - repo: meta hooks: - id: check-hooks-apply - id: check-useless-excludes # - id: identity # Prints all files passed to pre-commits. Debugging. +- repo: local + hooks: + - id: typing + name: typing + language: system + entry: uv run tox -e typing + pass_filenames: false diff --git a/cookiecutter.json b/cookiecutter.json index 364b088..c9d80e5 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -9,7 +9,6 @@ "python_version": "3.10", "add_tox": ["yes", "no"], "add_github_actions": ["yes", "no"], - "add_mypy": ["yes", "no"], "add_readthedocs": ["yes", "no"], "open_source_license": [ "MIT", diff --git a/hooks/pre_gen_project.py b/hooks/pre_gen_project.py index e3db32d..ad53f4f 100644 --- a/hooks/pre_gen_project.py +++ b/hooks/pre_gen_project.py @@ -5,7 +5,7 @@ MODULE_REGEX = r"^[_a-zA-Z][_a-zA-Z0-9]*$" ENVIRON_REGEX = r"^[-_a-zA-Z0-9]*$" PYTHONVERSION_REGEX = r"^(3\.(1[0-9]|[8-9])(\.[0-9]{1,2})?)$" -PYTHONVERSION_MIN = "3.8" +PYTHONVERSION_MIN = "3.9" EXCEPTION_MSG_MODULE_NAME = """ ERROR: The project slug ({module_name}) is not a valid Python module name. diff --git a/pyproject.toml b/pyproject.toml index 94ed373..f44a38b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,13 +15,16 @@ classifiers = [ "Topic :: Scientific/Engineering", "Topic :: Software Development :: Build Tools", ] -requires-python = ">=3.8" +requires-python = ">=3.9" dependencies = ["cookiecutter"] [[project.authors]] name = "Tobias Raabe" email = "raabe@posteo.de" +[tool.uv] +dev-dependencies = ["tox-uv>=1.7.0"] + [project.optional-dependencies] docs = [ "furo", @@ -36,6 +39,7 @@ docs = [ "sphinxext-opengraph", ] test = ["pytest", "pytest-cookies", "pytest-cov"] +typing = ["mypy"] [project.readme] file = "README.md" @@ -51,13 +55,6 @@ Documentation = "https://cookiecutter-pytask-project.readthedocs.io/en/latest" Github = "https://github.com/pytask-dev/cookiecutter-pytask-project" Tracker = "https://github.com/pytask-dev/cookiecutter-pytask-project/issues" -[tool.rye] -managed = true -virtual = true -dev-dependencies = [ - "tox-uv>=1.8.2", -] - [tool.mypy] files = ["hooks", "tests"] exclude = "{{cookiecutter.project_slug}}" @@ -75,7 +72,7 @@ disallow_untyped_defs = false ignore_errors = true [tool.ruff] -target-version = "py38" +target-version = "py39" fix = true unsafe-fixes = true diff --git a/requirements-dev.lock b/requirements-dev.lock deleted file mode 100644 index e848340..0000000 --- a/requirements-dev.lock +++ /dev/null @@ -1,80 +0,0 @@ -# generated by rye -# use `rye lock` or `rye sync` to update this lockfile -# -# last locked with the following flags: -# pre: false -# features: [] -# all-features: true -# with-sources: false - -arrow==1.3.0 - # via cookiecutter -binaryornot==0.4.4 - # via cookiecutter -cachetools==5.3.3 - # via tox -certifi==2024.2.2 - # via requests -chardet==5.2.0 - # via binaryornot - # via tox -charset-normalizer==3.3.2 - # via requests -click==8.1.7 - # via cookiecutter -colorama==0.4.6 - # via tox -cookiecutter==2.6.0 -distlib==0.3.8 - # via virtualenv -filelock==3.14.0 - # via tox - # via virtualenv -idna==3.7 - # via requests -jinja2==3.1.3 - # via cookiecutter -markdown-it-py==3.0.0 - # via rich -markupsafe==2.1.5 - # via jinja2 -mdurl==0.1.2 - # via markdown-it-py -packaging==24.0 - # via pyproject-api - # via tox - # via tox-uv -platformdirs==4.2.1 - # via tox - # via virtualenv -pluggy==1.5.0 - # via tox -pygments==2.17.2 - # via rich -pyproject-api==1.6.1 - # via tox -python-dateutil==2.9.0.post0 - # via arrow -python-slugify==8.0.4 - # via cookiecutter -pyyaml==6.0.1 - # via cookiecutter -requests==2.31.0 - # via cookiecutter -rich==13.7.1 - # via cookiecutter -six==1.16.0 - # via python-dateutil -text-unidecode==1.3 - # via python-slugify -tox==4.15.0 - # via tox-uv -tox-uv==1.8.2 -types-python-dateutil==2.9.0.20240316 - # via arrow -urllib3==2.2.1 - # via requests -uv==0.1.39 - # via tox-uv -virtualenv==20.26.1 - # via tox diff --git a/requirements.lock b/requirements.lock deleted file mode 100644 index c7f16f0..0000000 --- a/requirements.lock +++ /dev/null @@ -1,52 +0,0 @@ -# generated by rye -# use `rye lock` or `rye sync` to update this lockfile -# -# last locked with the following flags: -# pre: false -# features: [] -# all-features: true -# with-sources: false - -arrow==1.3.0 - # via cookiecutter -binaryornot==0.4.4 - # via cookiecutter -certifi==2024.2.2 - # via requests -chardet==5.2.0 - # via binaryornot -charset-normalizer==3.3.2 - # via requests -click==8.1.7 - # via cookiecutter -cookiecutter==2.6.0 -idna==3.7 - # via requests -jinja2==3.1.3 - # via cookiecutter -markdown-it-py==3.0.0 - # via rich -markupsafe==2.1.5 - # via jinja2 -mdurl==0.1.2 - # via markdown-it-py -pygments==2.17.2 - # via rich -python-dateutil==2.9.0.post0 - # via arrow -python-slugify==8.0.4 - # via cookiecutter -pyyaml==6.0.1 - # via cookiecutter -requests==2.31.0 - # via cookiecutter -rich==13.7.1 - # via cookiecutter -six==1.16.0 - # via python-dateutil -text-unidecode==1.3 - # via python-slugify -types-python-dateutil==2.9.0.20240316 - # via arrow -urllib3==2.2.1 - # via requests diff --git a/{{cookiecutter.project_slug}}/.github/workflows/main.yml b/{{cookiecutter.project_slug}}/.github/workflows/main.yml index 807e6f5..f031eb4 100644 --- a/{{cookiecutter.project_slug}}/.github/workflows/main.yml +++ b/{{cookiecutter.project_slug}}/.github/workflows/main.yml @@ -15,6 +15,19 @@ on: jobs: + run-type-checking: + + name: Run tests for type-checking + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - uses: prefix-dev/setup-pixi@v0.8.1 + with: + pixi-version: v0.34.3 + cache: true + - run: pixi run typing + run-tests: name: Run tests for ${{ matrix.os }} on ${{ matrix.python-version }} @@ -28,9 +41,9 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: prefix-dev/setup-pixi@v0.7.0 + - uses: prefix-dev/setup-pixi@v0.8.1 with: - pixi-version: v0.22.0 + pixi-version: v0.34.3 cache: true - name: Run tests and doctests. diff --git a/{{cookiecutter.project_slug}}/.pre-commit-config.yaml b/{{cookiecutter.project_slug}}/.pre-commit-config.yaml index 0a5cd0d..22cbe6e 100644 --- a/{{cookiecutter.project_slug}}/.pre-commit-config.yaml +++ b/{{cookiecutter.project_slug}}/.pre-commit-config.yaml @@ -1,6 +1,9 @@ +ci: + skip: [typing] + repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.6.0 + rev: v5.0.0 hooks: - id: check-added-large-files args: ['--maxkb=25'] @@ -24,55 +27,44 @@ repos: - id: python-no-log-warn - id: python-use-type-annotations - id: text-unicode-replacement-char -- repo: https://github.com/aio-libs/sort-all - rev: v1.2.0 - hooks: - - id: sort-all - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: v0.4.4 + rev: v0.8.4 hooks: - id: ruff - id: ruff-format -{% if cookiecutter.python_version in ["3.10", "3.11", "3.12"] %}- repo: https://github.com/dosisod/refurb - rev: v2.0.0 - hooks: - - id: refurb -{% endif %} - repo: https://github.com/executablebooks/mdformat - rev: 0.7.17 + rev: 0.7.21 hooks: - id: mdformat additional_dependencies: [ mdformat-gfm, - mdformat-black, + mdformat-ruff, ] args: [--wrap, "88"] files: (README\.md) - repo: https://github.com/executablebooks/mdformat - rev: 0.7.17 + rev: 0.7.21 hooks: - id: mdformat additional_dependencies: [ mdformat-myst, - mdformat-black, + mdformat-ruff, ] args: [--wrap, "88"] files: (docs/.) -{% if cookiecutter.add_mypy == "yes" %}- repo: https://github.com/pre-commit/mirrors-mypy - rev: 'v1.10.0' +- repo: https://github.com/crate-ci/typos + rev: v1.28.4 hooks: - - id: mypy - args: [ - --no-strict-optional, - --ignore-missing-imports, - ] - pass_filenames: false -{% endif %}- repo: https://github.com/codespell-project/codespell - rev: v2.2.6 - hooks: - - id: codespell + - id: typos - repo: meta hooks: - id: check-hooks-apply - id: check-useless-excludes # - id: identity # Prints all files passed to pre-commits. Debugging. +- repo: local + hooks: + - id: typing + name: typing + language: system + entry: pixi run typing + pass_filenames: false diff --git a/{{cookiecutter.project_slug}}/pyproject.toml b/{{cookiecutter.project_slug}}/pyproject.toml index e41393b..adbe51d 100644 --- a/{{cookiecutter.project_slug}}/pyproject.toml +++ b/{{cookiecutter.project_slug}}/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "hatchling.build" name = "{{ cookiecutter.project_slug }}" version = "0.1.0" description = "{{ cookiecutter.project_description }}" -requires-python = ">=3.8" +requires-python = ">=3.9" classifiers = [ "Intended Audience :: Science/Research", "License :: OSI Approved :: {{ cookiecutter.open_source_license }} License", @@ -16,7 +16,6 @@ classifiers = [ "Programming Language :: Python :: 3", "Programming Language :: Python :: 3 :: Only", ] -dependencies = ["pytask"] [project.readme] file = "README.md" @@ -29,27 +28,66 @@ text = "{{ cookiecutter.open_source_license }}" name = "{{ cookiecutter.author }}" email = "{{ cookiecutter.email }}" -[project.optional-dependencies] -docs = [ - "furo", - "ipython", - "myst-parser", - "nbsphinx", - "sphinx", - "sphinx-copybutton", - "sphinx-design>=0.3", - "sphinx-toolbox", - "sphinxext-opengraph", -] -test = ["pytest", "pytest-cov", "pytest-xdist"] - [project.urls] Changelog = "https://github.com/{{ cookiecutter.github_username }}/{{ cookiecutter.project_slug }}" Documentation = "https://github.com/{{ cookiecutter.github_username }}/{{ cookiecutter.project_slug }}" Github = "https://github.com/{{ cookiecutter.github_username }}/{{ cookiecutter.project_slug }}" Tracker = "https://github.com/{{ cookiecutter.github_username }}/{{ cookiecutter.project_slug }}/issues" -{% if cookiecutter.add_mypy == "yes" %}[tool.mypy] +[tool.pixi.project] +channels = ["conda-forge"] +platforms = ["win-64", "linux-64", "osx-64", "osx-arm64"] + +[tool.pixi.tasks] + +[tool.pixi.dependencies] +pytask = ">=0.5.0" + +[tool.pixi.pypi-dependencies] +"{{ cookiecutter.project_slug }}" = { path = ".", editable = true } + +[tool.pixi.feature.docs.tasks] +docs = "sphinx-build -b html docs/source docs/build" + +[tool.pixi.feature.docs.dependencies] +furo = "*" +ipython = "*" +myst-parser = "*" +nbsphinx = "*" +sphinx = "*" +sphinx-copybutton = "*" +sphinx-design = ">=0.3" +sphinx-toolbox = "*" +sphinxext-opengraph = "*" + +[tool.pixi.feature.test.tasks] +test = "pytest --cov src --cov tests" + +[tool.pixi.feature.test.dependencies] +pytest = "*" +pytest-cov = "*" +pytest-xdist = "*" + +[tool.pixi.feature.typing.tasks] +typing = "mypy" + +[tool.pixi.feature.typing.dependencies] +mypy = "*" + +[tool.pixi.feature.dev.tasks] +nb = "jupyter lab --no-browser" + +[tool.pixi.feature.dev.dependencies] +jupyterlab = "*" +# pixi-pycharm = "*" + +[tool.pixi.environments] +default = { features = ["dev", "docs", "test"], solve-group = "default" } +docs = { features = ["docs"], solve-group = "default" } +repro = { features = [], solve-group = "default" } +typing = { features = ["typing"], solve-group = "default" } + +[tool.mypy] files = ["src", "tests"] check_untyped_defs = true disallow_any_generics = true @@ -58,12 +96,13 @@ disallow_untyped_defs = true no_implicit_optional = true warn_redundant_casts = true warn_unused_ignores = true +ignore_missing_imports = true [[tool.mypy.overrides]] -ignore_errors = true module = "tests.*" +ignore_errors = true disallow_untyped_defs = false -{% endif %} + [tool.pytask.ini_options] paths = ["src/{{ cookiecutter.project_slug }}"] @@ -93,26 +132,3 @@ convention = "numpy" addopts = ["--doctest-modules"] testpaths = ["src", "tests"] norecursedirs = [".idea", ".tox"] - -[tool.pixi.project] -channels = ["conda-forge"] -platforms = ["win-64", "linux-64", "osx-64", "osx-arm64"] - -[tool.pixi.dependencies] -pytask = ">=0.4.7,<0.5" - -[tool.pixi.pypi-dependencies] -{{ cookiecutter.project_slug }} = { path = ".", editable = true } - -[tool.pixi.environments] -default = { solve-group = "default" } -docs = { features = ["docs"], solve-group = "default" } -test = { features = ["test"], solve-group = "default" } - -[tool.pixi.tasks] - -[tool.pixi.feature.test.tasks] -test = "pytest --cov src --cov tests" - -[tool.pixi.feature.docs.tasks] -docs = "sphinx-build -b html docs/source docs/build" From 58e1b9884bf4e0c4b1a20f3be4b36fbb8c112ea1 Mon Sep 17 00:00:00 2001 From: Tobias Raabe Date: Tue, 24 Dec 2024 20:51:23 +0100 Subject: [PATCH 2/5] Fix pixi version. --- .github/workflows/main.yml | 2 +- {{cookiecutter.project_slug}}/.github/workflows/main.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e73b29a..b473db5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -50,7 +50,7 @@ jobs: allow-prereleases: true - uses: prefix-dev/setup-pixi@v0.8.1 with: - pixi-version: v0.34.3 + pixi-version: v0.39.4 run-install: false - run: pip install tox-uv diff --git a/{{cookiecutter.project_slug}}/.github/workflows/main.yml b/{{cookiecutter.project_slug}}/.github/workflows/main.yml index f031eb4..f2557ad 100644 --- a/{{cookiecutter.project_slug}}/.github/workflows/main.yml +++ b/{{cookiecutter.project_slug}}/.github/workflows/main.yml @@ -24,7 +24,7 @@ jobs: - uses: actions/checkout@v4 - uses: prefix-dev/setup-pixi@v0.8.1 with: - pixi-version: v0.34.3 + pixi-version: v0.39.4 cache: true - run: pixi run typing @@ -43,7 +43,7 @@ jobs: - uses: actions/checkout@v4 - uses: prefix-dev/setup-pixi@v0.8.1 with: - pixi-version: v0.34.3 + pixi-version: v0.39.4 cache: true - name: Run tests and doctests. From aae86d2efdaa6f870e8630be4d0307eb35287943 Mon Sep 17 00:00:00 2001 From: Tobias Raabe Date: Tue, 24 Dec 2024 20:52:52 +0100 Subject: [PATCH 3/5] Fix pre-commit. --- .pre-commit-config.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 87839e7..5fa8e9c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,3 +1,6 @@ +ci: + skip: [typing] + exclude: | (?x)^( {{cookiecutter.project_slug}}/tests/test_import.py From 2615b1efd8009bfd70f5fb6aa025a15490268d7b Mon Sep 17 00:00:00 2001 From: Tobias Raabe Date: Tue, 24 Dec 2024 21:00:07 +0100 Subject: [PATCH 4/5] Document chagnes. --- docs/source/changes.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/source/changes.md b/docs/source/changes.md index 7cf458d..33af5c3 100644 --- a/docs/source/changes.md +++ b/docs/source/changes.md @@ -3,7 +3,11 @@ This is a record of all past cookiecutter-pytask-project releases and what went into them in reverse chronological order. -## 1.7.0 - 2024-xx-xx +## 1.8.0 - 2024-12-24 + +- {pull}`52` updates the template in many different ways. Better pre-commit hooks, better integration with pixi, mypy is not optional anymore, etc.. + +## 1.7.0 - 2024-05-03 - {pull}`39` updates the pre-commit hooks. - {pull}`41` updates the infrastructure. From 9942a61ef0f9caaccd287db7e266c9634ddf5da6 Mon Sep 17 00:00:00 2001 From: Tobias Raabe Date: Tue, 24 Dec 2024 21:00:16 +0100 Subject: [PATCH 5/5] Fix. --- docs/source/changes.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/source/changes.md b/docs/source/changes.md index 33af5c3..106f46b 100644 --- a/docs/source/changes.md +++ b/docs/source/changes.md @@ -5,7 +5,8 @@ them in reverse chronological order. ## 1.8.0 - 2024-12-24 -- {pull}`52` updates the template in many different ways. Better pre-commit hooks, better integration with pixi, mypy is not optional anymore, etc.. +- {pull}`52` updates the template in many different ways. Better pre-commit hooks, + better integration with pixi, mypy is not optional anymore, etc.. ## 1.7.0 - 2024-05-03