Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

Commit

Permalink
factor out the wheel step
Browse files Browse the repository at this point in the history
  • Loading branch information
Buck Golemon committed Nov 25, 2014
1 parent e55d234 commit d3e2076
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 40 deletions.
2 changes: 1 addition & 1 deletion tests/functional/relocation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_is_relocatable(tmpdir):
def test_is_relocatable_different_python_version(tmpdir):
tmpdir.chdir()
with io.open('requirements.txt', 'w') as reqs:
reqs.write('doge==3.5.0')
reqs.write('argparse\ndoge==3.5.0')

python_arg = '--python=python' + ('2.7' if not PY27 else '2.6')

Expand Down
5 changes: 2 additions & 3 deletions tests/functional/simple_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ def test_second_install_faster(tmpdir):
# Should I make my own fake c-extention just to remove this dependency?
requirements.write('''\
simplejson
pyyaml
pyyaml==3.11
pylint
pytest
pep8==1.0
-r {0}/requirements.d/coverage.txt
'''.format(TOP))

Expand All @@ -47,7 +46,7 @@ def test_second_install_faster(tmpdir):
# second install should be at least twice as fast
ratio = time1 / time2
print('%.2fx speedup' % ratio)
assert ratio > 3
assert ratio > 2.5


def test_arguments_version(tmpdir, capfd):
Expand Down
51 changes: 15 additions & 36 deletions venv_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,26 +135,6 @@ def _get_page(self, link, req):
PackageFinder._get_page = orig_packagefinder['_get_page']


def pip(args):
"""Run pip, in-process."""
import pip as pipmodule

# pip<1.6 needs its logging config reset on each invocation, or else we get duplicate outputs -.-
pipmodule.logger.consumers = []

from sys import stdout
stdout.write(colorize(('pip',) + args))
stdout.write('\n')
stdout.flush()

with faster_pip_packagefinder():
result = pipmodule.main(list(args))

if result != 0:
# pip exited with failure, then we should too
exit(result)


def pip_get_installed():
"""Code extracted from the middle of the pip freeze command.
"""
Expand Down Expand Up @@ -204,7 +184,8 @@ def pip_install(args):
install = InstallCommand()
options, args = install.parse_args(list(args))

successfully_installed = install.run(options, args)
with faster_pip_packagefinder():
successfully_installed = install.run(options, args)
if successfully_installed is None:
return {}
else:
Expand Down Expand Up @@ -233,7 +214,14 @@ def trace_requirements(requirements):

result[dist.project_name] = dist

for req in dist.requires(): # should we support extras?
try:
dist_reqs = dist.requires() # should we support extras?
except IOError:
# This happens sometimes with setuptools. Don't understand why, yet.
# IOError: [Errno 2] No such file or directory: '${site-packages}/setuptools-3.6.dist-info/METADATA'
continue

for req in dist_reqs:
if req.project_name not in result:
stack.append(req)

Expand Down Expand Up @@ -263,6 +251,7 @@ def venv_uses_system_site_packages():

def do_install(reqs):
from os import environ
from sys import executable as python

previously_installed = pip_get_installed()
required = pip_parse_requirements(reqs)
Expand All @@ -284,18 +273,9 @@ def do_install(reqs):
'--find-links=file://' + pip_download_cache,
)

# --use-wheel is somewhat redundant here, but it means we get an error if we have a bad version of pip/setuptools.
install_opts = ('--use-wheel',) + cache_opts
wheel = ('wheel',) + cache_opts

# 1) Bootstrap the install system; setuptools and pip are already installed, just need wheel
pip_install(install_opts + ('wheel',))

# 2) Caching: Make sure everything we want is downloaded, cached, and has a wheel.
pip(wheel + ('--wheel-dir=' + pip_download_cache, 'wheel') + requirements_as_options)

# 3) Install: Use our well-populated cache (only) to do the installations.
install_opts += ('--upgrade', '--no-index',)
# --use-wheel is somewhat redundant here, but it means we get an error if we have a bad version of pip/setuptools.
install_opts = ('--upgrade', '--use-wheel',) + cache_opts
if venv_uses_system_site_packages():
# In the worst case, a --system-site-packages venv will be missing packages because it was built in an
# environment which satisfied requirements at the system level, then be relocated to a system that doesn't have
Expand All @@ -313,13 +293,12 @@ def do_install(reqs):
extraneous = (
set(previously_installed) -
set(required_with_deps) -
set(recently_installed) -
set(['wheel']) # no need to install/uninstall wheel every run
set(recently_installed)
)

# 4) Uninstall any extraneous packages.
if extraneous:
pip(('uninstall', '--yes') + tuple(sorted(extraneous)))
run((python, '-m', 'pip', 'uninstall', '--yes') + tuple(sorted(extraneous)))

return 0 # posix:success!

Expand Down

0 comments on commit d3e2076

Please sign in to comment.