Skip to content

Commit de69313

Browse files
committed
Fix setup.py to work with runtests.py
Previously, at least on my machine (Mac with Anaconda), running runtests.py gave a build error when setup.py tried to build a local copy of the package. It turns out this was because we were importing setuptools, which caused problems, because the rest of the setup.py script (which was taken from numpy) assumes we are using the numpy version of setup(), in numpy.distutils.core This commit removes the import of setuptools and makes setup.py almost identical to that used in numpy.
1 parent 6fcae2d commit de69313

File tree

1 file changed

+35
-7
lines changed

1 file changed

+35
-7
lines changed

setup.py

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@
4343
import subprocess
4444

4545

46-
from setuptools import setup, find_packages
47-
4846
CLASSIFIERS = """\
4947
Development Status :: 3 - Alpha
5048
Intended Audience :: Science/Research
@@ -136,6 +134,20 @@ def write_version_py(filename='control/version.py'):
136134
finally:
137135
a.close()
138136

137+
def configuration(parent_package='',top_path=None):
138+
from numpy.distutils.misc_util import Configuration
139+
140+
config = Configuration(None, parent_package, top_path)
141+
config.set_options(ignore_setup_xxx_py=True,
142+
assume_default_configuration=True,
143+
delegate_options_to_subpackages=True,
144+
quiet=True)
145+
146+
config.add_subpackage(PACKAGE_NAME)
147+
148+
config.get_version(PACKAGE_NAME + '/version.py') # sets config.version
149+
150+
return config
139151

140152
def setup_package():
141153
src_path = os.path.dirname(os.path.abspath(sys.argv[0]))
@@ -162,13 +174,29 @@ def setup_package():
162174
install_requires=['numpy', 'scipy'],
163175
tests_require=['nose'],
164176
test_suite='nose.collector',
165-
packages=find_packages(
166-
exclude=['*.tests']
167-
),
177+
packages=[PACKAGE_NAME],
168178
)
169179

170-
FULLVERSION, GIT_REVISION = get_version_info()
171-
metadata['version'] = FULLVERSION
180+
# Run build
181+
if len(sys.argv) >= 2 and ('--help' in sys.argv[1:] or
182+
sys.argv[1] in ('--help-commands', 'egg_info', '--version',
183+
'clean')):
184+
# Use setuptools for these commands (they don't work well or at all
185+
# with distutils). For normal builds use distutils.
186+
try:
187+
from setuptools import setup
188+
except ImportError:
189+
from distutils.core import setup
190+
191+
FULLVERSION, GIT_REVISION = get_version_info()
192+
metadata['version'] = FULLVERSION
193+
else:
194+
if len(sys.argv) >= 2 and sys.argv[1] == 'bdist_wheel':
195+
# bdist_wheel needs setuptools
196+
import setuptools
197+
from numpy.distutils.core import setup
198+
cwd = os.path.abspath(os.path.dirname(__file__))
199+
metadata['configuration'] = configuration
172200

173201
try:
174202
setup(**metadata)

0 commit comments

Comments
 (0)