Skip to content

Reduce scope of dash deprecation warning. Fixes #2595 #2600

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 3 commits into from
Mar 14, 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
1 change: 1 addition & 0 deletions changelog.d/2595.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Reduced scope of dash deprecation warning to Setuptools/distutils only -- by :user:`melissa-kun-li`
12 changes: 10 additions & 2 deletions setuptools/dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import distutils.core
import distutils.cmd
import distutils.dist
import distutils.command
from distutils.util import strtobool
from distutils.debug import DEBUG
from distutils.fancy_getopt import translate_longopt
Expand All @@ -29,6 +30,7 @@
from . import SetuptoolsDeprecationWarning

import setuptools
import setuptools.command
from setuptools import windows_support
from setuptools.monkey import get_unpatched
from setuptools.config import parse_configuration
Expand Down Expand Up @@ -598,7 +600,7 @@ def _parse_config_files(self, filenames=None): # noqa: C901
continue

val = parser.get(section, opt)
opt = self.dash_to_underscore_warning(opt, section)
opt = self.warn_dash_deprecation(opt, section)
opt = self.make_option_lowercase(opt, section)
opt_dict[opt] = (filename, val)

Expand All @@ -624,12 +626,18 @@ 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):
def warn_dash_deprecation(self, opt, section):
if section in (
'options.extras_require', 'options.data_files',
):
return opt

underscore_opt = opt.replace('-', '_')
commands = distutils.command.__all__ + setuptools.command.__all__
if (not section.startswith('options') and section != 'metadata'
and section not in commands):
return underscore_opt

if '-' in opt:
warnings.warn(
"Usage of dash-separated '%s' will not be supported in future "
Expand Down
16 changes: 8 additions & 8 deletions setuptools/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,10 +507,9 @@ 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
def test_warn_dash_deprecation(self, tmpdir):
# warn_dash_deprecation() is a method in setuptools.dist
# remove this test and the method when no longer needed
fake_env(
tmpdir,
'[metadata]\n'
Expand All @@ -523,11 +522,12 @@ def test_dash_to_underscore_warning(self, tmpdir):
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]'

def test_uppercase_warning(self, tmpdir):
# remove this test and the method uppercase_warning() in setuptools.dist
assert metadata.author_email == '[email protected]'
assert metadata.maintainer_email == '[email protected]'

def test_make_option_lowercase(self, tmpdir):
# remove this test and the method make_option_lowercase() in setuptools.dist
# when no longer needed
fake_env(
tmpdir,
Expand Down