|
16 | 16 |
|
17 | 17 | """ |
18 | 18 |
|
| 19 | +MAJOR = 0 |
| 20 | +MINOR = 6 |
| 21 | +MICRO = 2 |
| 22 | +ISRELEASED = True |
19 | 23 | DISTNAME = 'control' |
20 | 24 | DESCRIPTION = 'Python control systems library' |
21 | 25 | LONG_DESCRIPTION = descr |
|
26 | 30 | URL = 'http://python-control.sourceforge.net' |
27 | 31 | LICENSE = 'BSD' |
28 | 32 | DOWNLOAD_URL = URL |
29 | | -VERSION = '0.6e' |
30 | 33 | PACKAGE_NAME = 'control' |
31 | 34 | EXTRA_INFO = dict( |
32 | 35 | install_requires=['scipy', 'matplotlib'], |
33 | 36 | tests_require=['scipy', 'matplotlib', 'nose'] |
34 | 37 | ) |
35 | 38 |
|
| 39 | +VERSION = '%d.%d.%d' % (MAJOR, MINOR, MICRO) |
| 40 | + |
| 41 | +import os |
| 42 | +import sys |
| 43 | +import subprocess |
| 44 | + |
| 45 | + |
| 46 | +from setuptools import setup, find_packages |
| 47 | + |
36 | 48 | CLASSIFIERS = """\ |
37 | 49 | Development Status :: 3 - Alpha |
38 | 50 | Intended Audience :: Science/Research |
|
48 | 60 | Operating System :: MacOS |
49 | 61 | """ |
50 | 62 |
|
51 | | -import os |
52 | | -import sys |
53 | | -import subprocess |
54 | 63 |
|
55 | | -import setuptools |
56 | | -from numpy.distutils.core import setup |
57 | | - |
58 | | -def configuration(parent_package='', top_path=None, package_name=DISTNAME): |
59 | | - if os.path.exists('MANIFEST'): os.remove('MANIFEST') |
60 | | - |
61 | | - from numpy.distutils.misc_util import Configuration |
62 | | - config = Configuration(None, parent_package, top_path) |
63 | | - |
64 | | - # Avoid non-useful msg: "Ignoring attempt to set 'name' (from ... " |
65 | | - config.set_options(ignore_setup_xxx_py=True, |
66 | | - assume_default_configuration=True, |
67 | | - delegate_options_to_subpackages=True, |
68 | | - quiet=True) |
69 | | - |
70 | | - config.add_subpackage(PACKAGE_NAME) |
71 | | - return config |
72 | | - |
73 | | -def get_version(): |
74 | | - """Obtain the version number""" |
75 | | - import imp |
76 | | - mod = imp.load_source('version', os.path.join(PACKAGE_NAME, 'version.py')) |
77 | | - return mod.__version__ |
78 | | - |
79 | | -# Documentation building command |
80 | | -try: |
81 | | - from sphinx.setup_command import BuildDoc as SphinxBuildDoc |
82 | | - class BuildDoc(SphinxBuildDoc): |
83 | | - """Run in-place build before Sphinx doc build""" |
84 | | - def run(self): |
85 | | - ret = subprocess.call([sys.executable, sys.argv[0], 'build_ext', '-i']) |
86 | | - if ret != 0: |
87 | | - raise RuntimeError("Building Scipy failed!") |
88 | | - SphinxBuildDoc.run(self) |
89 | | - cmdclass = {'build_sphinx': BuildDoc} |
90 | | -except ImportError: |
91 | | - cmdclass = {} |
| 64 | +# Return the git revision as a string |
| 65 | +def git_version(): |
| 66 | + def _minimal_ext_cmd(cmd): |
| 67 | + # construct minimal environment |
| 68 | + env = {} |
| 69 | + for k in ['SYSTEMROOT', 'PATH']: |
| 70 | + v = os.environ.get(k) |
| 71 | + if v is not None: |
| 72 | + env[k] = v |
| 73 | + # LANGUAGE is used on win32 |
| 74 | + env['LANGUAGE'] = 'C' |
| 75 | + env['LANG'] = 'C' |
| 76 | + env['LC_ALL'] = 'C' |
| 77 | + out = subprocess.Popen( |
| 78 | + cmd, |
| 79 | + stdout=subprocess.PIPE, |
| 80 | + env=env).communicate()[0] |
| 81 | + return out |
| 82 | + |
| 83 | + try: |
| 84 | + out = _minimal_ext_cmd(['git', 'rev-parse', 'HEAD']) |
| 85 | + GIT_REVISION = out.strip().decode('ascii') |
| 86 | + except OSError: |
| 87 | + GIT_REVISION = "Unknown" |
| 88 | + |
| 89 | + return GIT_REVISION |
| 90 | + |
| 91 | + |
| 92 | +def get_version_info(): |
| 93 | + # Adding the git rev number needs to be done inside write_version_py(), |
| 94 | + # otherwise the import of package.version messes up |
| 95 | + # the build under Python 3. |
| 96 | + FULLVERSION = VERSION |
| 97 | + if os.path.exists('.git'): |
| 98 | + GIT_REVISION = git_version() |
| 99 | + elif os.path.exists('control/version.py'): |
| 100 | + # must be a source distribution, use existing version file |
| 101 | + try: |
| 102 | + from control.version import git_revision as GIT_REVISION |
| 103 | + except ImportError: |
| 104 | + raise ImportError("Unable to import git_revision. Try removing " |
| 105 | + "control/version.py and the build directory " |
| 106 | + "before building.") |
| 107 | + else: |
| 108 | + GIT_REVISION = "Unknown" |
| 109 | + |
| 110 | + if not ISRELEASED: |
| 111 | + FULLVERSION += '.dev-' + GIT_REVISION[:7] |
| 112 | + |
| 113 | + return FULLVERSION, GIT_REVISION |
| 114 | + |
92 | 115 |
|
93 | 116 | def write_version_py(filename='control/version.py'): |
94 | | - template = """# THIS FILE IS GENERATED FROM THE CONTROL SETUP.PY |
95 | | -version='%s' |
| 117 | + cnt = """ |
| 118 | +# THIS FILE IS GENERATED FROM SETUP.PY |
| 119 | +short_version = '%(version)s' |
| 120 | +version = '%(version)s' |
| 121 | +full_version = '%(full_version)s' |
| 122 | +git_revision = '%(git_revision)s' |
| 123 | +release = %(isrelease)s |
| 124 | +
|
| 125 | +if not release: |
| 126 | + version = full_version |
96 | 127 | """ |
97 | | - cwd = os.path.dirname(__file__) |
98 | | - with open(os.path.join(cwd, filename), 'w') as vfile: |
99 | | - vfile.write(template % VERSION) |
| 128 | + FULLVERSION, GIT_REVISION = get_version_info() |
| 129 | + |
| 130 | + a = open(filename, 'w') |
| 131 | + try: |
| 132 | + a.write(cnt % {'version': VERSION, |
| 133 | + 'full_version': FULLVERSION, |
| 134 | + 'git_revision': GIT_REVISION, |
| 135 | + 'isrelease': str(ISRELEASED)}) |
| 136 | + finally: |
| 137 | + a.close() |
| 138 | + |
| 139 | + |
| 140 | +def setup_package(): |
| 141 | + src_path = os.path.dirname(os.path.abspath(sys.argv[0])) |
| 142 | + old_path = os.getcwd() |
| 143 | + os.chdir(src_path) |
| 144 | + sys.path.insert(0, src_path) |
100 | 145 |
|
101 | | -# Call the setup function |
102 | | -if __name__ == "__main__": |
| 146 | + # Rewrite the version file everytime |
103 | 147 | write_version_py() |
104 | 148 |
|
105 | | - setup(configuration=configuration, |
106 | | - name=DISTNAME, |
107 | | - author=AUTHOR, |
108 | | - author_email=AUTHOR_EMAIL, |
109 | | - maintainer=MAINTAINER, |
110 | | - maintainer_email=MAINTAINER_EMAIL, |
111 | | - description=DESCRIPTION, |
112 | | - license=LICENSE, |
113 | | - url=URL, |
114 | | - download_url=DOWNLOAD_URL, |
115 | | - long_description=LONG_DESCRIPTION, |
116 | | - include_package_data=True, |
117 | | - test_suite="nose.collector", |
118 | | - cmdclass=cmdclass, |
119 | | - version=VERSION, |
120 | | - classifiers=[a for a in CLASSIFIERS.split('\n') if a], |
121 | | - **EXTRA_INFO) |
| 149 | + metadata = dict( |
| 150 | + name=DISTNAME, |
| 151 | + author=AUTHOR, |
| 152 | + author_email=AUTHOR_EMAIL, |
| 153 | + maintainer=MAINTAINER, |
| 154 | + maintainer_email=MAINTAINER_EMAIL, |
| 155 | + description=DESCRIPTION, |
| 156 | + license=LICENSE, |
| 157 | + url=URL, |
| 158 | + download_url=DOWNLOAD_URL, |
| 159 | + long_description=LONG_DESCRIPTION, |
| 160 | + classifiers=[_f for _f in CLASSIFIERS.split('\n') if _f], |
| 161 | + platforms=["Windows", "Linux", "Solaris", "Mac OS-X", "Unix"], |
| 162 | + install_requires=['numpy', 'scipy'], |
| 163 | + tests_require=['nose'], |
| 164 | + test_suite='nose.collector', |
| 165 | + packages=find_packages( |
| 166 | + exclude=['*.tests'] |
| 167 | + ), |
| 168 | + ) |
| 169 | + |
| 170 | + FULLVERSION, GIT_REVISION = get_version_info() |
| 171 | + metadata['version'] = FULLVERSION |
| 172 | + |
| 173 | + try: |
| 174 | + setup(**metadata) |
| 175 | + finally: |
| 176 | + del sys.path[0] |
| 177 | + os.chdir(old_path) |
| 178 | + return |
| 179 | + |
| 180 | +if __name__ == '__main__': |
| 181 | + setup_package() |
0 commit comments