From de5b49b73864d3de963ab24e928c189284ba35f1 Mon Sep 17 00:00:00 2001 From: Antonio Russo Date: Mon, 6 Sep 2021 19:03:28 -0600 Subject: [PATCH 1/2] Preserve case of keys during edit_config This aligns behavior with 21b122e06969a9d85c65ce8276519d34da7dc747 during source distribution generation. Signed-off-by: Antonio Russo --- changelog.d/2773.change.rst | 1 + setuptools/command/setopt.py | 1 + setuptools/tests/test_setopt.py | 11 +++++++++++ 3 files changed, 13 insertions(+) create mode 100644 changelog.d/2773.change.rst diff --git a/changelog.d/2773.change.rst b/changelog.d/2773.change.rst new file mode 100644 index 0000000000..bf5ac0bc65 --- /dev/null +++ b/changelog.d/2773.change.rst @@ -0,0 +1 @@ +Preserve case of keys during edit_config diff --git a/setuptools/command/setopt.py b/setuptools/command/setopt.py index e18057c81e..893ee5153e 100644 --- a/setuptools/command/setopt.py +++ b/setuptools/command/setopt.py @@ -39,6 +39,7 @@ def edit_config(filename, settings, dry_run=False): """ log.debug("Reading configuration from %s", filename) opts = configparser.RawConfigParser() + opts.optionxform = str opts.read([filename]) for section, options in settings.items(): if options is None: diff --git a/setuptools/tests/test_setopt.py b/setuptools/tests/test_setopt.py index 0163f9af64..a34d3f61bd 100644 --- a/setuptools/tests/test_setopt.py +++ b/setuptools/tests/test_setopt.py @@ -28,3 +28,14 @@ def test_utf8_encoding_retained(self, tmpdir): parser = self.parse_config(str(config)) assert parser.get('names', 'jaraco') == 'джарако' assert parser.get('names', 'other') == 'yes' + + def test_case_retained(self, tmpdir): + """ + When editing a file, case of keys should be retained. + """ + config = tmpdir.join('setup.cfg') + self.write_text(str(config), '[names]\nFoO=bAr') + setopt.edit_config(str(config), dict(names=dict(oTher='yes'))) + parser = self.parse_config(str(config)) + assert parser.get('names', 'FoO') == 'bAr' + assert parser.get('names', 'oTher') == 'yes' From 3ce32eb107d4e6436aa687fa6a7fa4a7dad25d1f Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 8 Sep 2021 21:28:47 -0400 Subject: [PATCH 2/2] Delete 2773.change.rst --- changelog.d/2773.change.rst | 1 - 1 file changed, 1 deletion(-) delete mode 100644 changelog.d/2773.change.rst diff --git a/changelog.d/2773.change.rst b/changelog.d/2773.change.rst deleted file mode 100644 index bf5ac0bc65..0000000000 --- a/changelog.d/2773.change.rst +++ /dev/null @@ -1 +0,0 @@ -Preserve case of keys during edit_config