From 003b4afc8cfce58d4fb9b62c6fdb6b03d362afd9 Mon Sep 17 00:00:00 2001 From: Benoit Pierre Date: Tue, 18 Jul 2017 08:54:05 +0200 Subject: [PATCH] disable interpolation when parsing config files Fix #889. --- setuptools/dist.py | 2 +- setuptools/py36compat.py | 15 +++++---------- setuptools/tests/test_config.py | 9 +++++++++ 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/setuptools/dist.py b/setuptools/dist.py index a805cac613a..9b12acf33a5 100644 --- a/setuptools/dist.py +++ b/setuptools/dist.py @@ -438,7 +438,7 @@ def parse_config_files(self, filenames=None): and loads configuration. """ - _Distribution.parse_config_files(self, filenames=filenames) + Distribution_parse_config_files.parse_config_files(self, filenames=filenames) parse_configuration(self, self.command_options) if getattr(self, 'python_requires', None): diff --git a/setuptools/py36compat.py b/setuptools/py36compat.py index f5279696457..05fef406b40 100644 --- a/setuptools/py36compat.py +++ b/setuptools/py36compat.py @@ -2,6 +2,7 @@ from distutils.errors import DistutilsOptionError from distutils.util import strtobool from distutils.debug import DEBUG +from setuptools.extern import six class Distribution_parse_config_files: @@ -13,10 +14,10 @@ class Distribution_parse_config_files: as implemented in distutils. """ def parse_config_files(self, filenames=None): - from configparser import ConfigParser + from setuptools.extern.six.moves.configparser import ConfigParser # Ignore install directory options if we have a venv - if sys.prefix != sys.base_prefix: + if six.PY3 and sys.prefix != sys.base_prefix: ignore_options = [ 'install-base', 'install-platbase', 'install-lib', 'install-platlib', 'install-purelib', 'install-headers', @@ -33,7 +34,7 @@ def parse_config_files(self, filenames=None): if DEBUG: self.announce("Distribution.parse_config_files():") - parser = ConfigParser(interpolation=None) + parser = ConfigParser() for filename in filenames: if DEBUG: self.announce(" reading %s" % filename) @@ -44,7 +45,7 @@ def parse_config_files(self, filenames=None): for opt in options: if opt != '__name__' and opt not in ignore_options: - val = parser.get(section,opt) + val = parser.get(section,opt,raw=True) opt = opt.replace('-', '_') opt_dict[opt] = (filename, val) @@ -69,12 +70,6 @@ def parse_config_files(self, filenames=None): raise DistutilsOptionError(msg) -if sys.version_info < (3,): - # Python 2 behavior is sufficient - class Distribution_parse_config_files: - pass - - if False: # When updated behavior is available upstream, # disable override here. diff --git a/setuptools/tests/test_config.py b/setuptools/tests/test_config.py index 8bd2a494281..2b118b701bb 100644 --- a/setuptools/tests/test_config.py +++ b/setuptools/tests/test_config.py @@ -288,6 +288,15 @@ def test_classifiers(self, tmpdir): with get_dist(tmpdir) as dist: assert set(dist.metadata.classifiers) == expected + def test_no_interpolation(self, tmpdir): + fake_env( + tmpdir, + '[metadata]\n' + 'description = %(message)s\n' + ) + with get_dist(tmpdir) as dist: + assert dist.metadata.description == '%(message)s' + class TestOptions: