diff --git a/setup_cfg_fmt.py b/setup_cfg_fmt.py index 19ebf6e..25fa5de 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]: TOX_ENV = re.compile(r'py3(\d+)') -def _python_requires(setup_cfg: str, *, min_py_version: tuple[int, int] | None) -> str : +def _python_requires(setup_cfg: str, *, min_py_version: tuple[int, int] | None) -> str: cfg = NoTransformConfigParser() cfg.read(setup_cfg) current_value = cfg.get('options', 'python_requires', fallback='') diff --git a/tests/setup_cfg_fmt_test.py b/tests/setup_cfg_fmt_test.py index a205ef5..7a35c0f 100644 --- a/tests/setup_cfg_fmt_test.py +++ b/tests/setup_cfg_fmt_test.py @@ -148,17 +148,17 @@ def test_rewrite_requires(which, input_tpl, expected, tmpdir): 'name = pkg\n', '[metadata]\n' - 'name = pkg\n' - 'version = 1.0\n' - 'classifiers =\n' - ' Programming Language :: Python :: 3\n' - ' Programming Language :: Python :: 3 :: Only\n' - '\n' - '[options]\n' - 'python_requires = >=3.7\n' - '\n' - '[bdist_wheel]\n' - 'universal = true\n', + 'name = pkg\n' + 'version = 1.0\n' + 'classifiers =\n' + ' Programming Language :: Python :: 3\n' + ' Programming Language :: Python :: 3 :: Only\n' + '\n' + '[options]\n' + 'python_requires = >=3.7\n' + '\n' + '[bdist_wheel]\n' + 'universal = true\n', id='orders fields and sections', ), @@ -174,20 +174,20 @@ def test_rewrite_requires(which, input_tpl, expected, tmpdir): 'where = src\n', '[metadata]\n' - 'name = pkg\n' - 'version = 1.0\n' - 'classifiers =\n' - ' Programming Language :: Python :: 3\n' - ' Programming Language :: Python :: 3 :: Only\n' - '\n' - '[options]\n' - 'python_requires = >=3.7\n' - '\n' - '[options.packages.find]\n' - 'where = src\n' - '\n' - '[bdist_wheel]\n' - 'universal = true\n', + 'name = pkg\n' + 'version = 1.0\n' + 'classifiers =\n' + ' Programming Language :: Python :: 3\n' + ' Programming Language :: Python :: 3 :: Only\n' + '\n' + '[options]\n' + 'python_requires = >=3.7\n' + '\n' + '[options.packages.find]\n' + 'where = src\n' + '\n' + '[bdist_wheel]\n' + 'universal = true\n', id='orders sections (options.packages.find)', ), @@ -217,16 +217,16 @@ def test_rewrite_requires(which, input_tpl, expected, tmpdir): ' License :: OSI Approved :: MIT License\n' ' Programming Language :: Python :: 3 :: Only\n', -'[metadata]\n' - 'name = pkg\n' - 'version = 1.0\n' - 'classifiers =\n' - ' License :: OSI Approved :: MIT License\n' - ' Programming Language :: Python :: 3\n' - ' Programming Language :: Python :: 3 :: Only\n' - '\n' - '[options]\n' - 'python_requires = >=3.7\n', + '[metadata]\n' + 'name = pkg\n' + 'version = 1.0\n' + 'classifiers =\n' + ' License :: OSI Approved :: MIT License\n' + ' Programming Language :: Python :: 3\n' + ' Programming Language :: Python :: 3 :: Only\n' + '\n' + '[options]\n' + 'python_requires = >=3.7\n', id='sorts classifiers', ), @@ -240,18 +240,18 @@ def test_rewrite_requires(which, input_tpl, expected, tmpdir): 'author = john\n', '[metadata]\n' - 'name = pkg\n' - 'author = john\n' - 'author_email = john@example.com\n' - 'maintainer = jane\n' - 'maintainer_email = jane@example.com\n' - 'license = foo\n' - 'classifiers =\n' - ' Programming Language :: Python :: 3\n' - ' Programming Language :: Python :: 3 :: Only\n' - '\n' - '[options]\n' - 'python_requires = >=3.7\n', + 'name = pkg\n' + 'author = john\n' + 'author_email = john@example.com\n' + 'maintainer = jane\n' + 'maintainer_email = jane@example.com\n' + 'license = foo\n' + 'classifiers =\n' + ' Programming Language :: Python :: 3\n' + ' Programming Language :: Python :: 3 :: Only\n' + '\n' + '[options]\n' + 'python_requires = >=3.7\n', id='orders authors and maintainers', ), @@ -262,15 +262,15 @@ def test_rewrite_requires(which, input_tpl, expected, tmpdir): 'maintainer-email = jane@example.com\n', '[metadata]\n' - 'name = pkg\n' - 'author_email = john@example.com\n' - 'maintainer_email = jane@example.com\n' - 'classifiers =\n' - ' Programming Language :: Python :: 3\n' - ' Programming Language :: Python :: 3 :: Only\n' - '\n' - '[options]\n' - 'python_requires = >=3.7\n', + 'name = pkg\n' + 'author_email = john@example.com\n' + 'maintainer_email = jane@example.com\n' + 'classifiers =\n' + ' Programming Language :: Python :: 3\n' + ' Programming Language :: Python :: 3 :: Only\n' + '\n' + '[options]\n' + 'python_requires = >=3.7\n', id='normalize dashes to underscores in keys', ), @@ -492,16 +492,13 @@ def test_license_does_not_set_when_licenses_matches(tmpdir): '\n' \ '[options]\n' \ 'python_requires = >=3.7\n' - + tmpdir.join('LICENSE').write('COPYRIGHT (C) 2019 ME') setup_cfg = tmpdir.join('setup.cfg') setup_cfg.write(s) assert not main((str(setup_cfg),)) - - - def test_license_does_set_when_licenses_mismatches(tmpdir): tmpdir.join('LICENSE').write('COPYRIGHT (C) 2019 ME') @@ -521,11 +518,11 @@ def test_license_does_set_when_licenses_mismatches(tmpdir): 'version = 1.0\n' 'license_file = LICENSE\n' 'license_files = LICENSES\n' - 'classifiers =\n' - ' Programming Language :: Python :: 3\n' - ' Programming Language :: Python :: 3 :: Only\n' - '\n' - '[options]\n' + 'classifiers =\n' + ' Programming Language :: Python :: 3\n' + ' Programming Language :: Python :: 3 :: Only\n' + '\n' + '[options]\n' 'python_requires = >=3.7\n' ) @@ -546,17 +543,17 @@ def test_rewrite_sets_license_type_and_classifier(tmpdir): assert setup_cfg.read() == ( '[metadata]\n' - 'name = pkg\n' - 'version = 1.0\n' - 'license = MIT\n' - 'license_file = LICENSE\n' - 'classifiers =\n' - ' License :: OSI Approved :: MIT License\n' - ' Programming Language :: Python :: 3\n' - ' Programming Language :: Python :: 3 :: Only\n' - '\n' - '[options]\n' - 'python_requires = >=3.7\n' + 'name = pkg\n' + 'version = 1.0\n' + 'license = MIT\n' + 'license_file = LICENSE\n' + 'classifiers =\n' + ' License :: OSI Approved :: MIT License\n' + ' Programming Language :: Python :: 3\n' + ' Programming Language :: Python :: 3 :: Only\n' + '\n' + '[options]\n' + 'python_requires = >=3.7\n' ) @@ -599,12 +596,12 @@ def test_rewrite_identifies_license(tmpdir): 'license = Zlib\n' 'license_file = LICENSE\n' 'classifiers =\n' - ' License :: OSI Approved :: zlib/libpng License\n' - ' Programming Language :: Python :: 3\n' - ' Programming Language :: Python :: 3 :: Only\n' - '\n' - '[options]\n' - 'python_requires = >=3.7\n' + ' License :: OSI Approved :: zlib/libpng License\n' + ' Programming Language :: Python :: 3\n' + ' Programming Language :: Python :: 3 :: Only\n' + '\n' + '[options]\n' + 'python_requires = >=3.7\n' ) @@ -676,9 +673,9 @@ def test_strips_empty_options_and_sections(tmpdir, section, expected): '[metadata]\n' 'name = pkg\n' 'version = 1.0\n' -'classifiers =\n' - ' Programming Language :: Python :: 3\n' - ' Programming Language :: Python :: 3 :: Only\n' + 'classifiers =\n' + ' Programming Language :: Python :: 3\n' + ' Programming Language :: Python :: 3 :: Only\n' f'{section}', ) @@ -687,9 +684,9 @@ def test_strips_empty_options_and_sections(tmpdir, section, expected): '[metadata]\n' 'name = pkg\n' 'version = 1.0\n' -'classifiers =\n' - ' Programming Language :: Python :: 3\n' - ' Programming Language :: Python :: 3 :: Only\n' + 'classifiers =\n' + ' Programming Language :: Python :: 3\n' + ' Programming Language :: Python :: 3 :: Only\n' f'{expected}' ) @@ -772,20 +769,20 @@ def test_guess_python_requires_tox_ini_py310(tmpdir): assert setup_cfg.read() == ( '[metadata]\n' - 'name = pkg\n' - 'version = 1.0\n' - 'classifiers =\n' - ' Programming Language :: Python :: 3\n' - ' Programming Language :: Python :: 3 :: Only\n' - ' Programming Language :: Python :: 3.7\n' - ' Programming Language :: Python :: 3.8\n' - ' Programming Language :: Python :: 3.9\n' - ' Programming Language :: Python :: 3.10\n' - ' Programming Language :: Python :: 3.11\n' - ' Programming Language :: Python :: Implementation :: CPython\n' - '\n' - '[options]\n' - 'python_requires = >=3.7\n' + 'name = pkg\n' + 'version = 1.0\n' + 'classifiers =\n' + ' Programming Language :: Python :: 3\n' + ' Programming Language :: Python :: 3 :: Only\n' + ' Programming Language :: Python :: 3.7\n' + ' Programming Language :: Python :: 3.8\n' + ' Programming Language :: Python :: 3.9\n' + ' Programming Language :: Python :: 3.10\n' + ' Programming Language :: Python :: 3.11\n' + ' Programming Language :: Python :: Implementation :: CPython\n' + '\n' + '[options]\n' + 'python_requires = >=3.7\n' ) @@ -800,7 +797,7 @@ def test_guess_python_requires_ignores_insufficient_version_envs(tmpdir): ' Programming Language :: Python :: Implementation :: CPython\n', ) - assert main((str(setup_cfg), '--max-py-version=3.7',)) + assert main((str(setup_cfg), '--max-py-version=3.7')) assert setup_cfg.read() == ( '[metadata]\n' @@ -808,11 +805,11 @@ def test_guess_python_requires_ignores_insufficient_version_envs(tmpdir): 'version = 1.0\n' 'classifiers =\n' ' Programming Language :: Python :: 3\n' - ' Programming Language :: Python :: 3 :: Only\n' - ' Programming Language :: Python :: Implementation :: CPython\n' - '\n' - '[options]\n' - 'python_requires = >=3.7\n' + ' Programming Language :: Python :: 3 :: Only\n' + ' Programming Language :: Python :: Implementation :: CPython\n' + '\n' + '[options]\n' + 'python_requires = >=3.7\n' ) @@ -1049,12 +1046,12 @@ def test_rewrite_extras(tmpdir): setup_cfg_content = ( '[metadata]\n' 'name = test\n' - 'classifiers =\n' - ' Programming Language :: Python :: 3\n' - ' Programming Language :: Python :: 3 :: Only\n' - '\n' - '[options]\n' - 'python_requires = >=3.7\n' + 'classifiers =\n' + ' Programming Language :: Python :: 3\n' + ' Programming Language :: Python :: 3 :: Only\n' + '\n' + '[options]\n' + 'python_requires = >=3.7\n' '[options.extras_require]\n' 'dev =\n' ' pytest\n' @@ -1072,12 +1069,12 @@ def test_rewrite_extras(tmpdir): assert setup_cfg.read() == ( '[metadata]\n' 'name = test\n' - 'classifiers =\n' - ' Programming Language :: Python :: 3\n' - ' Programming Language :: Python :: 3 :: Only\n' - '\n' - '[options]\n' - 'python_requires = >=3.7\n' + 'classifiers =\n' + ' Programming Language :: Python :: 3\n' + ' Programming Language :: Python :: 3 :: Only\n' + '\n' + '[options]\n' + 'python_requires = >=3.7\n' '\n' '[options.extras_require]\n' 'ci =\n' @@ -1281,10 +1278,10 @@ def test_leaves_casing_of_unrelated_settings(tmpdir): 'python_requires = >=3.7\n' '\n' '[tool:pytest]\n' - 'DJANGO_SETTINGS_MODULE = test.test\n' + 'DJANGO_SETTINGS_MODULE = test.test\n', ) - assert not main((str(setup_cfg),)) + assert not main((str(setup_cfg),)) def test_natural_sort():