File tree Expand file tree Collapse file tree 5 files changed +23
-11
lines changed
project-template/{{cookiecutter.repo_name}} Expand file tree Collapse file tree 5 files changed +23
-11
lines changed Original file line number Diff line number Diff 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+ Default argument to :func:`exasol.toolbox._format._pyupgrade`.
70+
71+ It uses the minimum Python version to ensure compatibility with all supported
72+ versions of a project.
73+ """
74+ version_parts = self .minimum_python_version .split ("." )[:2 ]
75+ version_number = "" .join (version_parts )
76+ return (f"--py{ version_number } -plus" ,)
Original file line number Diff line number Diff line change 88from exasol .toolbox .nox ._shared import (
99 Mode ,
1010 _version ,
11+ check_for_config_attribute ,
1112 python_files ,
1213)
1314from noxconfig import (
1415 PROJECT_CONFIG ,
1516 Config ,
1617)
1718
18- _PYUPGRADE_ARGS = ("--py39-plus" ,)
19-
2019
2120def _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
2928def _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 )
Original file line number Diff line number Diff 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
7268PROJECT_CONFIG = Config (
Original file line number Diff line number Diff 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
2422PROJECT_CONFIG = Config ()
Original file line number Diff line number Diff line change @@ -57,6 +57,12 @@ def test_expansion_validation_fails_for_invalid_version():
5757 BaseConfigExpansion (python_versions = ("1.f.0" ,))
5858
5959
60- def test_min_py_version ():
60+ def test_minimum_python_version ():
6161 conf = BaseConfig (python_versions = ("5.5.5" , "1.1.1" , "9.9.9" ))
6262 assert conf .minimum_python_version == "1.1.1"
63+
64+
65+ @pytest .mark .parametrize ("minimum_python_version" , ["3.10" , "3.10.5" ])
66+ def test_pyupgrade_argument (minimum_python_version ):
67+ conf = BaseConfig (python_versions = ("3.11" , minimum_python_version , "3.12" ))
68+ assert conf .pyupgrade_argument == ("--py310-plus" ,)
You can’t perform that action at this time.
0 commit comments