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:

  1. create a clean virtualenv, empty directory
  2. create this setup.cfg file in cwd:
[tool:pytest]
log_format = %(name)-18s %(levelname)-8s %(message)s
  1. 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

Most upvoted comments

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 for setuptools). 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!