-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsetup.py
More file actions
189 lines (166 loc) · 6.21 KB
/
setup.py
File metadata and controls
189 lines (166 loc) · 6.21 KB
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# -*- coding: utf-8 -*-
# @Time : 2021/01/05 22:41:59
# @Author : ddvv
# @Site : https://ddvvmmzz.github.io
# @File : setup.py
# @Software: Visual Studio Code
import platform
import glob
import os
import subprocess
import sys
import setuptools
from setuptools import Distribution as _Distribution, setup
import errno
try:
from setuptools.command.build_clib import build_clib as _build_clib
except ImportError:
# We ignore type checking because mypy shows an import error
from distutils.command.build_clib import build_clib as _build_clib # type: ignore
base_dir = os.path.dirname(__file__)
print('base dir is: %s' % base_dir)
SYSTEM_VER = platform.system().lower()
ENGINE_SUFFIX = {
"windows": "dll",
"darwin": "dylib",
"linux": "so"
}
use_system_lib = False
class BuildClib(_build_clib):
def build_libraries(self, libraries):
raise Exception("build_libraries")
def check_library_list(self, libraries):
raise Exception("check_library_list")
def get_source_files(self):
files = glob.glob(os.path.relpath("python_mmdt/mmdt-lib/*"))
return files
def run(self):
try:
cmake_config = ''
rm_cmd = 'rm'
mv_cmd = 'mv'
rm_param = '-fr'
if SYSTEM_VER == 'windows':
print("try to use Mingwin compile. ")
cmake_config = '-G"Unix Makefiles"'
rm_cmd = 'powershell.exe rm'
mv_cmd = 'powershell.exe mv'
rm_param = '-recurse'
build_temp = os.path.abspath(self.build_temp)
if os.path.exists(build_temp):
cmds = list()
cmds.extend(rm_cmd.split(' '))
cmds.append(rm_param)
cmds.append(build_temp)
returncode = subprocess.call(cmds)
print('temp build dir is: %s' % build_temp)
os.makedirs(build_temp)
returncode = subprocess.call(
"(cd {build_temp} && cmake {cmake_config} ../lib/python_mmdt/mmdt-lib)".format(
build_temp=build_temp, cmake_config=cmake_config),
shell=True
)
if returncode != 0:
# try harder
returncode = subprocess.call(
"(cd {build_temp} && cmake {cmake_config} ../lib/python_mmdt/mmdt-lib)".format(
build_temp=build_temp, cmake_config=cmake_config),
shell=True
)
if returncode != 0:
sys.exit("Failed to cmake the project build.")
returncode = subprocess.call(
["make"],
cwd=build_temp
)
if returncode != 0:
sys.exit("Failed while building mmdt lib.")
# mv libcore
build_libcore = os.path.join(
build_temp, "libcore.{}".format(ENGINE_SUFFIX[SYSTEM_VER]))
install_libcore = os.path.join(
build_temp, '..', 'lib', 'python_mmdt', 'mmdt')
cmds = list()
cmds.extend(mv_cmd.split(' '))
cmds.append(build_libcore)
cmds.append(install_libcore)
returncode = subprocess.call(cmds)
if returncode != 0:
sys.exit("Failed while install mmdt lib.")
# remove build
cmds = list()
cmds.extend(rm_cmd.split(' '))
cmds.append(rm_param)
cmds.append(build_temp)
returncode = subprocess.call(cmds)
if returncode != 0:
sys.exit("Failed while remove mmdt build dir.")
# remove mmdt-lib
c_src_path = os.path.join(
build_temp, '..', 'lib', 'python_mmdt', 'mmdt-lib')
cmds = list()
cmds.extend(rm_cmd.split(' '))
cmds.append(rm_param)
cmds.append(c_src_path)
returncode = subprocess.call(cmds)
if returncode != 0:
sys.exit("Failed while remove c source build dir.")
except OSError as e:
if e.errno != errno.EEXIST:
raise
class Distribution(_Distribution):
def has_c_libraries(self):
return not use_system_lib
about = {}
with open(os.path.join(base_dir, "__about__.py")) as f:
exec(f.read(), about)
with open(os.path.join(base_dir, "README.md"), 'r', encoding='utf8') as f:
long_description = f.read()
setup(
name=about["__title__"],
version=about["__version__"],
description=about["__summary__"],
long_description=long_description,
long_description_content_type="text/markdown",
license=about["__license__"],
url=about["__uri__"],
author=about["__author__"],
author_email=about["__email__"],
classifiers=[
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: Implementation :: PyPy",
"Topic :: Software Development :: Libraries :: Python Modules",
],
entry_points={
"console_scripts": [
"mmdt-hash = python_mmdt.mmdt.run:mmdt_hash",
"mmdt-compare = python_mmdt.mmdt.run:mmdt_compare",
"mmdt-classify = python_mmdt.mmdt.run:mmdt_classfiy",
"mmdt-gen = python_mmdt.mmdt.run:mmdt_gen_sets",
"mmdt-filter = python_mmdt.mmdt.run:mmdt_filter_sets",
"mmdt-filter-simple = python_mmdt.mmdt.run:mmdt_filter_simple_sets",
"mmdt-std = python_mmdt.mmdt.run:mmdt_std",
"mmdt-copy = python_mmdt.mmdt.run:mmdt_copy_data",
"mmdt-scan-online = python_mmdt.mmdt.run:mmdt_scan_online",
"mmdt-feature-merge = python_mmdt.mmdt.run:mmdt_feature_merge",
]
},
python_requires='>=3.6',
keywords="mmdt",
packages=setuptools.find_packages(exclude=["tests"]),
include_package_data=True,
cmdclass={
"build_clib": BuildClib,
},
distclass=Distribution,
install_requires=[
"requests",
"numpy"
]
)