-
Notifications
You must be signed in to change notification settings - Fork 36
/
setup.py
141 lines (112 loc) · 4.21 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
140
141
#!/usr/bin/env python3
""" Neural Network Design & Deployment with Python
N2D2 is a Python package to use the N2D2 engine with a Python interface.
"""
DOCLINES = (__doc__ or '').split("\n")
import sys
import os
# Python supported version checks
if sys.version_info[:2] < (3, 7):
raise RuntimeError("Python version >= 3.7 required.")
CLASSIFIERS = """\
Development Status :: 5 - Production/Stable
Intended Audience :: Developers
Intended Audience :: Education
Intended Audience :: Science/Research
License :: OSI Approved :: CEA CNRS Inria Logiciel Libre License, version 2.1 (CeCILL-2.1)
Programming Language :: C++
Programming Language :: Python
Programming Language :: Python :: 3
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3 :: Only
Programming Language :: Python :: Implementation :: CPython
Topic :: Scientific/Engineering
Topic :: Scientific/Engineering :: Artificial Intelligence
Topic :: Software Development
Topic :: Software Development :: Libraries
Topic :: Software Development :: Libraries :: Python Modules
Typing :: Typed
Operating System :: POSIX
"""
import shutil
import pathlib
import subprocess
import multiprocessing
from math import ceil
from setuptools import setup, Extension
from setuptools import find_packages
from setuptools.command.build_ext import build_ext
def get_n2d2_version() -> str:
n2d2_root = pathlib.Path().absolute()
version = open(n2d2_root / "version.txt", "r").read().strip()
return version
class CMakeExtension(Extension):
def __init__(self, name):
super().__init__(name, sources=[])
class CMakeBuild(build_ext):
def run(self):
try:
out = subprocess.check_output(['cmake', '--version'])
except OSError:
raise RuntimeError("CMake must be installed to build N2D2")
# This lists the number of processors available on the machine
# The compilation will use half of them
max_jobs = str(ceil(multiprocessing.cpu_count() / 2))
cwd = pathlib.Path().absolute()
build_temp = cwd / "build"
if not build_temp.exists():
build_temp.mkdir(parents=True, exist_ok=True)
build_lib = pathlib.Path(self.build_lib)
if not build_lib.exists():
build_lib.mkdir(parents=True, exist_ok=True)
os.chdir(str(build_temp))
self.spawn(['cmake', str(cwd)])
if not self.dry_run:
self.spawn(['make', '-j', max_jobs])
os.chdir(str(cwd))
ext_lib = build_temp / "lib"
# Copy all shared object files from build_temp/lib to build_lib
for root, dirs, files in os.walk(ext_lib.absolute()):
for file in files:
if file.endswith('.so'):
currentFile=os.path.join(root, file)
shutil.copy(currentFile, str(build_lib.absolute()))
# Copy export folder in "n2d2"
shutil.copytree(
str(cwd / "export"),
str(build_lib.absolute() / "n2d2" / "export")
)
if __name__ == '__main__':
n2d2_packages = find_packages(where="./python")
setup(
name='n2d2',
version=get_n2d2_version(),
url='https://github.com/CEA-LIST/N2D2',
license='CECILL-2.1',
author='N2D2 Team',
author_email='[email protected]',
python_requires='>=3.7',
description=DOCLINES[0],
long_description_content_type="text/markdown",
long_description="\n".join(DOCLINES[2:]),
keywords=['n2d2', 'machine', 'learning'],
project_urls={
"Bug Tracker": "https://github.com/CEA-LIST/N2D2/issues",
"Documentation": "https://cea-list.github.io/N2D2-docs/",
"Source Code": "https://github.com/CEA-LIST/N2D2",
},
classifiers=[c for c in CLASSIFIERS.split('\n') if c],
platforms=["Linux"],
packages=n2d2_packages,
package_dir={
"n2d2": "python/n2d2",
"pytorch_to_n2d2": "python/pytorch_to_n2d2",
"keras_to_n2d2": "python/keras_to_n2d2",
},
ext_modules=[CMakeExtension('N2D2')],
cmdclass={
'build_ext': CMakeBuild,
},
)