forked from vstconsulting/polemarch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
139 lines (111 loc) · 3.43 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import os
import sys
try:
from sphinx.setup_command import BuildDoc
import sphinx
has_sphinx = True
except ImportError:
has_sphinx = False
from setuptools import find_packages, setup
from setuptools.command.install import install
from setuptools.command.build_ext import build_ext as _build_ext
from setuptools.command.sdist import sdist as _sdist
from setuptools.extension import Extension
try:
from Cython.Distutils import build_ext as _build_ext
from Cython.Build import cythonize
except ImportError:
has_cython = False
else:
has_cython = True
# allow setup.py to be run from any path
os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir)))
RMF = os.path.join(os.path.dirname(__file__), 'README.rst')
with open(RMF) as readme:
README = readme.read()
def load_requirements(file_name):
with open(os.path.join(os.path.dirname(__file__), file_name)) as req_file:
return req_file.read().strip().split('\n')
REQUIRES = load_requirements('requirements.txt')
REQUIRES += load_requirements('requirements-doc.txt')
REQUIRES_git = load_requirements('requirements-git.txt')
if 'compile' in sys.argv:
use_cython = True
ext = ".py"
else:
use_cython = False
ext = '.c'
ext_list = [
"polemarch.api.v1.filters",
"polemarch.api.v1.serializers",
"polemarch.api.v1.views",
"polemarch.api.base",
"polemarch.api.handlers",
"polemarch.api.permissions",
"polemarch.api.routers",
"polemarch.api.urls",
"polemarch.main.models.base",
"polemarch.main.models.hosts",
"polemarch.main.models.projects",
"polemarch.main.models.tasks",
"polemarch.main.models.utils",
"polemarch.main.models.users",
"polemarch.main.models.vars",
"polemarch.main.tasks.tasks",
'polemarch.main.settings',
'polemarch.main.repo._base',
'polemarch.main.repo.manual',
'polemarch.main.repo.tar',
'polemarch.main.repo.vcs',
'polemarch.main.validators',
'polemarch.main.views',
'polemarch.main.context_processors',
]
if not os.path.exists(ext_list[0].replace(".", "/")+ext):
ext = ".py" if ext == ".c" else ".c"
extensions_dict = dict((
(exten, [exten.replace(".", "/")+ext]) for exten in ext_list
))
if 'develop' in sys.argv:
ext_modules = []
else:
ext_modules = list(Extension(m, f) for m, f in extensions_dict.items())
if use_cython and has_cython:
ext_modules = cythonize(ext_modules)
class PostInstallCommand(install):
"""Post-installation for installation mode."""
def run(self):
install.run(self)
class Compile(_sdist):
def __filter_files(self, files):
for _files in extensions_dict.values():
for file in _files:
if file in files:
files.remove(file)
return files
def make_release_tree(self, base_dir, files):
if use_cython:
files = self.__filter_files(files)
_sdist.make_release_tree(self, base_dir, files)
def run(self):
return _sdist.run(self)
cmdclass = {
'install': PostInstallCommand,
'compile': Compile,
'build_ext': _build_ext
}
if has_sphinx:
cmdclass['build_sphinx'] = BuildDoc
setup(
name='polemarch',
packages=find_packages(),
ext_modules=ext_modules,
include_package_data=True,
scripts=['polemarchctl'],
install_requires=[
"django>=1.11,<2.0",
] + REQUIRES,
dependency_links=[
] + REQUIRES_git,
cmdclass=cmdclass,
)