-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathsetup.py
108 lines (91 loc) · 3.67 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
import os, subprocess, sys
from importlib.machinery import SourceFileLoader
from setuptools import setup, Extension
from setuptools.command.bdist_wheel import bdist_wheel
from setuptools.command.build_ext import build_ext
from setuptools.command.egg_info import egg_info
from setuptools.command.install_lib import install_lib
from setuptools.command.install_scripts import install_scripts
from twine.commands.check import check
# use importlib to avoid import so file
_version = SourceFileLoader('version', 'tensornet/version.py').load_module()
class DistCfg():
VER = _version.VERSION
EXT_NAME = 'tensornet.core._pywrap_tn'
PLAT = "manylinux2010_x86_64"
BUILD_PRESET = "release"
BUILD_DIR = "build/release"
class CMakeBuild(build_ext):
def build_extensions(self):
subprocess.check_call([ 'cmake', '--workflow', '--preset', DistCfg.BUILD_PRESET, '--fresh' ])
# Make sure CMake generated all the appropriate extensions
for ext in self.extensions:
ext = self.get_ext_fullpath(ext.name)
if not os.path.exists(ext):
raise RuntimeError(f'Failed to build extension: {ext}')
class CMakeInstall(install_lib):
def install(self):
subprocess.check_call([
'cmake', '--build',
'--preset', DistCfg.BUILD_PRESET, '--target', 'install',
'--', "SKIP_RUN_TESTS=1" ])
class NoopInstallScript(install_scripts):
def run(self):
pass
class EggInfo(egg_info):
def _get_egg_basename(self, py_version=sys.version_info.major, platform=None):
if py_version:
return super()._get_egg_basename("3.5", platform)
else:
return super()._get_egg_basename(py_version, platform)
class BdistWheelWithCheck(bdist_wheel):
def get_tag(self):
_, _, plat_tag = super().get_tag()
return "cp35", "abi3", plat_tag
def run(self):
# from cmake 3.29, pass install prefix via CMAKE_INSTALL_PREFIX env
os.putenv("CMAKE_INSTALL_PREFIX", os.path.abspath(self.bdist_dir))
# build and create the whl package
super().run()
# twine check
impl_tag, abi_tag, plat_tag = self.get_tag()
whl_file = f"{self.wheel_dist_name}-{impl_tag}-{abi_tag}-{plat_tag}.whl"
check([os.path.join(self.dist_dir, whl_file)], strict=True)
setup(
name = 'qihoo-tensornet',
version = DistCfg.VER,
description = 'tensornet',
long_description = open('README.md').read(),
long_description_content_type = 'text/markdown',
author = 'jiangxinglei',
author_email = '[email protected]',
url = 'https://github.com/Qihoo360/tensornet',
python_requires = '>=3.6, <3.9',
classifiers = [
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'License :: OSI Approved :: Apache Software License',
'Programming Language :: Python :: 3 :: Only',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
],
platforms = [DistCfg.PLAT],
cmdclass = {
"bdist_wheel": BdistWheelWithCheck,
'build_ext': CMakeBuild,
'egg_info': EggInfo,
'install_lib': CMakeInstall,
'install_scripts': NoopInstallScript ,
},
# build ext with cmake, so sources are not listed here
ext_modules=[Extension(DistCfg.EXT_NAME, [])],
# force skip the build-py step
packages=[],
options = {
# set build_lib for checking the existence of built modules
"build_ext": { "build_lib": DistCfg.BUILD_DIR },
'bdist_wheel': { "plat_name": DistCfg.PLAT },
},
)