Skip to content

Instantly share code, notes, and snippets.

@SamuelMarks SamuelMarks/setup.py
Last active Aug 29, 2015

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

commented Feb 18, 2015

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
You can’t perform that action at this time.