Skip to content

Commit 7e717ba

Browse files
authored
Feature/667 fill in templates with defaults (#668)
* Prepare BaseConfig for usage in jinja templates * Modify templates & add render code for output and diff * Add information to the Dependencies documentation
1 parent 7f32b64 commit 7e717ba

File tree

22 files changed

+463
-46
lines changed

22 files changed

+463
-46
lines changed

.import_linter_config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ ignore_imports =
2727
# To reduce the effort in using nox sessions (i.e. having to pass the config path
2828
# in each CLI usage), we allow the noxconfig to be imported within these modules.
2929
exasol.toolbox.nox.* -> noxconfig
30+
exasol.toolbox.tools.template -> noxconfig

doc/changes/unreleased.md

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,22 @@ In previous versions, the default value for `poetry-version` was `2.1.2`, and it
3434
* Depending on its poetry version, a repository relying on the default behavior of said
3535
action may run into breaking changes. This can easily be resolved with explicitly setting the
3636
`poetry-version` when calling the GitHub action. It is, however, recommended whenever
37-
possible to update the poetry version of the affected repository. Unfortunately,
38-
there is not a quick and easy way to update all the places where `poetry-version`
39-
could be specified in the GitHub workflows.
37+
possible to update the poetry version of the affected repository. Since this major release,
38+
you can, if needed, alter the `poetry-version` via the `noxconfig.py::PROJECT_CONFIG`
39+
by changing `dependency_manager_version`. If you do this, please create an issue to
40+
update to `2.3.0` at your earliest convenience.
4041

4142
* Projects migrating to this version should:
4243

43-
* Update their `pyproject.toml` to have:
44-
```toml
45-
requires-poetry = ">=2.3.0"
46-
```
47-
* Run `poetry check` and resolve any issues
48-
* (optional) Run `poetry lock` to update the lock
49-
* (optional) Update their `pyproject.toml` to fit:
50-
* [PEP-621](https://peps.python.org/pep-0621/)
51-
* [PEP-735](https://peps.python.org/pep-0735/)
44+
* Update their `pyproject.toml` to have:
45+
```toml
46+
requires-poetry = ">=2.3.0"
47+
```
48+
* Run `poetry check` and resolve any issues
49+
* (optional) Run `poetry lock` to update the lock
50+
* (optional) Update their `pyproject.toml` to fit:
51+
* [PEP-621](https://peps.python.org/pep-0621/)
52+
* [PEP-735](https://peps.python.org/pep-0735/)
5253

5354
Note that [uvx migrate-to-uv](https://github.com/mkniewallner/migrate-to-uv) seems to
5455
do a good job with automating many of the PEP-related changes; though developers should
@@ -65,6 +66,16 @@ take care and will need to make manual changes to ensure it still works with
6566
* #647: Added summary to changelog template
6667
* #657: Updated `release:prepare` to modify cookiecutter template exasol-toolbox version range
6768
* #665: Added SECURITY.md to the cookiecutter template
69+
* #667: Switched GitHub workflow templates to be controlled by PROJECT_CONFIG:
70+
* The values in `BaseConfig.github_template_dict` are used to render the following values in
71+
the templates
72+
* `dependency_manager_version` - used for `poetry-version` in the workflows.
73+
The default it `2.3.0`.
74+
* `minimum_python_version` - used for `python-version` in the workflows whenever
75+
`python-version` for actions that are run once. The default is the minimum value
76+
in your project's defined `python_versions`
77+
* `os_version` - used for the GitHub runner in the workflows. The default is
78+
`ubuntu-24.04`
6879
6980
## Refactoring
7081
@@ -74,3 +85,5 @@ take care and will need to make manual changes to ensure it still works with
7485
* `upload-pages-artifact` from v3 to [v4](https://github.com/actions/upload-pages-artifact/releases/tag/v4.0.0) - breaking change
7586
* `download-artifact`from v6 to [v7](https://github.com/actions/download-artifact/releases/tag/v7.0.0) - using Node.js 24
7687
* `upload-artifact` from v5 to [v6](https://github.com/actions/upload-artifact/releases/tag/v6.0.0) - using Node.js 24
88+
* #667: Added deprecation warnings to `tbx workflow x` endpoints as some are unneeded
89+
(will be removed) and others need updates (will be moved to a nox session)

doc/user_guide/dependencies.rst

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,62 @@
11
Dependencies
22
============
33

4-
Core dependencies
5-
+++++++++++++++++
4+
Core Dependencies
5+
-----------------
66

77
- Python >= 3.10
8-
- poetry >= 2.3.0
8+
- `Poetry <https://python-poetry.org/docs/#installing-with-the-official-installer>`__ >= 2.3.0
99
- `poetry export <https://github.com/python-poetry/poetry-plugin-export>`__
10+
11+
Supported Poetry Versions by PTB
12+
--------------------------------
13+
14+
.. list-table:: PTB Poetry Version Compatibility
15+
:header-rows: 1
16+
17+
* - PTB Version
18+
- Default in PTB
19+
- Range Allowed
20+
- Migration Information
21+
* - >=1.0.0, <5.0.0
22+
- 2.1.2
23+
- >=2.1.0,<3.0
24+
- None
25+
* - >=5.0.0
26+
- 2.3.0
27+
- >=2.3.0,<3.0
28+
- :ref:`migration_to_2.3.x`
29+
30+
Migration Information
31+
---------------------
32+
33+
.. _migration_to_2.3.x:
34+
35+
From Poetry ``2.1.x`` to ``2.3.0``
36+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
37+
It is **highly** encouraged that a developer update their ``pyproject.toml`` and
38+
system-wide Poetry installation to most use effectively use Poetry ``2.3.0``:
39+
40+
#. In your terminal, update your system-wide Poetry version:
41+
42+
.. code-block:: bash
43+
44+
poetry self update 2.3.0
45+
46+
#. In your project's ``pyproject.toml``, update the ``requires-poetry`` value:
47+
48+
.. code-block:: toml
49+
50+
requires-poetry = ">=2.3.0"
51+
52+
#. In your terminal, execute ``poetry check`` and resolve any listed issues
53+
#. In your terminal, run ``poetry lock`` to update the lock
54+
#. (optional but recommended) In your project's ``pyproject.toml``, update it to fit:
55+
* `PEP-621 <https://peps.python.org/pep-0621/>`__
56+
* `PEP-735 <https://peps.python.org/pep-0735/>`__
57+
58+
.. note::
59+
Note that `uvx migrate-to-uv <https://github.com/mkniewallner/migrate-to-uv>`__
60+
seems to do a good job with automating many of the PEP-related changes.
61+
Though, a developer should take care to verify the changes, as some are unneeded
62+
as it completes the migration to ``uv`` which the PTB does NOT yet support.

doc/user_guide/features/documentation/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Deploying documentation
99
multiversion
1010
troubleshooting
1111

12-
The PTB uses ref:`sphinx <https://www.sphinx-doc.org/>`__ to build and validate the contents
12+
The PTB uses `sphinx <https://www.sphinx-doc.org/>`__ to build and validate the contents
1313
of your project's documentation. PTB expects the project's documentation in directory ``doc``,
1414
primarily as ``rst`` files. The ``doc/conf.py`` acts as the configuration file for building the
1515
documentation.

exasol/toolbox/config.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
import inspect
2+
import warnings
23
from collections.abc import Callable
34
from pathlib import Path
45
from typing import (
56
Annotated,
67
Any,
8+
Literal,
79
)
810

11+
from packaging import version
912
from pydantic import (
1013
AfterValidator,
1114
BaseModel,
1215
ConfigDict,
1316
Field,
1417
computed_field,
18+
field_validator,
1519
)
20+
from pydantic_core.core_schema import ValidationInfo
1621

1722
from exasol.toolbox.nox.plugin import (
1823
METHODS_SPECIFIED_FOR_HOOKS,
@@ -93,6 +98,26 @@ def valid_version_string(version_string: str) -> str:
9398
}
9499

95100

101+
class DependencyManager(BaseModel):
102+
# Restricted to only allow "poetry" at the moment
103+
name: Literal["poetry"]
104+
version: ValidVersionStr
105+
106+
@field_validator("version")
107+
@classmethod
108+
def check_minimum_version(cls, v: str, info: ValidationInfo) -> str:
109+
tool = info.data.get("name")
110+
if tool == "poetry":
111+
prefix = "Poetry version "
112+
if version.parse(v) < (min_version := version.parse("2.1.4")):
113+
raise ValueError(prefix + f"must be >= {min_version}")
114+
elif version.parse(v) >= (max_version := version.parse("3.0.0")):
115+
raise ValueError(prefix + f"must be < {max_version}")
116+
elif version.parse(v) > (current_version := version.parse("2.3.0")):
117+
warnings.warn(prefix + f"exceeds last tested version {current_version}")
118+
return v
119+
120+
96121
class BaseConfig(BaseModel):
97122
"""
98123
Basic configuration for projects using the PTB
@@ -142,6 +167,24 @@ class BaseConfig(BaseModel):
142167
possible plugin options are defined in `exasol.toolbox.nox.plugins.NoxTasks`.
143168
""",
144169
)
170+
dependency_manager: DependencyManager = Field(
171+
default=DependencyManager(name="poetry", version="2.3.0"),
172+
description="""
173+
This is used to define which dependency manager is used to install dependencies
174+
in the CI. For more details on which PTB version pairs with which
175+
dependency manager, see:
176+
https://exasol.github.io/python-toolbox/main/user_guide/dependencies.html
177+
""",
178+
)
179+
os_version: str = Field(
180+
default="ubuntu-24.04",
181+
pattern=r"^ubuntu-.*",
182+
description="""
183+
This is used to set the OS-runner in the GitHub workflows that are
184+
provided as templates from the PTB. Currently, only ubuntu-based runners
185+
are supported.
186+
""",
187+
)
145188
model_config = ConfigDict(frozen=True, arbitrary_types_allowed=True)
146189

147190
@computed_field # type: ignore[misc]
@@ -222,3 +265,16 @@ def version_filepath(self) -> Path:
222265
the nox sessions ``version:check`` and ``release:prepare``.
223266
"""
224267
return self.source_code_path / "version.py"
268+
269+
@computed_field # type: ignore[misc]
270+
@property
271+
def github_template_dict(self) -> dict[str, Any]:
272+
"""
273+
Dictionary of variables to dynamically render Jinja2 templates into valid YAML
274+
configurations.
275+
"""
276+
return {
277+
"dependency_manager_version": self.dependency_manager.version,
278+
"minimum_python_version": self.minimum_python_version,
279+
"os_version": self.os_version,
280+
}

exasol/toolbox/templates/github/workflows/build-and-publish.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010

1111
cd-job:
1212
name: Continuous Delivery
13-
runs-on: ubuntu-24.04
13+
runs-on: "(( os_version ))"
1414
permissions:
1515
contents: write
1616
steps:
@@ -19,6 +19,9 @@ jobs:
1919

2020
- name: Setup Python & Poetry Environment
2121
uses: exasol/python-toolbox/.github/actions/python-environment@v4
22+
with:
23+
python-version: "(( minimum_python_version ))"
24+
poetry-version: "(( dependency_manager_version ))"
2225

2326
- name: Build Artifacts
2427
run: poetry build

exasol/toolbox/templates/github/workflows/check-release-tag.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77

88
check-tag-version-job:
99
name: Check Tag Version
10-
runs-on: ubuntu-24.04
10+
runs-on: "(( os_version ))"
1111
permissions:
1212
contents: read
1313
steps:
@@ -16,6 +16,9 @@ jobs:
1616

1717
- name: Setup Python & Poetry Environment
1818
uses: exasol/python-toolbox/.github/actions/python-environment@v4
19+
with:
20+
python-version: "(( minimum_python_version ))"
21+
poetry-version: "(( dependency_manager_version ))"
1922

2023
- name: Check Tag Version
2124
# make sure the pushed/created tag matched the project version

0 commit comments

Comments
 (0)