1
1
Fork 0
mirror of https://github.com/pypa/pip synced 2023-12-13 21:30:23 +01:00

uninstall from requirements file

This commit is contained in:
Carl Meyer 2009-03-31 17:57:38 -05:00
parent d9d32ae25b
commit 470f66515a
2 changed files with 26 additions and 3 deletions

15
pip.py
View file

@ -439,6 +439,14 @@ class UninstallCommand(Command):
def __init__(self):
super(UninstallCommand, self).__init__()
self.parser.add_option(
'-r', '--requirement',
dest='requirements',
action='append',
default=[],
metavar='FILENAME',
help='Uninstall all the packages listed in the given requirements file. '
'This option can be used multiple times.')
self.parser.add_option(
'-y', '--yes',
dest='yes',
@ -453,6 +461,9 @@ class UninstallCommand(Command):
for name in args:
requirement_set.add_requirement(
InstallRequirement.from_line(name))
for filename in options.requirements:
for req in parse_requirements(filename):
requirement_set.add_requirement(req)
requirement_set.uninstall(auto_confirm=options.yes)
UninstallCommand()
@ -3429,7 +3440,7 @@ def get_file_content(url, comes_from=None):
f.close()
return url, content
def parse_requirements(filename, finder, comes_from=None):
def parse_requirements(filename, finder=None, comes_from=None):
skip_match = None
if os.environ.get('PIP_SKIP_REQUIREMENTS_REGEX'):
skip_match = re.compile(os.environ['PIP_SKIP_REQUIREMENTS_REGEX'])
@ -3457,7 +3468,7 @@ def parse_requirements(filename, finder, comes_from=None):
# No longer used, but previously these were used in
# requirement files, so we'll ignore.
pass
elif line.startswith('-f') or line.startswith('--find-links'):
elif finder and line.startswith('-f') or line.startswith('--find-links'):
if line.startswith('-f'):
line = line[2:].strip()
else:

View file

@ -1,6 +1,6 @@
Basic setup::
>>> from __main__ import here, reset_env, run_pip, pyversion, lib_py, get_env, diff_states
>>> from __main__ import here, reset_env, run_pip, pyversion, lib_py, get_env, diff_states, write_file
>>> easy_install_pth = lib_py + 'site-packages/easy-install.pth'
Simple install and uninstall::
@ -41,3 +41,15 @@ Uninstall an editable installation from svn::
>>> diff_states(result.files_before, result2.files_after).values()
[{}, {}, {}]
Uninstall from a requirements file::
>>> reset_env()
>>> write_file('test-req.txt', '''\
... -e svn+http://svn.colorstudy.com/INITools/trunk#egg=initools-dev
... # and something else to test out:
... simplejson<=1.7.4
... ''')
>>> result = run_pip('install', '-r', 'test-req.txt')
>>> result2 = run_pip('uninstall', '-r', 'test-req.txt', '-y')
>>> diff_states(result.files_before, result2.files_after, ignore_keys=['build']).values()
[{}, {}, {}]