-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
109 lines (93 loc) · 3.8 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import io
import os
import re
import shutil
import subprocess
import sys
import warnings
from setuptools import setup
pkg_name = 'pycompilation'
url = 'https://github.com/bjodah/' + pkg_name
license = 'BSD'
def _path_under_setup(*args):
return os.path.join(os.path.dirname(__file__), *args)
release_py_path = _path_under_setup(pkg_name, '_release.py')
_version_env_var = '%s_RELEASE_VERSION' % pkg_name.upper()
RELEASE_VERSION = os.environ.get(_version_env_var, '')
if len(RELEASE_VERSION) > 1 and RELEASE_VERSION[0] == 'v':
TAGGED_RELEASE = True
__version__ = RELEASE_VERSION[1:]
else:
TAGGED_RELEASE = False
# read __version__ attribute from _release.py:
with io.open(release_py_path, encoding='utf-8') as ifh:
exec(ifh.read())
if __version__.endswith('git'):
try:
_git_version = subprocess.check_output(
['git', 'describe', '--dirty']).rstrip().decode('utf-8').replace('-dirty', '.dirty')
except subprocess.CalledProcessError:
warnings.warn("A git-archive is being installed - version information incomplete.")
else:
if 'develop' not in sys.argv:
warnings.warn("Using git to derive version: dev-branches may compete.")
_ver_tmplt = r'\1.post\2' if os.environ.get('CONDA_BUILD', '0') == '1' else r'\1.post\2+\3'
__version__ = re.sub(r'v([0-9.]+)-(\d+)-(\S+)', _ver_tmplt, _git_version) # .dev < '' < .post
tests = [
'pycompilation.tests',
]
classifiers = [
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"License :: OSI Approved :: BSD License",
"Operating System :: POSIX",
"Programming Language :: Python",
"Programming Language :: C",
"Programming Language :: C++",
"Programming Language :: Cython",
"Programming Language :: Fortran",
"Topic :: Software Development :: Code Generators",
"Topic :: Software Development :: Compilers",
"Topic :: Software Development :: Libraries :: Python Modules"
]
with io.open(_path_under_setup(pkg_name, '__init__.py'), 'rt', encoding='utf-8') as f:
short_description = f.read().split('"""')[1].split('\n')[1]
if not 10 < len(short_description) < 255:
warnings.warn("Short description from __init__.py proably not read correctly.")
with io.open(_path_under_setup('README.rst'), encoding='utf-8') as ifh:
long_description = ifh.read()
if not len(long_description) > 100:
warnings.warn("Long description from README.rst probably not read correctly.")
with io.open(_path_under_setup('AUTHORS'), 'rt', encoding='utf-8') as ifh:
_author, _author_email = ifh.readline().split('<')
setup_kwargs = dict(
name=pkg_name,
version=__version__, # from release_py_path
description=short_description,
long_description=long_description,
author=_author.strip(),
author_email=_author_email.split('>')[0].strip(),
url=url,
license=license,
packages=[pkg_name] + tests,
classifiers=classifiers,
extras_require={
'all': ['cython', 'appdirs', 'argh', 'joblib', 'pytest', 'numpy',
'Sphinx', 'sphinx_rtd_theme', 'numpydoc', 'pytest-cov', 'pytest-flakes', 'pytest-pep8']
}
)
if __name__ == '__main__':
try:
if TAGGED_RELEASE:
# Same commit should generate different sdist
# depending on tagged version (set ${pkg_name}_RELEASE_VERSION)
# this will ensure source distributions contain the correct version
shutil.move(release_py_path, release_py_path+'__temp__')
with open(release_py_path, 'wt') as ofh:
ofh.write("__version__ = '{}'\n".format(__version__))
setup(**setup_kwargs)
finally:
if TAGGED_RELEASE:
shutil.move(release_py_path+'__temp__', release_py_path)