summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2021-03-06 22:00:25 -0500
committerGitHub <noreply@github.com>2021-03-06 22:00:25 -0500
commit15249f13d03d5703956de9986a473d7125e49bb2 (patch)
treea19a7129db7dd3b5c24dbc3d5ff5e256027d48e8
parent23ee037d56a6d8ab957882e1a041f67924ae04da (diff)
parent66323adeae5cb2d143d00db13fd96686c0887233 (diff)
downloadpython-setuptools-git-15249f13d03d5703956de9986a473d7125e49bb2.tar.gz
Merge pull request #2593 from melissa-kun-li/uppercase_metadata_warning
Warn for uppercase key usage in metadata in setup.cfg, provides compatibility. Fixes #2592
-rw-r--r--changelog.d/2592.bugfix.rst3
-rw-r--r--setuptools/dist.py13
-rw-r--r--setuptools/tests/test_config.py19
3 files changed, 35 insertions, 0 deletions
diff --git a/changelog.d/2592.bugfix.rst b/changelog.d/2592.bugfix.rst
new file mode 100644
index 00000000..a38ae0c4
--- /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 c074468b..70c0e6be 100644
--- a/setuptools/dist.py
+++ b/setuptools/dist.py
@@ -599,6 +599,7 @@ class Distribution(_Distribution):
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 @@ class Distribution(_Distribution):
% (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 eac26749..1ff5ee41 100644
--- a/setuptools/tests/test_config.py
+++ b/setuptools/tests/test_config.py
@@ -526,6 +526,25 @@ class TestMetadata:
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: