diff --git a/changelog.d/2592.bugfix.rst b/changelog.d/2592.bugfix.rst new file mode 100644 index 0000000000..a38ae0c4c4 --- /dev/null +++ b/changelog.d/2592.bugfix.rst @@ -0,0 +1,3 @@ +Made option keys in the ``[metadata]`` section of ``setup.cfg`` case-sensitive. Users having +uppercase option spellings will get a warning suggesting to make them to lowercase +-- by :user:`melissa-kun-li` diff --git a/setuptools/dist.py b/setuptools/dist.py index c074468ba9..70c0e6becb 100644 --- a/setuptools/dist.py +++ b/setuptools/dist.py @@ -599,6 +599,7 @@ def _parse_config_files(self, filenames=None): # noqa: C901 val = parser.get(section, opt) opt = self.dash_to_underscore_warning(opt, section) + opt = self.make_option_lowercase(opt, section) opt_dict[opt] = (filename, val) # Make the ConfigParser forget everything (so we retain @@ -636,6 +637,18 @@ def dash_to_underscore_warning(self, opt, section): % (opt, underscore_opt)) return underscore_opt + def make_option_lowercase(self, opt, section): + if section != 'metadata' or opt.islower(): + return opt + + lowercase_opt = opt.lower() + warnings.warn( + "Usage of uppercase key '%s' in '%s' will be deprecated in future " + "versions. Please use lowercase '%s' instead" + % (opt, section, lowercase_opt) + ) + return lowercase_opt + # FIXME: 'Distribution._set_command_options' is too complex (14) def _set_command_options(self, command_obj, option_dict=None): # noqa: C901 """ diff --git a/setuptools/tests/test_config.py b/setuptools/tests/test_config.py index eac26749d4..1ff5ee4185 100644 --- a/setuptools/tests/test_config.py +++ b/setuptools/tests/test_config.py @@ -526,6 +526,25 @@ def test_dash_to_underscore_warning(self, tmpdir): assert metadata.author_email == 'test@test.com' assert metadata.maintainer_email == 'foo@foo.com' + def test_uppercase_warning(self, tmpdir): + # remove this test and the method uppercase_warning() in setuptools.dist + # when no longer needed + fake_env( + tmpdir, + '[metadata]\n' + 'Name = foo\n' + 'description = Some description\n' + ) + msg = ("Usage of uppercase key 'Name' in 'metadata' will be deprecated in " + "future versions. " + "Please use lowercase 'name' instead") + with pytest.warns(UserWarning, match=msg): + with get_dist(tmpdir) as dist: + metadata = dist.metadata + + assert metadata.name == 'foo' + assert metadata.description == 'Some description' + class TestOptions: