diff --git a/CHANGELOG.md b/CHANGELOG.md index ec7d3e4d..1413ea43 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,11 +4,12 @@ ### Added -- Typing support. [#698](https://github.com/NLeSC/python-template/pull/698) +* Typing support. [#698](https://github.com/NLeSC/python-template/pull/698) ### Changed * Recommend `ruff format` instead of `yapf` for fixing code style readability [#695](https://github.com/NLeSC/python-template/pull/695) +* Replace optional dependencies with dependency groups in template [#705](https://github.com/NLeSC/python-template/pull/705) ### Removed diff --git a/template/pyproject.toml.jinja b/template/pyproject.toml.jinja index 1a854574..6c155b8c 100644 --- a/template/pyproject.toml.jinja +++ b/template/pyproject.toml.jinja @@ -41,7 +41,7 @@ readme = {file = "README.md", content-type = "text/markdown"} requires-python = ">=3.10" version = "{{ version }}" -[project.optional-dependencies] +[dependency-groups] dev = [ "build", # build is not only used in publishing (below), but also in the template's test suite "bump-my-version", @@ -104,16 +104,16 @@ command_line = "-m pytest" {%- endif %} [tool.tox] -legacy_tox_ini = """ -[tox] -envlist = py310,py311,py312 +requires = ["tox>=4.22"] +env_list = [ "py310", "py311", "py312" ] skip_missing_interpreters = true {% if AddLocalTests -%} -[testenv] -commands = pytest -extras = dev +[tool.box.testenv] +description = "Run test under {base_python}" +commands = [["pytest"]] +[tool.tox.env_run_base] +dependency_groups = [ "dev" ] {%- endif %} -""" [tool.ruff] line-length = 79 diff --git a/template/{% if AddDevDoc %}README.dev.md{% endif %}.jinja b/template/{% if AddDevDoc %}README.dev.md{% endif %}.jinja index ebcb751a..f0d46201 100644 --- a/template/{% if AddDevDoc %}README.dev.md{% endif %}.jinja +++ b/template/{% if AddDevDoc %}README.dev.md{% endif %}.jinja @@ -18,9 +18,9 @@ python -m pip install --upgrade pip setuptools # install {{ package_name }} as an editable package python -m pip install --no-cache-dir --editable . # install development dependencies -python -m pip install --no-cache-dir --editable .[dev] +python -m pip install --no-cache-dir --editable . --group dev # install documentation dependencies only -python -m pip install --no-cache-dir --editable .[docs] +python -m pip install --no-cache-dir --editable . --group docs ``` Afterwards check that the install directory is present in the `PATH` environment variable. diff --git a/template/{% if HasWorkflows %}.github{% endif %}/workflows/{% if AddGitHubActionBuild %}build.yml{% endif %}.jinja b/template/{% if HasWorkflows %}.github{% endif %}/workflows/{% if AddGitHubActionBuild %}build.yml{% endif %}.jinja index 4bddbb36..a03678fa 100644 --- a/template/{% if HasWorkflows %}.github{% endif %}/workflows/{% if AddGitHubActionBuild %}build.yml{% endif %}.jinja +++ b/template/{% if HasWorkflows %}.github{% endif %}/workflows/{% if AddGitHubActionBuild %}build.yml{% endif %}.jinja @@ -32,7 +32,7 @@ jobs: - name: Upgrade pip and install dependencies run: | python -m pip install --upgrade pip setuptools - python -m pip install .[dev,publishing] + python -m pip install . --group dev --group publishing - name: Run unit tests run: python -m pytest -v - name: Verify that we can build the package @@ -58,7 +58,7 @@ jobs: - name: Upgrade pip and install dependencies run: | python -m pip install --upgrade pip setuptools - python -m pip install .[dev,publishing] + python -m pip install . --group dev - name: Check style against standards using ruff run: | ruff check . @@ -78,7 +78,7 @@ jobs: - name: Upgrade pip and install dependencies run: | python -m pip install --upgrade pip setuptools - python -m pip install .[dev] + python -m pip install . --group dev - name: Run {{ SelectTypeChecker }} run: | {{ SelectTypeChecker }} diff --git a/template/{% if HasWorkflows %}.github{% endif %}/workflows/{% if AddGitHubActionDocumentation %}documentation.yml{% endif %} b/template/{% if HasWorkflows %}.github{% endif %}/workflows/{% if AddGitHubActionDocumentation %}documentation.yml{% endif %} index af2d22b3..2c3096bb 100644 --- a/template/{% if HasWorkflows %}.github{% endif %}/workflows/{% if AddGitHubActionDocumentation %}documentation.yml{% endif %} +++ b/template/{% if HasWorkflows %}.github{% endif %}/workflows/{% if AddGitHubActionDocumentation %}documentation.yml{% endif %} @@ -28,7 +28,7 @@ jobs: - name: Upgrade pip and install dependencies run: | python -m pip install --upgrade pip setuptools - python -m pip install .[dev,publishing] + python -m pip install . --group dev --group docs - name: Install pandoc using apt run: sudo apt install pandoc - name: Build documentation diff --git a/template/{% if HasWorkflows %}.github{% endif %}/workflows/{% if AddSonarCloud %}sonarcloud.yml{% endif %} b/template/{% if HasWorkflows %}.github{% endif %}/workflows/{% if AddSonarCloud %}sonarcloud.yml{% endif %} index c28505a4..3d3b10ad 100644 --- a/template/{% if HasWorkflows %}.github{% endif %}/workflows/{% if AddSonarCloud %}sonarcloud.yml{% endif %} +++ b/template/{% if HasWorkflows %}.github{% endif %}/workflows/{% if AddSonarCloud %}sonarcloud.yml{% endif %} @@ -28,7 +28,7 @@ jobs: which python python --version - name: Install dependencies - run: python -m pip install .[dev] + run: python -m pip install . --group dev - name: Run unit tests with coverage run: python -m pytest --cov --cov-report term --cov-report xml --junitxml=xunit-result.xml tests/ - name: Correct coverage paths diff --git a/tests/test_project.py b/tests/test_project.py index a2b5a35f..78ef3012 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -64,7 +64,7 @@ def baked_with_development_dependencies(copie_session, project_env_bin_dir, copi bin_dir = project_env_bin_dir latest_pip_output = run([f'{bin_dir}python', '-m', 'pip', 'install', '--upgrade', 'pip', 'setuptools'], project_dir) assert latest_pip_output.returncode == 0 - pip_output = run([f'{bin_dir}python', '-m', 'pip', 'install', '--editable', '.[dev]'], project_dir) + pip_output = run([f'{bin_dir}python', '-m', 'pip', 'install', '--editable', '.', '--group', 'dev'], project_dir) assert pip_output.returncode == 0 return project_dir @@ -91,7 +91,7 @@ def test_tox(baked_with_development_dependencies, project_env_bin_dir): bin_dir = project_env_bin_dir result = run([f'{bin_dir}tox'], project_dir) assert result.returncode == 0 - assert '== 3 passed in' in result.stdout + assert 'congratulations :)' in result.stdout # assert (project_dir / '.tox' / 'dist' / 'my_python_package-0.1.0.zip').exists() assert (project_dir / '.tox' / '.pkg' / 'dist'/ 'my_python_package-0.1.0.tar.gz').exists()