-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
Percent-signs (%) in .pypirc should not be interpolated #64319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This works fine in Python 2.7, but it fails in Python 3.3. [tlevine@wildebeest mailfest-scoreboard]$ python3 --version
Python 3.3.3
[tlevine@wildebeest mailfest-scoreboard]$ python3 setup.py register sdist
running register
Traceback (most recent call last):
File "setup.py", line 11, in <module>
scripts=['scoreboard']
File "/usr/lib/python3.3/distutils/core.py", line 148, in setup
dist.run_commands()
File "/usr/lib/python3.3/distutils/dist.py", line 929, in run_commands
self.run_command(cmd)
File "/usr/lib/python3.3/distutils/dist.py", line 948, in run_command
cmd_obj.run()
File "/usr/lib/python3.3/distutils/command/register.py", line 45, in run
self._set_config()
File "/usr/lib/python3.3/distutils/command/register.py", line 71, in _set_config
config = self._read_pypirc()
File "/usr/lib/python3.3/distutils/config.py", line 83, in _read_pypirc
current[key] = config.get(server, key)
File "/usr/lib/python3.3/configparser.py", line 790, in get
d)
File "/usr/lib/python3.3/configparser.py", line 391, in before_get
self._interpolate_some(parser, option, L, value, section, defaults, 1)
File "/usr/lib/python3.3/configparser.py", line 440, in _interpolate_some
"found: %r" % (rest,))
configparser.InterpolationSyntaxError: '%' must be followed by '%' or '(', found: '%rest-of-my-password' Here are the relevant files. [tlevine@wildebeest mailfest-scoreboard]$ cat ~/.pypirc [pypi] from distutils.core import setup
setup(name='mailfest-scoreboard',
version='0.0.1',
description='Score mailfest participants',
author='Thomas Levine',
author_email='_@thomaslevine.com',
url='https://github.com/tlevine/mailfest-scoreboard',
scripts=['scoreboard']
) |
The relevant section distutils/config.py seems no different in Python 2.7, so now I see this as a bug in configparser. |
Hmm now it looks to me like this is the intended behavior. Switching the single percent sign (%) to two (%%) in .pypirc makes it work. Maybe we can make a nicer error message though. |
It could be an issue of which configparser is/was used. |
In 3.x, the ConfigParser class is 2.x's SafeConfigParser, and the parsing rules are different (stricter, it seems). It's probably a won't fix, I'd say. |
"More rational" is probably closer to the truth :). Yeah, it's probably a won't fix, but it would be nice to have Łukasz's input. |
Yes, that's wontfix but we can make the error message more friendly so I'll leave this open. The .pypirc parser should have been RawConfigParser from the start, the interpolation mechanism is obscure enough it's probably not used. Unfortunately this "probably" means we cannot easily switch it to RawConfigParser now. |
When I uploaded via "setup.py register" and created a new user, then distutils saved the password in the wrong format! So maybe the password read part is a wontfix, but then the save part must be fixed. |
This same issue applies to setuptools (https://bitbucket.org/pypa/setuptools/issues/442/setuptools-1832-cannot-access-pypi-if-pypi). I've created a test that captures the failure, but I struggled to find a solution that doesn't break across Python versions. Thomas suggested guiding the user to provide two percent signs instead of one, but that breaks on Python 2, which will interpret the value as two percent signs. As suggested, using RawConfigParser does address the issue on both Python 2 and 3, but that of course could break compatibility if interpolation was expected. I have found that if one uses SafeConfigParser on Python 2 and 3, and requires the user to use two percent signs to represent one, it does seem to work on both Python 2 and 3. |
The error message could just say. something to the effect of ".pypyrc works differently in Python 2 and Python 3. If you want a percent sign in Python 3, you have to escape it with another percent sign". Suppose someone is already using a configuration file that specifies a value as having two literal percent signs in a row, like a password that actually contains two percent signs. I see no way of fixing the present bug without breaking this situation, and I presume that this is why Antoine suggested that this is a wont fix. |
It doesn't make sense to give guidance to use one percent sign on one Python and two on another because .pypirc applies to all Python versions. I'm sure it's not uncommon for one to use different versions of Python for various package releases. I'm planning to use RawConfigParser in Setuptools. If there's no fallout from this change, I suggest that Python 3 should do the same for distutils in bugfix releases, as this behavior is a regression over Python 2. |
I noticed something else that might be interesting. python3.5 -c 'import setuptools; setuptools.setup()' register the .pypirc is created with the un-escaped percent sign and without error. If a different config parser is being used in the writing, perhaps we could at least use the same one in both places. |
Setuptools 19 has been out for over a month now with no adverse consequences. Łukasz and David, as you both originally tagged this as won't fix, how would you feel about interpreting this as a defect and regression over Python 2.7 and fixing it it all Python 3 versions that receive bug fixes and bringing it into parity with Setuptools? If you give me the green light, I'll apply the patches. |
So fixing distutils to use RawConfigParser? How likely is that to break currently working python3-only code? I'm imagining from what you wrote that your answer is "very close to zero', but I'd like explicit confirmation :) |
I also expect very close to zero, given the still heavy adoption of Python 2 and the fact that .pypirc is not Python specific. |
Closing this as setuptools switched to RawConfigParser. |
Łukasz, my proposal was to also update distutils (in all Python versions that get bugfixes) to match the Setuptools behavior and Python 2 behavior. I'd still like to do that to harmonize the implementations. |
Oh, my bad. Yeah, that sounds like a worthwhile change. |
I just confirmed only Python 3.5 gets bugfixes, so I'll apply this to 3.5 and default. |
New changeset eae59b6bf133 by Jason R. Coombs in branch '3.5': New changeset 89116bd505cb by Jason R. Coombs in branch 'default': |
Fixed now. I'll watch the buildbots to assure acceptance. |
New changeset 83d731f01dde by Berker Peksag in branch '3.5': New changeset 703d9066c459 by Berker Peksag in branch 'default': |
I just upgraded from 3.5.1 to 3.5.2 and found that I couldn't authenticate to PyPI anymore. And then I remembered that this had been fixed, so removed the extra percent sign, and my uploads worked. Thanks! |
Not sure if it's in the scope of this issue but I thought I'd report it. I've just hit a similar issue with
(https://github.com/ansible/pylibssh/runs/640262804?check_suite_focus=true#step:7:32) This is caused by
|
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: