Created
January 17, 2014 20:20
-
-
Save davidbgk/8480685 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /usr/bin/env python2 | |
| import os | |
| import subprocess | |
| import sys | |
| from contextlib import contextmanager | |
| from wheel.install import WheelFile | |
| from wheel.util import matches_requirement | |
| @contextmanager | |
| def pushd(new_dir): | |
| current = os.getcwd() | |
| os.chdir(new_dir) | |
| try: | |
| yield | |
| finally: | |
| os.chdir(current) | |
| def download(requirements, wheeldir): | |
| wheels = [WheelFile(f) for f in os.listdir(wheeldir)] | |
| with open(requirements, 'r') as f: | |
| reqs = [ | |
| req.strip() for req in f | |
| if not req.startswith('-') | |
| and not matches_requirement(req, wheels)] | |
| if not reqs: | |
| print("Nothing to do.") | |
| return | |
| parent_pip = os.path.join(os.path.dirname(sys.executable), 'pip') | |
| pip = parent_pip if os.path.exists(parent_pip) else 'pip' | |
| cmd = '{0} wheel --wheel-dir={1}'.format(pip, wheeldir).split() + reqs | |
| try: | |
| out = subprocess.check_output(cmd) | |
| except subprocess.CalledProcessError as e: | |
| raise SystemExit(e.output) | |
| for line in out.split('\n'): | |
| if line.strip().startswith('Skipping building wheel'): | |
| url = line.split()[-1] | |
| url = url.split('#')[0] | |
| filename = url.rsplit('/')[-1] | |
| path = os.path.join(wheeldir, filename) | |
| if not os.path.exists(path): | |
| cmd = 'wget {0}'.format(url).split() | |
| with pushd(wheeldir): | |
| out += subprocess.check_output(cmd) | |
| print(out) | |
| if __name__ == '__main__': | |
| if len(sys.argv) != 3: | |
| raise SystemExit("Usage: python wheels.py <requirements> <wheel_dir>") | |
| download(sys.argv[1], sys.argv[2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment