Skip to content

Instantly share code, notes, and snippets.

@dholth
Created May 18, 2014 13:01
Show Gist options
  • Save dholth/5c2296b5bfdf32deffb0 to your computer and use it in GitHub Desktop.
Save dholth/5c2296b5bfdf32deffb0 to your computer and use it in GitHub Desktop.
setup.py setup_requires implementation, first stab. To install things that are imported by setup.py itself.
#!/usr/bin/env python
# Install setup-requires before running setup.py
import sys
sys.path[0:0] = ['setup-requires']
import os, subprocess, pkg_resources
try:
requirements = [x.strip() for x in open('setup-requires.txt', 'r').readlines()]
except IOError: # file not found?
requirements = []
to_install = []
for requirement in requirements:
if not requirement or requirement.strip().startswith('#'):
continue
try:
pkg_resources.require(requirement)
except pkg_resources.DistributionNotFound:
to_install.append(requirement)
if to_install:
subprocess.call([sys.executable, "-m", "pip", "install", "-t", "setup-requires"] + to_install)
# Now run real setup.py...
exec(compile(open("real-setup.py").read().replace('\\r\\n', '\\n'),
__file__,
'exec'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment