Skip to content

Commit

Permalink
Fix a bug in pip when package description containing % char.
Browse files Browse the repository at this point in the history
The SafeConfigParser used by the package registry performs string
interpolation when it sees single percentage sign. This is fixed by
always replace single percentage with double % sign.
  • Loading branch information
ywangd committed Jan 8, 2017
1 parent fdf74c9 commit 89bcefe
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions bin/pip.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ def get(self, name, option_name):

def set(self, name, option_name, value):
section_name = self._get_section_name(name)
return SafeConfigParser.set(self, section_name, option_name, value)
return SafeConfigParser.set(self, section_name, option_name, value.replace('%', '%%'))

def remove_section(self, name):
section_name = self._get_section_name(name)
Expand Down Expand Up @@ -829,10 +829,10 @@ def remove(self, pkg_name):
else:
print('Package may have been removed externally without using pip. Deleting from registry ...')
else:
if os.path.isdir(os.path.expanduser('~/Documents/site-packages/%s' % pkg_name.lower())):
shutil.rmtree(os.path.expanduser('~/Documents/site-packages/%s' % pkg_name.lower()))
elif os.path.isfile(os.path.expanduser('~/Documents/site-packages/%s.py' % pkg_name.lower())):
os.remove(os.path.expanduser('~/Documents/site-packages/%s.py' % pkg_name.lower()))
if os.path.isdir(os.path.expanduser('~/Documents/site-packages/{}'.format(pkg_name.lower()))):
shutil.rmtree(os.path.expanduser('~/Documents/site-packages/{}'.format(pkg_name.lower())))
elif os.path.isfile(os.path.expanduser('~/Documents/site-packages/{}.py'.format(pkg_name.lower()))):
os.remove(os.path.expanduser('~/Documents/site-packages/{}.py'.format(pkg_name.lower())))
else:
print('Package may have been removed externally without using pip. Deleting from registry ...')

Expand Down Expand Up @@ -948,7 +948,7 @@ def update(self, pkg_name):
current = self.config.get_info(pkg_name)
hit = self.pypi.package_releases(pkg_name)[0]
if not current['version'] == hit:
print('Updating %s' % pkg_name)
print('Updating {}'.format(pkg_name))
self.remove(pkg_name)
self.install(pkg_name, VersionSpecifier(hit))
else:
Expand Down Expand Up @@ -1239,4 +1239,4 @@ def parse_requirement(requirement):
raise PipError('unknown command: {}'.format(ns.sub_command))

except PipError as e:
print('Error: {}'.format(e))
print('Error: {}'.format(e))

0 comments on commit 89bcefe

Please sign in to comment.