Skip to content

Commit

Permalink
Merge pull request #2588 from melissa-kun-li/compatibility-dash-method
Browse files Browse the repository at this point in the history
Provide support for dash-separated keys in setup.cfg, warns for future incompatibility of certain keys
  • Loading branch information
jaraco authored Mar 3, 2021
2 parents 8307bd4 + 1af7000 commit 729c45d
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 5 deletions.
1 change: 1 addition & 0 deletions changelog.d/1608.change.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Removed the conversion of dashes to underscores in the :code:`extras_require` and :code:`data_files` of :code:`setup.cfg` to support the usage of dashes. Method will warn users when they use a dash-separated key which in the future will only allow an underscore. Note: the method performs the dash to underscore conversion to preserve compatibility, but future versions will no longer support it -- by :user:`melissa-kun-li`
2 changes: 1 addition & 1 deletion setuptools/command/easy_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -1190,7 +1190,7 @@ def _set_fetcher_options(self, base):
for key, val in ei_opts.items():
if key not in fetch_directives:
continue
fetch_options[key.replace('_', '-')] = val[1]
fetch_options[key] = val[1]
# create a settings dictionary suitable for `edit_config`
settings = dict(easy_install=fetch_options)
cfg_filename = os.path.join(base, 'setup.cfg')
Expand Down
15 changes: 14 additions & 1 deletion setuptools/dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ def _parse_config_files(self, filenames=None): # noqa: C901
continue

val = parser.get(section, opt)
opt = opt.replace('-', '_')
opt = self.dash_to_underscore_warning(opt, section)
opt_dict[opt] = (filename, val)

# Make the ConfigParser forget everything (so we retain
Expand All @@ -623,6 +623,19 @@ def _parse_config_files(self, filenames=None): # noqa: C901
except ValueError as e:
raise DistutilsOptionError(e) from e

def dash_to_underscore_warning(self, opt, section):
if section in (
'options.extras_require', 'options.data_files',
):
return opt
underscore_opt = opt.replace('-', '_')
if '-' in opt:
warnings.warn(
"Usage of dash-separated '%s' will not be supported in future "
"versions. Please use the underscore name '%s' instead"
% (opt, underscore_opt))
return underscore_opt

# FIXME: 'Distribution._set_command_options' is too complex (14)
def _set_command_options(self, command_obj, option_dict=None): # noqa: C901
"""
Expand Down
2 changes: 1 addition & 1 deletion setuptools/tests/test_build_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def test_build_ext_config_handling(tmpdir_cwd):
'setup.cfg': DALS(
"""
[build]
build-base = foo_build
build_base = foo_build
"""),
}
path.build(files)
Expand Down
37 changes: 35 additions & 2 deletions setuptools/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ def test_aliases(self, tmpdir):
fake_env(
tmpdir,
'[metadata]\n'
'author-email = [email protected]\n'
'home-page = http://test.test.com/test/\n'
'author_email = [email protected]\n'
'home_page = http://test.test.com/test/\n'
'summary = Short summary\n'
'platform = a, b\n'
'classifier =\n'
Expand Down Expand Up @@ -507,6 +507,25 @@ def test_not_utf8(self, tmpdir):
with get_dist(tmpdir):
pass

def test_dash_to_underscore_warning(self, tmpdir):
# dash_to_underscore_warning() is a method in setuptools.dist
# remove this test and method when dash convert to underscore in setup.cfg
# is no longer supported
fake_env(
tmpdir,
'[metadata]\n'
'author-email = [email protected]\n'
'maintainer_email = [email protected]\n'
)
msg = ("Usage of dash-separated 'author-email' will not be supported "
"in future versions. "
"Please use the underscore name 'author_email' instead")
with pytest.warns(UserWarning, match=msg):
with get_dist(tmpdir) as dist:
metadata = dist.metadata
assert metadata.author_email == '[email protected]'
assert metadata.maintainer_email == '[email protected]'


class TestOptions:

Expand Down Expand Up @@ -772,6 +791,20 @@ def test_extras_require(self, tmpdir):
}
assert dist.metadata.provides_extras == set(['pdf', 'rest'])

def test_dash_preserved_extras_require(self, tmpdir):
fake_env(
tmpdir,
'[options.extras_require]\n'
'foo-a = foo\n'
'foo_b = test\n'
)

with get_dist(tmpdir) as dist:
assert dist.extras_require == {
'foo-a': ['foo'],
'foo_b': ['test']
}

def test_entry_points(self, tmpdir):
_, config = fake_env(
tmpdir,
Expand Down

0 comments on commit 729c45d

Please sign in to comment.