Pip fails if the python config file contains a percentage sign in the comments
See original GitHub issueDescription
Hi,
With the following setup.cfg
file that contains the percentage sign in the comment section as
$ cat setup.cfg
[flake8]
ignore =
WPS323 # percentage sign '%'
any attempt to use pip to install a package fails with InterpolationSyntaxError
. Removing the percentage sign solves the issue, to me seems to be bug as according to the documentation1
Blank lines are ignored, as are comments, which run from a β#β character until the end of the line.
my config file should be just fine 1
Expected behavior
Expected to not see the assertion and get the package installed as:
root@d3eef6b3d7d7:/tmp# cat setup.cfg
[flake8]
ignore =
WPS323 # percentage char
root@d3eef6b3d7d7:/tmp# pip install numpy
Collecting numpy
Downloading numpy-1.21.1-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (15.8 MB)
|ββββββββββββββββββββββββββββββββ| 15.8 MB 11.9 MB/s
Installing collected packages: numpy
Successfully installed numpy-1.21.1
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
pip version
21.2.3
Python version
3.9
OS
ubuntu16.04
How to Reproduce
- Create a
setup.cfg
file with a percentage sign in the comments - In the same directory where the
setup.cfg
is, try to install any package via pip (i.e.pip install --user numpy
)
Output
ERROR: Exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/pip/_internal/cli/base_command.py", line 173, in _main
status = self.run(options, args)
File "/usr/local/lib/python3.9/site-packages/pip/_internal/cli/req_command.py", line 203, in wrapper
return func(self, options, args)
File "/usr/local/lib/python3.9/site-packages/pip/_internal/commands/install.py", line 239, in run
options.use_user_site = decide_user_install(
File "/usr/local/lib/python3.9/site-packages/pip/_internal/commands/install.py", line 652, in decide_user_install
if site_packages_writable(root=root_path, isolated=isolated_mode):
File "/usr/local/lib/python3.9/site-packages/pip/_internal/commands/install.py", line 598, in site_packages_writable
get_lib_location_guesses(root=root, isolated=isolated))
File "/usr/local/lib/python3.9/site-packages/pip/_internal/commands/install.py", line 584, in get_lib_location_guesses
scheme = get_scheme(
File "/usr/local/lib/python3.9/site-packages/pip/_internal/locations/__init__.py", line 159, in get_scheme
old = _distutils.get_scheme(
File "/usr/local/lib/python3.9/site-packages/pip/_internal/locations/_distutils.py", line 130, in get_scheme
scheme = distutils_scheme(dist_name, user, home, root, isolated, prefix)
File "/usr/local/lib/python3.9/site-packages/pip/_internal/locations/_distutils.py", line 46, in distutils_scheme
d.parse_config_files()
File "/usr/local/lib/python3.9/distutils/dist.py", line 413, in parse_config_files
val = parser.get(section,opt)
File "/usr/local/lib/python3.9/configparser.py", line 799, in get
return self._interpolation.before_get(self, section, option, value,
File "/usr/local/lib/python3.9/configparser.py", line 395, in before_get
self._interpolate_some(parser, option, L, value, section, defaults, 1)
File "/usr/local/lib/python3.9/configparser.py", line 442, in _interpolate_some
raise InterpolationSyntaxError(
configparser.InterpolationSyntaxError: '%' must be followed by '%' or '(', found: "%' in string formatting"
Code of Conduct
- I agree to follow the PSF Code of Conduct.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Configparser fails when the .cfg file contains inline 'comments'
The config file had a percentage character ("%") inside a commentary. But the module "configparser" failed with traceback: configparser.
Read more >How to store/encode URL with percentage % in config file?
If your ini file don't use interpolation, the easiest way is to disable interpolatin in the construction: config = configparser.
Read more >CLI parses unrelated config files and then crashes #5182
Can't use pip from within that directory, because it attempts to parse the file incorrectly (using a ConfigParser with interpolation) and thenΒ ...
Read more >Using Python's pip to Manage Your Projects' Dependencies
When you run the pip command, you may get an error in some cases. ... The get-pip.py file contains a full copy of...
Read more >How to Write a Configuration file in Python | by Xiaoxu Gao
It's used a lot by Python package managements like pip or poetry. But if the config file has too many nested structures, YAML...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I created https://bugs.python.org/issue44892 to ask the CPython developers about this.
@berthin I can open an issue in
bugs.python.org
, if you want π.