From a6e71a5bf5c423a1e10bdf1f37f4cf261066d323 Mon Sep 17 00:00:00 2001 From: James Tocknell Date: Fri, 19 Sep 2014 13:12:56 +1000 Subject: Fix requirements --- setup.py | 53 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 13 deletions(-) (limited to 'setup.py') diff --git a/setup.py b/setup.py index 9e80889..cd079e6 100644 --- a/setup.py +++ b/setup.py @@ -1,13 +1,40 @@ -from setuptools import find_packages, setup -from Cython.Build import cythonize - -setup( - name='robots', - packages=find_packages(), - ext_modules=cythonize('robots/*.pyx'), - install_requires=[ - 'flask', - 'blessings', - 'cython', - ], -) +#!/usr/bin/env python +# Install dependencies from a "[metadata] setup-requires = ..." section in +# setup.cfg, then run real-setup.py. +# From https://bitbucket.org/dholth/setup-requires + +import sys, os, subprocess, codecs, pkg_resources + +sys.path[0:0] = ['setup-requires'] +pkg_resources.working_set.add_entry('setup-requires') + +try: + import configparser +except: + import ConfigParser as configparser + +def get_requirements(): + if not os.path.exists('setup.cfg'): return + config = configparser.ConfigParser() + config.readfp(codecs.open('setup.cfg', encoding='utf-8')) + setup_requires = config.get('metadata', 'setup-requires') + specifiers = [line.strip() for line in setup_requires.splitlines()] + for specifier in specifiers: + try: + pkg_resources.require(specifier) + except pkg_resources.DistributionNotFound: + yield specifier + +try: + to_install = list(get_requirements()) + if to_install: + subprocess.call([sys.executable, "-m", "pip", "install", + "-t", "setup-requires"] + to_install) +except (configparser.NoSectionError, configparser.NoOptionError): + pass + +# Run real-setup.py +exec(compile(open("real-setup.py").read().replace('\\r\\n', '\\n'), + __file__, + 'exec')) + -- cgit v1.2.3