Last active
August 29, 2015 14:15
-
-
Save SamuelMarks/45a998a83dd60ddbadbc to your computer and use it in GitHub Desktop.
An attempt to explicitly installs package dependencies **before** running `setuptools.setup`…
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
from pip.commands import install | |
from pip.exceptions import DistributionNotFound | |
def setup2(**kwargs): | |
kwargs['install_requires'] = kwargs.get('dependency_links', []) + kwargs.get('install_requires', []) | |
if path.exists('requirements.txt'): | |
kwargs['install_requires'] += open('requirements.txt', 'r').readlines() | |
install_cmd = install.InstallCommand() | |
print 'Installing:', kwargs['install_requires'] | |
try: | |
install_cmd.run(*install_cmd.parse_args(kwargs['install_requires'])) | |
except DistributionNotFound as e: | |
name = e.message[e.message.rfind(' ') + 1:] | |
if len(filter(lambda n: n == name, kwargs['install_requires'])) > 1: | |
pass | |
else: | |
print e | |
kwargs['install_requires'] = filter(lambda i: i != name, | |
kwargs['install_requires']) # HAAAACK | |
# raise e # RAISE THIS! | |
kwargs.pop('install_requires') # Deps already handled [hopefully!] | |
return setup(**kwargs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hacked this together whilst troubleshooting: http://stackoverflow.com/q/28540839