Skip to content

Warn for uppercase key usage in metadata in setup.cfg, provides compatibility. Fixes #2592 #2593

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog.d/2592.bugfix.rst
Original file line number Diff line number Diff line change
@@ -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`
13 changes: 13 additions & 0 deletions setuptools/dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
"""
Expand Down
19 changes: 19 additions & 0 deletions setuptools/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,25 @@ def test_dash_to_underscore_warning(self, tmpdir):
assert metadata.author_email == '[email protected]'
assert metadata.maintainer_email == '[email protected]'

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:

Expand Down