From a2e9ae4cb75f9b00ddf37713ec307e5f00869737 Mon Sep 17 00:00:00 2001
From: Melissa Li
Date: Tue, 2 Mar 2021 19:36:41 -0500
Subject: [PATCH 1/7] Add compatibility method to warn for future underscore
change
---
setuptools/dist.py | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/setuptools/dist.py b/setuptools/dist.py
index 6ae3886b1f..fe5bd6f8f0 100644
--- a/setuptools/dist.py
+++ b/setuptools/dist.py
@@ -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)
opt_dict[opt] = (filename, val)
# Make the ConfigParser forget everything (so we retain
@@ -623,6 +623,21 @@ 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):
+ if opt in (
+ 'home-page', 'download-url', 'author-email',
+ 'maintainer-email', 'long-description', 'build-base',
+ 'project-urls', 'license-file', 'license-files',
+ 'long-description-content-type',
+ ):
+ underscore_opt = opt.replace('-', '_')
+ 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
+ return opt
+
# FIXME: 'Distribution._set_command_options' is too complex (14)
def _set_command_options(self, command_obj, option_dict=None): # noqa: C901
"""
From d027d6d2140daf87079dd3bd186585a5b063269e Mon Sep 17 00:00:00 2001
From: Melissa Li
Date: Tue, 2 Mar 2021 20:13:06 -0500
Subject: [PATCH 2/7] Modify existing tests to be compatible with future
underscore change
---
setuptools/command/easy_install.py | 2 +-
setuptools/tests/test_build_ext.py | 2 +-
setuptools/tests/test_config.py | 4 ++--
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py
index eeb21b5083..0917804f41 100644
--- a/setuptools/command/easy_install.py
+++ b/setuptools/command/easy_install.py
@@ -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')
diff --git a/setuptools/tests/test_build_ext.py b/setuptools/tests/test_build_ext.py
index be03893a1b..b6deebe4e2 100644
--- a/setuptools/tests/test_build_ext.py
+++ b/setuptools/tests/test_build_ext.py
@@ -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)
diff --git a/setuptools/tests/test_config.py b/setuptools/tests/test_config.py
index 6db86c7c58..0983f8362d 100644
--- a/setuptools/tests/test_config.py
+++ b/setuptools/tests/test_config.py
@@ -210,8 +210,8 @@ def test_aliases(self, tmpdir):
fake_env(
tmpdir,
'[metadata]\n'
- 'author-email = test@test.com\n'
- 'home-page = http://test.test.com/test/\n'
+ 'author_email = test@test.com\n'
+ 'home_page = http://test.test.com/test/\n'
'summary = Short summary\n'
'platform = a, b\n'
'classifier =\n'
From 08d6a2f2b0fb4b57f749d0adaaca3efc158419cd Mon Sep 17 00:00:00 2001
From: Melissa Li
Date: Tue, 2 Mar 2021 22:54:53 -0500
Subject: [PATCH 3/7] Add test for conversion warning
---
setuptools/tests/test_config.py | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/setuptools/tests/test_config.py b/setuptools/tests/test_config.py
index 0983f8362d..4a39917922 100644
--- a/setuptools/tests/test_config.py
+++ b/setuptools/tests/test_config.py
@@ -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 = test@test.com\n'
+ 'maintainer_email = foo@foo.com\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 == 'test@test.com'
+ assert metadata.maintainer_email == 'foo@foo.com'
+
class TestOptions:
From 67a5991997659326fd1439a58e2140731144f08c Mon Sep 17 00:00:00 2001
From: Melissa Li
Date: Tue, 2 Mar 2021 23:25:39 -0500
Subject: [PATCH 4/7] Add test for dash preserved extras_require in setup.cfg
---
setuptools/tests/test_config.py | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/setuptools/tests/test_config.py b/setuptools/tests/test_config.py
index 4a39917922..eac26749d4 100644
--- a/setuptools/tests/test_config.py
+++ b/setuptools/tests/test_config.py
@@ -791,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,
From 4cd5f1a23bced5679f219387afacc59dd360bce5 Mon Sep 17 00:00:00 2001
From: Melissa Li
Date: Tue, 2 Mar 2021 23:53:19 -0500
Subject: [PATCH 5/7] Add changelog
---
changelog.d/1608.change.rst | 1 +
1 file changed, 1 insertion(+)
create mode 100644 changelog.d/1608.change.rst
diff --git a/changelog.d/1608.change.rst b/changelog.d/1608.change.rst
new file mode 100644
index 0000000000..77fcfd57b7
--- /dev/null
+++ b/changelog.d/1608.change.rst
@@ -0,0 +1 @@
+Removed the general conversion of dashes to underscores in the keys of :code:`setup.cfg` to support the usage of dashes. Added a compatibility method to warn users when they use a specific 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`
\ No newline at end of file
From 9c2b717818046a0d8679b4a97c63db2dc1e32d54 Mon Sep 17 00:00:00 2001
From: Melissa Li
Date: Wed, 3 Mar 2021 16:42:16 -0500
Subject: [PATCH 6/7] Update warning for dash to underscore conversion
---
changelog.d/1608.change.rst | 2 +-
setuptools/dist.py | 20 +++++++++-----------
2 files changed, 10 insertions(+), 12 deletions(-)
diff --git a/changelog.d/1608.change.rst b/changelog.d/1608.change.rst
index 77fcfd57b7..c0f493b16c 100644
--- a/changelog.d/1608.change.rst
+++ b/changelog.d/1608.change.rst
@@ -1 +1 @@
-Removed the general conversion of dashes to underscores in the keys of :code:`setup.cfg` to support the usage of dashes. Added a compatibility method to warn users when they use a specific 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`
\ No newline at end of file
+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`
\ No newline at end of file
diff --git a/setuptools/dist.py b/setuptools/dist.py
index fe5bd6f8f0..40440a406a 100644
--- a/setuptools/dist.py
+++ b/setuptools/dist.py
@@ -598,7 +598,7 @@ def _parse_config_files(self, filenames=None): # noqa: C901
continue
val = parser.get(section, opt)
- opt = self.dash_to_underscore_warning(opt)
+ opt = self.dash_to_underscore_warning(opt, section)
opt_dict[opt] = (filename, val)
# Make the ConfigParser forget everything (so we retain
@@ -622,21 +622,19 @@ def _parse_config_files(self, filenames=None): # noqa: C901
setattr(self, alias or opt, val)
except ValueError as e:
raise DistutilsOptionError(e) from e
-
- def dash_to_underscore_warning(self, opt):
- if opt in (
- 'home-page', 'download-url', 'author-email',
- 'maintainer-email', 'long-description', 'build-base',
- 'project-urls', 'license-file', 'license-files',
- 'long-description-content-type',
+
+ def dash_to_underscore_warning(self, opt, section):
+ if section in (
+ 'options.extras_require', 'options.data_files',
):
- underscore_opt = opt.replace('-', '_')
+ 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
- return 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
From 1af7000887487cfe1aa4d127a15e7802656f1e8a Mon Sep 17 00:00:00 2001
From: Melissa Li
Date: Wed, 3 Mar 2021 17:02:45 -0500
Subject: [PATCH 7/7] Dash to underscore compatibility
---
setuptools/dist.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/setuptools/dist.py b/setuptools/dist.py
index 40440a406a..c074468ba9 100644
--- a/setuptools/dist.py
+++ b/setuptools/dist.py
@@ -622,7 +622,7 @@ def _parse_config_files(self, filenames=None): # noqa: C901
setattr(self, alias or opt, val)
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',