Skip to content

Commit b63596e

Browse files
committed
Add pyupgrade_argument to BaseConfig and use in pyupgrade command
1 parent 0cb5f13 commit b63596e

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

exasol/toolbox/config.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,16 @@ def minimum_python_version(self) -> str:
6161
costly to run the tests for all `python_versions` or we need a single metric.
6262
"""
6363
return str(min([Version.from_string(v) for v in self.python_versions]))
64+
65+
@computed_field # type: ignore[misc]
66+
@property
67+
def pyupgrade_argument(self) -> tuple[str, ...]:
68+
"""
69+
Minimum Python version declared from the `python_versions` list
70+
71+
This is used in specific testing scenarios where it would be either
72+
costly to run the tests for all `python_versions` or we need a single metric.
73+
"""
74+
version_parts = self.minimum_python_version.split(".")[:2]
75+
version_number = "".join(version_parts)
76+
return (f"--py{version_number}-plus",)

exasol/toolbox/nox/_format.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@
88
from exasol.toolbox.nox._shared import (
99
Mode,
1010
_version,
11+
check_for_config_attribute,
1112
python_files,
1213
)
1314
from noxconfig import (
1415
PROJECT_CONFIG,
1516
Config,
1617
)
1718

18-
_PYUPGRADE_ARGS = ("--py39-plus",)
19-
2019

2120
def _code_format(session: Session, mode: Mode, files: Iterable[str]) -> None:
2221
def command(*args: str) -> Iterable[str]:
@@ -27,10 +26,10 @@ def command(*args: str) -> Iterable[str]:
2726

2827

2928
def _pyupgrade(session: Session, config: Config, files: Iterable[str]) -> None:
30-
pyupgrade_args = getattr(config, "pyupgrade_args", _PYUPGRADE_ARGS)
29+
check_for_config_attribute(config, "pyupgrade_argument")
3130
session.run(
3231
"pyupgrade",
33-
*pyupgrade_args,
32+
*config.pyupgrade_argument,
3433
"--exit-zero-even-if-changed",
3534
*files,
3635
)

noxconfig.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,6 @@ class Config(BaseConfig):
6363
".github",
6464
)
6565
plugins: Iterable[object] = (UpdateTemplates,)
66-
# need --keep-runtime-typing, as pydantic with python3.9 does not accept str | None
67-
# format, and it is not resolved with from __future__ import annotations. pyupgrade
68-
# will keep switching Optional[str] to str | None leading to issues.
69-
pyupgrade_args: Iterable[str] = ("--py39-plus", "--keep-runtime-typing")
7066

7167

7268
PROJECT_CONFIG = Config(

project-template/{{cookiecutter.repo_name}}/noxconfig.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ class Config(BaseConfig):
1717
/ "version.py"
1818
)
1919
path_filters: Iterable[str] = ()
20-
pyupgrade_args: Iterable[str] = (
21-
"--py{{cookiecutter.python_version_min | replace('.', '')}}-plus",)
2220
plugins: Iterable[object] = ()
2321

2422
PROJECT_CONFIG = Config()

0 commit comments

Comments
 (0)