mirror of
https://github.com/pypa/pip
synced 2023-12-13 21:30:23 +01:00
add support for global distutils options
This commit is contained in:
parent
d06c98dc6f
commit
d8b00e253b
3 changed files with 36 additions and 7 deletions
|
@ -123,6 +123,14 @@ class InstallCommand(Command):
|
|||
"Use multiple --install-option options to pass multiple options to setup.py install. "
|
||||
"If you are using an option with a directory path, be sure to use absolute path.")
|
||||
|
||||
self.parser.add_option(
|
||||
'--global-option',
|
||||
dest='global_options',
|
||||
action='append',
|
||||
help="Extra global options to be supplied to the setup.py"
|
||||
"call before the install command"
|
||||
)
|
||||
|
||||
def run(self, options, args):
|
||||
if not options.build_dir:
|
||||
options.build_dir = build_prefix
|
||||
|
@ -134,6 +142,7 @@ class InstallCommand(Command):
|
|||
options.build_dir = os.path.abspath(options.build_dir)
|
||||
options.src_dir = os.path.abspath(options.src_dir)
|
||||
install_options = options.install_options or []
|
||||
global_options = options.global_options or []
|
||||
index_urls = [options.index_url] + options.extra_index_urls
|
||||
if options.no_index:
|
||||
logger.notify('Ignoring indexes: %s' % ','.join(index_urls))
|
||||
|
@ -163,7 +172,7 @@ class InstallCommand(Command):
|
|||
else:
|
||||
requirement_set.locate_files()
|
||||
if not options.no_install and not self.bundle:
|
||||
requirement_set.install(install_options)
|
||||
requirement_set.install(install_options, global_options)
|
||||
installed = ' '.join([req.name for req in
|
||||
requirement_set.successfully_installed])
|
||||
if installed:
|
||||
|
|
20
pip/req.py
20
pip/req.py
|
@ -517,7 +517,7 @@ execfile(__file__)
|
|||
name = name.replace(os.path.sep, '/')
|
||||
return name
|
||||
|
||||
def install(self, install_options):
|
||||
def install(self, install_options, global_options=()):
|
||||
if self.editable:
|
||||
self.install_editable()
|
||||
return
|
||||
|
@ -525,9 +525,14 @@ execfile(__file__)
|
|||
record_filename = os.path.join(temp_location, 'install-record.txt')
|
||||
try:
|
||||
|
||||
install_args = [sys.executable, '-c',
|
||||
"import setuptools; __file__=%r; execfile(%r)" % (self.setup_py, self.setup_py),
|
||||
'install', '--single-version-externally-managed', '--record', record_filename]
|
||||
install_args = [
|
||||
sys.executable, '-c',
|
||||
"import setuptools;__file__=%r;execfile(__file__)" % self.setup_py
|
||||
] + list(global_options) + [
|
||||
'install',
|
||||
'--single-version-externally-managed',
|
||||
'--record', record_filename,
|
||||
]
|
||||
|
||||
if in_venv():
|
||||
## FIXME: I'm not sure if this is a reasonable location; probably not
|
||||
|
@ -542,6 +547,9 @@ execfile(__file__)
|
|||
cwd=self.source_dir, filter_stdout=self._filter_install, show_stdout=False)
|
||||
finally:
|
||||
logger.indent -= 2
|
||||
if not os.path.exists(record_filename):
|
||||
logger.notify('Record file %s not found' % record_filename)
|
||||
return
|
||||
self.install_succeeded = True
|
||||
f = open(record_filename)
|
||||
for line in f:
|
||||
|
@ -1224,7 +1232,7 @@ class RequirementSet(object):
|
|||
finally:
|
||||
tar.close()
|
||||
|
||||
def install(self, install_options):
|
||||
def install(self, install_options, global_options=()):
|
||||
"""Install everything in this set (after having downloaded and unpacked the packages)"""
|
||||
to_install = sorted([r for r in self.requirements.values()
|
||||
if self.upgrade or not r.satisfied_by],
|
||||
|
@ -1243,7 +1251,7 @@ class RequirementSet(object):
|
|||
finally:
|
||||
logger.indent -= 2
|
||||
try:
|
||||
requirement.install(install_options)
|
||||
requirement.install(install_options, global_options)
|
||||
except:
|
||||
# if install did not succeed, rollback previous uninstall
|
||||
if requirement.conflicts_with and not requirement.install_succeeded:
|
||||
|
|
|
@ -250,3 +250,15 @@ def test_install_pardir():
|
|||
result = run_pip('install', pardir, cwd=run_from, expect_error=False)
|
||||
assert (env.site_packages/'fspkg') in result.files_created, str(result.stdout)
|
||||
assert (env.site_packages/'FSPkg-0.1dev-py%s.egg-info' % pyversion) in result.files_created, str(result)
|
||||
|
||||
|
||||
def test_install_global_option():
|
||||
"""
|
||||
test using global distutils options.
|
||||
|
||||
in particular those that disable the actual install action\
|
||||
|
||||
"""
|
||||
reset_env()
|
||||
result = run_pip('install', '--global-option=--version', "INITools==0.1")
|
||||
assert '0.1\n' in result.stdout
|
||||
|
|
Loading…
Reference in a new issue