Skip to content

Commit f6a2789

Browse files
committed
pypi support.
1 parent 34c31a4 commit f6a2789

17 files changed

Lines changed: 1330 additions & 636 deletions

‎setup.py‎

Lines changed: 231 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,237 @@
11
#!/usr/bin/env python
2-
#
3-
# setup.py
4-
#
5-
# Copyright 2010 Enrico Avventi <avventi@kth.se>
6-
#
7-
# This program is free software; you can redistribute it and/or modify
8-
# it under the terms of the GNU General Public License version 2 as
9-
# published by the Free Software Foundation.
10-
#
11-
# This program is distributed in the hope that it will be useful,
12-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14-
# GNU General Public License for more details.
15-
#
16-
# You should have received a copy of the GNU General Public License
17-
# along with this program; if not, write to the Free Software
18-
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19-
# MA 02110-1301, USA.
20-
21-
# Modification RvP: for Windows, select liblapack and libblas
22-
23-
from glob import glob
2+
"""Slycot: a wrapper for the SLICOT control and systems library
3+
4+
Slycot wraps the SLICOT library which is used for control and systems analysis.
5+
6+
"""
7+
from __future__ import division, print_function
8+
9+
DOCLINES = __doc__.split("\n")
10+
2411
import os
2512
import sys
13+
import subprocess
2614

