Skip to content

Instantly share code, notes, and snippets.

@SamuelMarks
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SamuelMarks/45a998a83dd60ddbadbc to your computer and use it in GitHub Desktop.
Save SamuelMarks/45a998a83dd60ddbadbc to your computer and use it in GitHub Desktop.
An attempt to explicitly installs package dependencies **before** running `setuptools.setup`…
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)
@SamuelMarks
Copy link
Author

Hacked this together whilst troubleshooting: http://stackoverflow.com/q/28540839

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment