Created
September 5, 2013 03:38
-
-
Save jamesls/6445787 to your computer and use it in GitHub Desktop.
Download all deps of a local python package
This file contains 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 python | |
# Given a local checkout of a python package | |
# in SOURCE_DIR, this script will download all | |
# of its deps (transitively) into BUNDLE_DIR. | |
import os | |
import shutil | |
import subprocess | |
BUNDLE_DIR = '/tmp/bundle' | |
# Directory of the local package (should contain a setup.py file). | |
SOURCE_DIR = '/Users/jamesls/Source/github/packagename/' | |
dist_dir = os.path.join(SOURCE_DIR, 'dist') | |
if os.path.isdir(dist_dir): | |
shutil.rmtree(os.path.join(SOURCE_DIR, 'dist')) | |
os.chdir(SOURCE_DIR) | |
subprocess.check_call('python setup.py sdist', shell=True) | |
dist_file = os.listdir(dist_dir)[0] | |
# 'pip install -d . {SOURCE_DIR}' doesn't work. | |
# 'pip install -d . -e {SOURCE_DIR}' doesn't work. | |
# 'pip install -d some_dir -e {SOURCE_DIR}' doesn't work. | |
# 'pip install --no-install -e {SOURCE_DIR}' doesn't work. | |
# | |
# But: | |
# 1. 'pip install -d . packagename' works. | |
# 2. 'pip install -d . http://location/foo.tar.gz' works | |
# So we'll use the second option to install a remote dir | |
os.chdir(dist_dir) | |
p = subprocess.Popen('python -m SimpleHTTPServer', shell=True) | |
if not os.path.isdir(BUNDLE_DIR): | |
os.makedirs(BUNDLE_DIR) | |
try: | |
subprocess.check_call( | |
'pip install -d %s http://localhost:8000/%s' % (BUNDLE_DIR, dist_file), | |
shell=True) | |
finally: | |
p.terminate() | |
print("Downloaded deps:") | |
for package in os.listdir(BUNDLE_DIR): | |
print(package) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment