CLI parses unrelated config files and then crashes · Issue #5182 · pypa/pip (original) (raw)
- Pip version: 9.0.3
- Python version: 3.6.4
- Operating system: Linux
Local project keeps configuration in a [tool:pytest]
section of setup.cfg
. Can't use pip from within that directory, because it attempts to parse the file incorrectly (using a ConfigParser
with interpolation) and then crashes out.
minimal steps to reproduce:
- create a clean virtualenv, empty directory
- create this
setup.cfg
file in cwd:
[tool:pytest]
log_format = %(name)-18s %(levelname)-8s %(message)s
- run unrelated pip command, e.g.
pip install --upgrade pip
.
Exception:
Traceback (most recent call last):
File "/tmp/blah/venv/lib64/python3.6/site-packages/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/tmp/blah/venv/lib64/python3.6/site-packages/pip/commands/install.py", line 350, in run
isolated=options.isolated_mode,
File "/tmp/blah/venv/lib64/python3.6/site-packages/pip/commands/install.py", line 436, in get_lib_location_guesses
scheme = distutils_scheme('', *args, **kwargs)
File "/tmp/blah/venv/lib64/python3.6/site-packages/pip/locations.py", line 141, in distutils_scheme
d.parse_config_files()
File "/usr/lib64/python3.6/distutils/dist.py", line 402, in parse_config_files
val = parser.get(section,opt)
File "/usr/lib64/python3.6/configparser.py", line 800, in get
d)
File "/usr/lib64/python3.6/configparser.py", line 394, in before_get
self._interpolate_some(parser, option, L, value, section, defaults, 1)
File "/usr/lib64/python3.6/configparser.py", line 427, in _interpolate_some
"bad interpolation variable reference %r" % rest)
configparser.InterpolationSyntaxError: bad interpolation variable reference '%(name)-18s %(levelname)-8s %(message)s'
That's a valid pytest config section but ConfigParser
is getting confused thinking parts of the logging config are interpolation references. I don't know how best to fix this issue because it's actually in distutils.dist.Distribution
where they create a ConfigParser
and there is not public API to enable/disable interpolation. However, perhaps pip's locations.py
shouldn't be attempting to eagerly parse this file in the first place?
Existing workaround: Changing out of the directory that has setup.cfg
before using pip
.