From 96bdbc1c1481508ad32138d33537c81c9f02820a Mon Sep 17 00:00:00 2001 From: Max R Date: Fri, 16 Dec 2022 14:32:25 -0500 Subject: [PATCH] Change --min-py-version behavior --- README.md | 5 +++-- setup_cfg_fmt.py | 30 +++++++++--------------------- tests/setup_cfg_fmt_test.py | 13 +++++-------- 3 files changed, 17 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index f9099f9..a76339c 100644 --- a/README.md +++ b/README.md @@ -116,12 +116,13 @@ This will show up on the pypi project page ### set `python_requires` -A few sources are searched for guessing `python_requires`: +If `--min-py-version` is set, it will be used as the source of truth +for `python_requires`. +Otherwise, a few sources are searched for guessing `python_requires`: - the existing `python_requires` setting itself - `envlist` in `tox.ini` if present - python version `classifiers` that are already set -- the `--min-py-version` argument (currently defaulting to `3.7) ### adds python version classifiers diff --git a/setup_cfg_fmt.py b/setup_cfg_fmt.py index a153906..d4e4d42 100644 --- a/setup_cfg_fmt.py +++ b/setup_cfg_fmt.py @@ -174,7 +174,7 @@ def _tox_envlist(setup_cfg: str) -> Generator[str, None, None]: def _python_requires( - setup_cfg: str, *, min_py_version: tuple[int, int], + setup_cfg: str, *, min_py_version: tuple[int, int] | None, ) -> str | None: cfg = NoTransformConfigParser() cfg.read(setup_cfg) @@ -186,6 +186,9 @@ def _python_requires( except UnknownVersionError: # assume they know what's up with weird things return current_value + if min_py_version is not None: + return _format_python_requires(min_py_version, excluded) + for env in _tox_envlist(setup_cfg): match = TOX_ENV.match(env) if match: @@ -204,10 +207,8 @@ def _python_requires( if minimum is None: return None - elif min_py_version > minimum: - return _format_python_requires(min_py_version, excluded) - else: - return _format_python_requires(minimum, excluded) + + return _format_python_requires(minimum, excluded) def _requires( @@ -356,7 +357,7 @@ def _natural_sort(items: Sequence[str]) -> list[str]: def format_file( filename: str, *, include_version_classifiers: bool, - min_py_version: tuple[int, int], + min_py_version: tuple[int, int] | None, max_py_version: tuple[int, int], ) -> bool: with open(filename) as f: @@ -509,29 +510,16 @@ def main(argv: Sequence[str] | None = None) -> int: parser = argparse.ArgumentParser() parser.add_argument('filenames', nargs='*') parser.add_argument('--include-version-classifiers', action='store_true') - parser.add_argument( - '--min-py3-version', type=_ver_type, default=None, - help=argparse.SUPPRESS, - ) - parser.add_argument('--min-py-version', type=_ver_type, default=(3, 7)) + parser.add_argument('--min-py-version', type=_ver_type, default=None) parser.add_argument('--max-py-version', type=_ver_type, default=(3, 11)) args = parser.parse_args(argv) - if args.min_py3_version: - print( - 'WARNING: setup-cfg-fmt will replace --min-py3-version ' - 'with --min-py-version in a future release', - ) - min_py_version = args.min_py3_version - else: - min_py_version = args.min_py_version - retv = 0 for filename in args.filenames: if format_file( filename, include_version_classifiers=args.include_version_classifiers, - min_py_version=min_py_version, + min_py_version=args.min_py_version, max_py_version=args.max_py_version, ): print(f'Rewriting {filename}') diff --git a/tests/setup_cfg_fmt_test.py b/tests/setup_cfg_fmt_test.py index 85d7004..e08a969 100644 --- a/tests/setup_cfg_fmt_test.py +++ b/tests/setup_cfg_fmt_test.py @@ -535,7 +535,7 @@ def test_python_requires_left_alone(tmpdir, s): assert not main(( str(setup_cfg), '--include-version-classifiers', - '--min-py3-version=3.2', + '--min-py-version=3.2', )) assert setup_cfg.read() == ( @@ -600,7 +600,6 @@ def test_guess_python_requires_python2_tox_ini(tmpdir): assert main(( str(setup_cfg), '--include-version-classifiers', - '--min-py-version=3.4', '--max-py-version=3.7', )) @@ -633,7 +632,6 @@ def test_guess_python_requires_tox_ini_dashed_name(tmpdir): assert main(( str(setup_cfg), '--include-version-classifiers', - '--min-py-version=3.4', '--max-py-version=3.7', )) @@ -664,7 +662,6 @@ def test_guess_python_requires_tox_ini_py310(tmpdir): assert main(( str(setup_cfg), '--include-version-classifiers', - '--min-py3-version=3.4', )) assert setup_cfg.read() == ( @@ -695,7 +692,7 @@ def test_guess_python_requires_ignores_insufficient_version_envs(tmpdir): ) assert not main(( - str(setup_cfg), '--min-py-version=3.4', '--max-py-version=3.7', + str(setup_cfg), '--max-py-version=3.7', )) assert setup_cfg.read() == ( @@ -721,7 +718,6 @@ def test_guess_python_requires_from_classifiers(tmpdir): assert main(( str(setup_cfg), '--include-version-classifiers', - '--min-py-version=3.4', '--max-py-version=3.7', )) @@ -841,7 +837,6 @@ def test_python_requires_with_patch_version(tmpdir): assert main(( str(setup_cfg), '--include-version-classifiers', - '--min-py-version=3.4', '--max-py-version=3.8', )) @@ -927,12 +922,14 @@ def test_min_py3_version_less_than_minimum(tmpdir): 'classifiers =\n' ' Programming Language :: Python :: 3\n' ' Programming Language :: Python :: 3 :: Only\n' + ' Programming Language :: Python :: 3.4\n' + ' Programming Language :: Python :: 3.5\n' ' Programming Language :: Python :: 3.6\n' ' Programming Language :: Python :: 3.7\n' ' Programming Language :: Python :: Implementation :: CPython\n' '\n' '[options]\n' - 'python_requires = >=3.6\n' + 'python_requires = >=3.4\n' )