Skip to content

Commit 17716d7

Browse files
author
Ralf Gommers
committed
MAINT: setup.py improvements - allow some setuptools commands to work.
1 parent d47b6de commit 17716d7

File tree

1 file changed

+60
-42
lines changed

1 file changed

+60
-42
lines changed

setup.py

+60-42
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@
1818
DOCLINES = __doc__.split("\n")
1919

2020
import os
21-
import shutil
2221
import sys
23-
import re
2422
import subprocess
2523

24+
2625
if sys.version_info[:2] < (2, 6) or (3, 0) <= sys.version_info[0:2] < (3, 2):
2726
raise RuntimeError("Python version 2.6, 2.7 or >= 3.2 required.")
2827

@@ -31,6 +30,7 @@
3130
else:
3231
import __builtin__ as builtins
3332

33+
3434
CLASSIFIERS = """\
3535
Development Status :: 5 - Production/Stable
3636
Intended Audience :: Science/Research
@@ -47,24 +47,13 @@
4747
Operating System :: MacOS
4848
"""
4949

50-
NAME = 'numpy'
51-
MAINTAINER = "NumPy Developers"
52-
MAINTAINER_EMAIL = "[email protected]"
53-
DESCRIPTION = DOCLINES[0]
54-
LONG_DESCRIPTION = "\n".join(DOCLINES[2:])
55-
URL = "http://www.numpy.org"
56-
DOWNLOAD_URL = "http://sourceforge.net/projects/numpy/files/NumPy/"
57-
LICENSE = 'BSD'
58-
CLASSIFIERS = [_f for _f in CLASSIFIERS.split('\n') if _f]
59-
AUTHOR = "Travis E. Oliphant et al."
60-
AUTHOR_EMAIL = "[email protected]"
61-
PLATFORMS = ["Windows", "Linux", "Solaris", "Mac OS-X", "Unix"]
6250
MAJOR = 1
6351
MINOR = 9
6452
MICRO = 0
6553
ISRELEASED = False
6654
VERSION = '%d.%d.%d' % (MAJOR, MINOR, MICRO)
6755

56+
6857
# Return the git revision as a string
6958
def git_version():
7059
def _minimal_ext_cmd(cmd):
@@ -100,18 +89,7 @@ def _minimal_ext_cmd(cmd):
10089
builtins.__NUMPY_SETUP__ = True
10190

10291

103-
def write_version_py(filename='numpy/version.py'):
104-
cnt = """
105-
# THIS FILE IS GENERATED FROM NUMPY SETUP.PY
106-
short_version = '%(version)s'
107-
version = '%(version)s'
108-
full_version = '%(full_version)s'
109-
git_revision = '%(git_revision)s'
110-
release = %(isrelease)s
111-
112-
if not release:
113-
version = full_version
114-
"""
92+
def get_version_info():
11593
# Adding the git rev number needs to be done inside write_version_py(),
11694
# otherwise the import of numpy.version messes up the build under Python 3.
11795
FULLVERSION = VERSION
@@ -131,6 +109,23 @@ def write_version_py(filename='numpy/version.py'):
131109
if not ISRELEASED:
132110
FULLVERSION += '.dev-' + GIT_REVISION[:7]
133111

112+
return FULLVERSION, GIT_REVISION
113+
114+
115+
def write_version_py(filename='numpy/version.py'):
116+
cnt = """
117+
# THIS FILE IS GENERATED FROM NUMPY SETUP.PY
118+
short_version = '%(version)s'
119+
version = '%(version)s'
120+
full_version = '%(full_version)s'
121+
git_revision = '%(git_revision)s'
122+
release = %(isrelease)s
123+
124+
if not release:
125+
version = full_version
126+
"""
127+
FULLVERSION, GIT_REVISION = get_version_info()
128+
134129
a = open(filename, 'w')
135130
try:
136131
a.write(cnt % {'version': VERSION,
@@ -140,6 +135,7 @@ def write_version_py(filename='numpy/version.py'):
140135
finally:
141136
a.close()
142137

138+
143139
def configuration(parent_package='',top_path=None):
144140
from numpy.distutils.misc_util import Configuration
145141

@@ -155,8 +151,8 @@ def configuration(parent_package='',top_path=None):
155151

156152
return config
157153

158-
def setup_package():
159154

155+
def setup_package():
160156
src_path = os.path.dirname(os.path.abspath(sys.argv[0]))
161157
old_path = os.getcwd()
162158
os.chdir(src_path)
@@ -165,28 +161,50 @@ def setup_package():
165161
# Rewrite the version file everytime
166162
write_version_py()
167163

164+
metadata = dict(
165+
name = 'numpy',
166+
maintainer = "NumPy Developers",
167+
maintainer_email = "[email protected]",
168+
description = DOCLINES[0],
169+
long_description = "\n".join(DOCLINES[2:]),
170+
url = "http://www.numpy.org",
171+
author = "Travis E. Oliphant et al.",
172+
download_url = "http://sourceforge.net/projects/numpy/files/NumPy/",
173+
license = 'BSD',
174+
classifiers=[_f for _f in CLASSIFIERS.split('\n') if _f],
175+
platforms = ["Windows", "Linux", "Solaris", "Mac OS-X", "Unix"],
176+
test_suite='nose.collector',
177+
)
178+
168179
# Run build
169-
from numpy.distutils.core import setup
180+
if len(sys.argv) >= 2 and ('--help' in sys.argv[1:] or
181+
sys.argv[1] in ('--help-commands', 'egg_info', '--version',
182+
'clean')):
183+
# Use setuptools for these commands (they don't work well or at all
184+
# with distutils). For normal builds use distutils.
185+
try:
186+
from setuptools import setup
187+
except ImportError:
188+
from distutils.core import setup
189+
190+
FULLVERSION, GIT_REVISION = get_version_info()
191+
metadata['version'] = FULLVERSION
192+
elif len(sys.argv) >= 2 and sys.argv[1] == 'bdist_wheel':
193+
# bdist_wheel needs setuptools
194+
import setuptools
195+
from numpy.distutils.core import setup
196+
metadata['configuration'] = configuration
197+
else:
198+
from numpy.distutils.core import setup
199+
metadata['configuration'] = configuration
170200

171201
try:
172-
setup(
173-
name=NAME,
174-
maintainer=MAINTAINER,
175-
maintainer_email=MAINTAINER_EMAIL,
176-
description=DESCRIPTION,
177-
long_description=LONG_DESCRIPTION,
178-
url=URL,
179-
download_url=DOWNLOAD_URL,
180-
license=LICENSE,
181-
classifiers=CLASSIFIERS,
182-
author=AUTHOR,
183-
author_email=AUTHOR_EMAIL,
184-
platforms=PLATFORMS,
185-
configuration=configuration )
202+
setup(**metadata)
186203
finally:
187204
del sys.path[0]
188205
os.chdir(old_path)
189206
return
190207

208+
191209
if __name__ == '__main__':
192210
setup_package()

0 commit comments

Comments
 (0)