27-
if __name__ == '__main__':
28-
from numpy.distutils.core import setup,Extension
29-
if sys.platform == 'win32':
30-
liblist = ['liblapack', 'libblas']
15+
16+
if sys.version_info[:2] < (2, 6) or (3, 0) <= sys.version_info[0:2] < (3, 2):
17+
raise RuntimeError("Python version 2.6, 2.7 or >= 3.2 required.")
18+
19+
if sys.version_info[0] >= 3:
20+
import builtins
21+
else:
22+
import __builtin__ as builtins
23+
24+
25+
CLASSIFIERS = """\
26+
Development Status :: 3 - Alpha
27+
Intended Audience :: Science/Research
28+
Intended Audience :: Developers
29+
License :: OSI Approved
30+
Programming Language :: C
31+
Programming Language :: Python
32+
Programming Language :: Python :: 3
33+
Topic :: Software Development
34+
Topic :: Scientific/Engineering
35+
Operating System :: Microsoft :: Windows
36+
Operating System :: POSIX
37+
Operating System :: Unix
38+
Operating System :: MacOS
39+
"""
40+
41+
MAJOR = 0
42+
MINOR = 1
43+
MICRO = 1
44+
ISRELEASED = True
45+
VERSION = '%d.%d.%d' % (MAJOR, MINOR, MICRO)
46+
47+
48+
# Return the git revision as a string
49+
def git_version():
50+
def _minimal_ext_cmd(cmd):
51+
# construct minimal environment
52+
env = {}
53+
for k in ['SYSTEMROOT', 'PATH']:
54+
v = os.environ.get(k)
55+
if v is not None:
56+
env[k] = v
57+
# LANGUAGE is used on win32
58+
env['LANGUAGE'] = 'C'
59+
env['LANG'] = 'C'
60+
env['LC_ALL'] = 'C'
61+
out = subprocess.Popen(
62+
cmd,
63+
stdout=subprocess.PIPE,
64+
env=env).communicate()[0]
65+
return out
66+
67+
try:
68+
out = _minimal_ext_cmd(['git', 'rev-parse', 'HEAD'])
69+
GIT_REVISION = out.strip().decode('ascii')
70+
except OSError:
71+
GIT_REVISION = "Unknown"
72+
73+
return GIT_REVISION
74+
75+
# BEFORE importing distutils, remove MANIFEST. distutils doesn't properly
76+
# update it when the contents of directories change.
77+
if os.path.exists('MANIFEST'):
78+
os.remove('MANIFEST')
79+
80+
# This is a bit hackish: we are setting a global variable so that the main
81+
# slycot __init__ can detect if it is being loaded by the setup routine, to
82+
# avoid attempting to load components that aren't built yet. While ugly, it's
83+
# a lot more robust than what was previously being used.
84+
builtins.__SLYCOT_SETUP__ = True
85+
86+
87+
def get_version_info():
88+
# Adding the git rev number needs to be done inside write_version_py(),
89+
# otherwise the import of slycot.version messes up
90+
# the build under Python 3.
91+
FULLVERSION = VERSION
92+
if os.path.exists('.git'):
93+
GIT_REVISION = git_version()
94+
elif os.path.exists('slycot/version.py'):
95+
# must be a source distribution, use existing version file
96+
try:
97+
from slycot.version import git_revision as GIT_REVISION
98+
except ImportError:
99+
raise ImportError("Unable to import git_revision. Try removing "
100+
"slycot/version.py and the build directory "
101+
"before building.")
102+
else:
103+
GIT_REVISION = "Unknown"
104+
105+
if not ISRELEASED:
106+
FULLVERSION += '.dev-' + GIT_REVISION[:7]
107+
108+
return FULLVERSION, GIT_REVISION
109+
110+
111+
def write_version_py(filename='slycot/version.py'):
112+
cnt = """
113+
# THIS FILE IS GENERATED FROM SLYCOT SETUP.PY
114+
short_version = '%(version)s'
115+
version = '%(version)s'
116+
full_version = '%(full_version)s'
117+
git_revision = '%(git_revision)s'
118+
release = %(isrelease)s
119+
120+
if not release:
121+
version = full_version
122+
"""
123+
FULLVERSION, GIT_REVISION = get_version_info()
124+
125+
a = open(filename, 'w')
126+
try:
127+
a.write(cnt % {'version': VERSION,
128+
'full_version': FULLVERSION,
129+
'git_revision': GIT_REVISION,
130+
'isrelease': str(ISRELEASED)})
131+
finally:
132+
a.close()
133+
134+
135+
def configuration(parent_package='', top_path=None):
136+
from numpy.distutils.misc_util import Configuration
137+
config = Configuration(None, parent_package, top_path)
138+
config.set_options(ignore_setup_xxx_py=True,
139+
assume_default_configuration=True,
140+
delegate_options_to_subpackages=True,
141+
quiet=True)
142+
config.add_subpackage('slycot')
143+
config.get_version('slycot/version.py') # sets config.version
144+
return config
145+
146+
147+
def check_submodules():
148+
""" verify that the submodules are checked out and clean
149+
use `git submodule update --init`; on failure
150+
"""
151+
if not os.path.exists('.git'):
152+
return
153+
with open('.gitmodules') as f:
154+
for l in f:
155+
if 'path' in l:
156+
p = l.split('=')[-1].strip()
157+
if not os.path.exists(p):
158+
raise ValueError('Submodule %s missing' % p)
159+
160+
proc = subprocess.Popen(['git', 'submodule', 'status'],
161+
stdout=subprocess.PIPE)
162+
status, _ = proc.communicate()
163+
status = status.decode("ascii", "replace")
164+
for line in status.splitlines():
165+
if line.startswith('-') or line.startswith('+'):
166+
raise ValueError('Submodule not clean: %s' % line)
167+
168+
from distutils.command.sdist import sdist
169+
170+
171+
class sdist_checked(sdist):
172+
""" check submodules on sdist to prevent incomplete tarballs """
173+
def run(self):
174+
# slycot had no submodules currently
175+
# check_submodules()
176+
sdist.run(self)
177+
178+
179+
def setup_package():
180+
src_path = os.path.dirname(os.path.abspath(sys.argv[0]))
181+
old_path = os.getcwd()
182+
os.chdir(src_path)
183+
sys.path.insert(0, src_path)
184+
185+
# Rewrite the version file everytime
186+
write_version_py()
187+
188+
metadata = dict(
189+
name='slycot',
190+
maintainer="James Goppert",
191+
maintainer_email="james.goppert@gmail.com",
192+
description=DOCLINES[0],
193+
long_description="\n".join(DOCLINES[2:]),
194+
url='https://github.com/jgoppert/Slycot',
195+
author='Enrico Avventi',
196+
author_email='james.goppert@gmail.com',
197+
download_url='https://github.com/jgoppert/Slycot',
198+
license='BSD',
199+
classifiers=[_f for _f in CLASSIFIERS.split('\n') if _f],
200+
platforms=["Windows", "Linux", "Solaris", "Mac OS-X", "Unix"],
201+
cmdclass={"sdist": sdist_checked},
202+
)
203+
204+
# Run build
205+
if len(sys.argv) >= 2 and \
206+
('--help' in sys.argv[1:] or
207+
sys.argv[1] in ('--help-commands', 'egg_info', '--version',
208+
'clean')):
209+
# Use setuptools for these commands (they don't work well or at all
210+
# with distutils). For normal builds use distutils.
211+
try:
212+
from setuptools import setup
213+
except ImportError:
214+
from distutils.core import setup
215+
216+
FULLVERSION, GIT_REVISION = get_version_info()
217+
metadata['version'] = FULLVERSION
218+
elif len(sys.argv) >= 2 and sys.argv[1] == 'bdist_wheel':
219+
# bdist_wheel needs setuptools
220+
import setuptools
221+
setuptools # reference once for pyflakes
222+
from numpy.distutils.core import setup
223+
metadata['configuration'] = configuration
31224
else:
32-
liblist = ['lapack']
33-
34-
wrappers = Extension('_wrapper',
35-
libraries=liblist,
36-
sources=['slycot/src/_wrapper.pyf'] +
37-
glob(os.path.join('slycot','src','*.f')))
38-
setup(name = 'Slycot',
39-
author = 'Enrico Avventi',
40-
license = 'GPLv2',
41-
version = '0.1.0',
42-
description = 'A wrapper for the Slicot library',
43-
packages = ['slycot'],
44-
py_modules = ['slycot/examples'],
45-
ext_package = 'slycot',
46-
ext_modules = [wrappers])
225+
from numpy.distutils.core import setup
226+
metadata['configuration'] = configuration
227+
228+
try:
229+
setup(**metadata)
230+
finally:
231+
del sys.path[0]
232+
os.chdir(old_path)
233+
return
47234

235+
236+
if __name__ == '__main__':
237+
setup_package()

0 commit comments

Comments
 (0)