Repository: asottile/setup-cfg-fmt

Issue:
normalize dashed-keys to underscored_keys
setuptools apparently allows both, but canonically spells them with underscores

found in https://github.com/pfmoore/editables/pull/2

Discussion:

Patch:
diff --git a/setup_cfg_fmt.py b/setup_cfg_fmt.py
index b1967b2..d541a70 100644
--- a/setup_cfg_fmt.py
+++ b/setup_cfg_fmt.py
@@ -398,11 +398,11 @@ def format_file(
         if section not in cfg:
             continue
 
-        new_section = {
-            k: cfg[section].pop(k) for k in key_order if k in cfg[section]
-        }
+        entries = {k.replace('-', '_'): v for k, v in cfg[section].items()}
+
+        new_section = {k: entries.pop(k) for k in key_order if k in entries}
         # sort any remaining keys
-        new_section.update(sorted(cfg[section].items()))
+        new_section.update(sorted(entries.items()))
 
         sections[section] = new_section
         cfg.pop(section)


Test patch:
diff --git a/tests/setup_cfg_fmt_test.py b/tests/setup_cfg_fmt_test.py
index 6558886..677291b 100644
--- a/tests/setup_cfg_fmt_test.py
+++ b/tests/setup_cfg_fmt_test.py
@@ -192,6 +192,19 @@ def test_rewrite_requires(which, input_tpl, expected_tpl, tmpdir):
 
             id='orders authors and maintainers',
         ),
+        pytest.param(
+            '[metadata]\n'
+            'name = pkg\n'
+            'author-email = john@example.com\n'
+            'maintainer-email = jane@example.com\n',
+
+            '[metadata]\n'
+            'name = pkg\n'
+            'author_email = john@example.com\n'
+            'maintainer_email = jane@example.com\n',
+
+            id='normalize dashes to underscores in keys',
+        ),
     ),
 )
 def test_rewrite(input_s, expected, tmpdir):