Skip to content

Commit

Permalink
Apply suggestions in code review.
Browse files Browse the repository at this point in the history
Co-authored-by: Sviatoslav Sydorenko <wk.cvs.github@sydorenko.org.ua>
  • Loading branch information
jaraco and webknjaz committed Mar 7, 2021
1 parent 28c7abc commit 0bffc7c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
4 changes: 3 additions & 1 deletion changelog.d/2592.change.rst
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
Warned for usage of uppercase keys in :code:`metadata` in :code:`setup.cfg`, restored some compatiblity by transforming to lowercase if not. Followed the change of keys in :code:`setup.cfg` now being case-sensitive -- by :user:`melissa-kun-li`
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`
23 changes: 12 additions & 11 deletions setuptools/dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +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.uppercase_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 @@ -637,16 +637,17 @@ def dash_to_underscore_warning(self, opt, section):
% (opt, underscore_opt))
return underscore_opt

def uppercase_warning(self, opt, section):
if section in ('metadata',) and (any(c.isupper() for c in 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
return 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
5 changes: 3 additions & 2 deletions setuptools/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,8 +541,9 @@ def test_uppercase_warning(self, tmpdir):
with pytest.warns(UserWarning, match=msg):
with get_dist(tmpdir) as dist:
metadata = dist.metadata
assert metadata.name == 'foo'
assert metadata.description == 'Some description'

assert metadata.name == 'foo'
assert metadata.description == 'Some description'


class TestOptions:
Expand Down

0 comments on commit 0bffc7c

Please sign in to comment.