From a36dbf75bd6b1283fd3da28c25fd583f20025c36 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 1 Jan 2017 23:12:23 -0500 Subject: In the bootstrap script, generate a requirements.txt file and use it to install the dependencies just in time to make them available long enough to generate the egg info. --- bootstrap.py | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) (limited to 'bootstrap.py') diff --git a/bootstrap.py b/bootstrap.py index 761b8dfc..705a8720 100644 --- a/bootstrap.py +++ b/bootstrap.py @@ -5,13 +5,18 @@ environment by creating a minimal egg-info directory and then invoking the egg-info command to flesh out the egg-info directory. """ -__requires__ = ['packaging', 'six', 'appdirs'] - import os +import io +import re +import contextlib +import tempfile +import shutil import sys import textwrap import subprocess +import pip + minimal_egg_info = textwrap.dedent(""" [distutils.commands] egg_info = setuptools.command.egg_info:egg_info @@ -54,6 +59,35 @@ def run_egg_info(): subprocess.check_call(cmd) +def gen_deps(): + with io.open('setup.py', encoding='utf-8') as strm: + text = strm.read() + pattern = r'install_requires=\[(.*?)\]' + match = re.search(pattern, text, flags=re.M|re.DOTALL) + reqs = eval(match.group(1).replace('\n', '')) + with io.open('requirements.txt', 'w', encoding='utf-8') as reqs_file: + reqs_file.write('\n'.join(reqs)) + + +@contextlib.contextmanager +def install_deps(): + "Just in time make the deps available" + gen_deps() + tmpdir = tempfile.mkdtemp() + args = [ + 'install', + '-t', tmpdir, + '-r', 'requirements.txt', + ] + pip.main(args) + os.environ['PYTHONPATH'] = tmpdir + try: + yield tmpdir + finally: + shutil.rmtree(tmpdir) + + if __name__ == '__main__': ensure_egg_info() - run_egg_info() + with install_deps(): + run_egg_info() -- cgit v1.2.3