pip: CLI parses unrelated config files and then crashes
- 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
.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 5
- Comments: 19 (14 by maintainers)
Commits related to this issue
- DX: Work-around: Tox crashes on flake8 format setting. - Running flake8 via tox, e.g., `tox -e flake8` crashes. Setuptools uses configparser to read the config, which throws configparser.Interpol... — committed to landonb/nark by hotoffthehamster 4 years ago
- DX: Work-around: Tox crashes on flake8 format setting. - Running flake8 via tox, e.g., `tox -e flake8` crashes. Setuptools uses configparser to read the config, which throws configparser.Interpol... — committed to landonb/dob by hotoffthehamster 4 years ago
- DX: Work-around: Tox crashes on flake8 format setting. - Running flake8 via tox, e.g., `tox -e flake8` crashes. Setuptools uses configparser to read the config, which throws configparser.Interpol... — committed to landonb/dob-viewer by hotoffthehamster 4 years ago
- DX: Work-around: Tox crashes on flake8 format setting. - Running flake8 via tox, e.g., `tox -e flake8` crashes. Setuptools uses configparser to read the config, which throws configparser.Interpol... — committed to landonb/dob-prompt by hotoffthehamster 4 years ago
- DX: Work-around: Tox crashes on flake8 format setting. - Running flake8 via tox, e.g., `tox -e flake8` crashes. Setuptools uses configparser to read the config, which throws configparser.Interpol... — committed to landonb/dob-bright by landonb 4 years ago
- DX: Work-around: Tox crashes on flake8 format setting. - Running flake8 via tox, e.g., `tox -e flake8` crashes. Setuptools uses configparser to read the config, which throws configparser.Interpol... — committed to landonb/config-decorator by hotoffthehamster 4 years ago
- DX: Work-around: Tox crashes on flake8 format setting. - Running flake8 via tox, e.g., `tox -e flake8` crashes. Setuptools uses configparser to read the config, which throws configparser.Interpol... — committed to landonb/human-friendly_pedantic-timedelta by hotoffthehamster 4 years ago
- DX: Work-around: Tox crashes on flake8 format setting. - Running flake8 via tox, e.g., `tox -e flake8` crashes. Setuptools uses configparser to read the config, which throws configparser.Interpol... — committed to landonb/pep440-version-compare-cli by landonb 4 years ago
- DX: Work-around: Tox crashes on flake8 format setting. - Running flake8 via tox, e.g., `tox -e flake8` crashes. Setuptools uses configparser to read the config, which throws configparser.Interpol... — committed to landonb/easy-as-pypi by landonb 4 years ago
- text: fix pytest config pytest was using config from `tox.ini` preferentially and ignoring config from `setup.cfg`, as a side-effect doctests were not running on code/docstrings in `rdflib/`. The re... — committed to aucampia/rdflib by aucampia 2 years ago
I like having pytest config as a section in
setup.cfg
because it avoids yet another random config file lying around in the project root (I already need it forsetuptools
). I see your point but it is also up to other tools not to break for silly reasons … 😃 distutils should not try to interpolate, imo, but since it’s stdlib it’s probably impossible to change now - pip probably shouldn’t need to eagerly parse everybody else’s sections!