Repository: pypa/setuptools

Issue:
Deprecation of dashes affects other project settings
Hi! I checked https://setuptools.readthedocs.io/en/latest/history.html#v54-1-0 but I wasn't entirely clear: is this meant to warn for all keys using hyphens in `setup.cfg`? For example, I see warnings for these Flake8 options:


```console
$ cat setup.cfg
[flake8]
extend-ignore = E203
max-line-length = 88

[isort]
profile = black

[tool:pytest]
addopts = -ra --color=yes
testpaths = Tests
$ python setup.py --version
/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/setuptools/dist.py:633: UserWarning: Usage of dash-separated 'extend-ignore' will not be supported in future versions. Please use the underscore name 'extend_ignore' instead
  warnings.warn(
/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/setuptools/dist.py:633: UserWarning: Usage of dash-separated 'max-line-length' will not be supported in future versions. Please use the underscore name 'max_line_length' instead
  warnings.warn(
/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/setuptools/dist.py:633: UserWarning: Usage of dash-separated 'extend-ignore' will not be supported in future versions. Please use the underscore name 'extend_ignore' instead
  warnings.warn(
/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/setuptools/dist.py:633: UserWarning: Usage of dash-separated 'max-line-length' will not be supported in future versions. Please use the underscore name 'max_line_length' instead
  warnings.warn(
8.2.0.dev0
```

Flake8 themselves say both underscores and hyphens are fine in `setup.cfg`:

https://flake8.pycqa.org/en/latest/user/configuration.html#project-configuration

Thanks!

_Originally posted by @hugovk in https://github.com/pypa/setuptools/issues/2588#issuecomment-792040266_
Deprecation of dashes affects other project settings
Hi! I checked https://setuptools.readthedocs.io/en/latest/history.html#v54-1-0 but I wasn't entirely clear: is this meant to warn for all keys using hyphens in `setup.cfg`? For example, I see warnings for these Flake8 options:


```console
$ cat setup.cfg
[flake8]
extend-ignore = E203
max-line-length = 88

[isort]
profile = black

[tool:pytest]
addopts = -ra --color=yes
testpaths = Tests
$ python setup.py --version
/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/setuptools/dist.py:633: UserWarning: Usage of dash-separated 'extend-ignore' will not be supported in future versions. Please use the underscore name 'extend_ignore' instead
  warnings.warn(
/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/setuptools/dist.py:633: UserWarning: Usage of dash-separated 'max-line-length' will not be supported in future versions. Please use the underscore name 'max_line_length' instead
  warnings.warn(
/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/setuptools/dist.py:633: UserWarning: Usage of dash-separated 'extend-ignore' will not be supported in future versions. Please use the underscore name 'extend_ignore' instead
  warnings.warn(
/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/setuptools/dist.py:633: UserWarning: Usage of dash-separated 'max-line-length' will not be supported in future versions. Please use the underscore name 'max_line_length' instead
  warnings.warn(
8.2.0.dev0
```

Flake8 themselves say both underscores and hyphens are fine in `setup.cfg`:

https://flake8.pycqa.org/en/latest/user/configuration.html#project-configuration

Thanks!

_Originally posted by @hugovk in https://github.com/pypa/setuptools/issues/2588#issuecomment-792040266_


Discussion:

Resolving patch:
diff --git a/setuptools/dist.py b/setuptools/dist.py
--- a/setuptools/dist.py
+++ b/setuptools/dist.py
@@ -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
@@ -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
@@ -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)
 
@@ -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 "


Test patch:
diff --git a/setuptools/tests/test_config.py b/setuptools/tests/test_config.py
--- a/setuptools/tests/test_config.py
+++ b/setuptools/tests/test_config.py
@@ -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'
@@ -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 == 'test@test.com'
-                assert metadata.maintainer_email == 'foo@foo.com'
 
-    def test_uppercase_warning(self, tmpdir):
-        # remove this test and the method uppercase_warning() in setuptools.dist
+        assert metadata.author_email == 'test@test.com'
+        assert metadata.maintainer_email == 'foo@foo.com'
+
+    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,