1
1
import os
2
+ import glob
2
3
import re
3
4
import subprocess
4
5
import sys
5
- from pathlib import Path
6
6
7
- from setuptools import Extension , setup , find_packages
8
- from setuptools . command . build_ext import build_ext
7
+ from setuptools import setup , find_packages
8
+ from pybind11 . setup_helpers import Pybind11Extension , build_ext
9
9
10
- # Convert distutils Windows platform specifiers to CMake -A arguments
11
- PLAT_TO_CMAKE = {
12
- "win32" : "Win32" ,
13
- "win-amd64" : "x64" ,
14
- "win-arm32" : "ARM" ,
15
- "win-arm64" : "ARM64" ,
16
- }
17
-
18
-
19
- # A CMakeExtension needs a sourcedir instead of a file list.
20
- # The name must be the _single_ output extension from the CMake build.
21
- # If you need multiple extensions, see scikit-build.
22
- class CMakeExtension (Extension ):
23
- def __init__ (self , name : str , sourcedir : str = "" ) -> None :
24
- super ().__init__ (name , sources = [])
25
- self .sourcedir = os .fspath (Path (sourcedir ).resolve ())
26
-
27
-
28
- class CMakeBuild (build_ext ):
29
- def build_extension (self , ext : CMakeExtension ) -> None :
30
- # Must be in this form due to bug in .resolve() only fixed in Python 3.10+
31
- ext_fullpath = Path .cwd () / self .get_ext_fullpath (ext .name )
32
- extdir = ext_fullpath .parent .resolve ()
33
-
34
- # Using this requires trailing slash for auto-detection & inclusion of
35
- # auxiliary "native" libs
36
-
37
- debug = int (os .environ .get ("DEBUG" , 0 )) if self .debug is None else self .debug
38
- cfg = "Debug" if debug else "Release"
39
-
40
- # CMake lets you override the generator - we need to check this.
41
- # Can be set with Conda-Build, for example.
42
- cmake_generator = os .environ .get ("CMAKE_GENERATOR" , "" )
43
-
44
- # Set Python_EXECUTABLE instead if you use PYBIND11_FINDPYTHON
45
- # EXAMPLE_VERSION_INFO shows you how to pass a value into the C++ code
46
- # from Python.
47
- cmake_args = [
48
- f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={ extdir } { os .sep } " ,
49
- f"-DPYTHON_EXECUTABLE={ sys .executable } " ,
50
- f"-DCMAKE_BUILD_TYPE={ cfg } " , # not used on MSVC, but no harm
51
- ]
52
- build_args = []
53
- # Adding CMake arguments set as environment variable
54
- # (needed e.g. to build for ARM OSx on conda-forge)
55
- if "CMAKE_ARGS" in os .environ :
56
- cmake_args += [item for item in os .environ ["CMAKE_ARGS" ].split (" " ) if item ]
57
-
58
- # In this example, we pass in the version to C++. You might not need to.
59
- cmake_args += [f"-DEXAMPLE_VERSION_INFO={ self .distribution .get_version ()} " ]
60
-
61
- if self .compiler .compiler_type != "msvc" :
62
- # Using Ninja-build since it a) is available as a wheel and b)
63
- # multithreads automatically. MSVC would require all variables be
64
- # exported for Ninja to pick it up, which is a little tricky to do.
65
- # Users can override the generator with CMAKE_GENERATOR in CMake
66
- # 3.15+.
67
- if not cmake_generator or cmake_generator == "Ninja" :
68
- try :
69
- import ninja
70
-
71
- ninja_executable_path = Path (ninja .BIN_DIR ) / "ninja"
72
- cmake_args += [
73
- "-GNinja" ,
74
- f"-DCMAKE_MAKE_PROGRAM:FILEPATH={ ninja_executable_path } " ,
75
- ]
76
- except ImportError :
77
- pass
78
-
79
- else :
80
- # Single config generators are handled "normally"
81
- single_config = any (x in cmake_generator for x in {"NMake" , "Ninja" })
82
-
83
- # CMake allows an arch-in-generator style for backward compatibility
84
- contains_arch = any (x in cmake_generator for x in {"ARM" , "Win64" })
85
-
86
- # Specify the arch if using MSVC generator, but only if it doesn't
87
- # contain a backward-compatibility arch spec already in the
88
- # generator name.
89
- if not single_config and not contains_arch :
90
- cmake_args += ["-A" , PLAT_TO_CMAKE [self .plat_name ]]
91
-
92
- # Multi-config generators have a different way to specify configs
93
- if not single_config :
94
- cmake_args += [
95
- f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{ cfg .upper ()} ={ extdir } "
96
- ]
97
- build_args += ["--config" , cfg ]
98
-
99
- if sys .platform .startswith ("darwin" ):
100
- # Cross-compile support for macOS - respect ARCHFLAGS if set
101
- archs = re .findall (r"-arch (\S+)" , os .environ .get ("ARCHFLAGS" , "" ))
102
- if archs :
103
- cmake_args += ["-DCMAKE_OSX_ARCHITECTURES={}" .format (";" .join (archs ))]
104
-
105
- # Set CMAKE_BUILD_PARALLEL_LEVEL to control the parallel build level
106
- # across all generators.
107
- if "CMAKE_BUILD_PARALLEL_LEVEL" not in os .environ :
108
- # self.parallel is a Python 3 only way to set parallel jobs by hand
109
- # using -j in the build_ext call, not supported by pip or PyPA-build.
110
- if hasattr (self , "parallel" ) and self .parallel :
111
- # CMake 3.12+ only.
112
- build_args += [f"-j{ self .parallel } " ]
113
-
114
- build_temp = Path (self .build_temp ) / ext .name
115
- if not build_temp .exists ():
116
- build_temp .mkdir (parents = True )
117
-
118
- subprocess .run (
119
- ["cmake" , ext .sourcedir , * cmake_args ], cwd = build_temp , check = True
120
- )
121
- subprocess .run (
122
- ["cmake" , "--build" , "." , * build_args ], cwd = build_temp , check = True
123
- )
10
+ __version__ = "0.0.5"
124
11
125
12
def main ():
126
13
cwd = os .path .dirname (os .path .abspath (__file__ ))
127
14
with open (os .path .join (cwd , "README.md" ), encoding = "utf-8" ) as f :
128
15
long_description = f .read ()
129
16
130
- packages = find_packages ()
131
-
132
- print (packages )
17
+ ext_modules = [
18
+ Pybind11Extension (
19
+ "tensor_array._ext" ,
20
+ sources = glob .glob (os .path .join ("cpp" , "*.cc" )),
21
+ include_dirs = ["tensor-array-repo/Tensor-Array/include" ],
22
+ library_dirs = ["tensor-array-repo/Tensor-Array/lib" ],
23
+ #libraries=["libtensorarray_core"],
24
+ define_macros = [("VERSION_INFO" , __version__ )],
25
+ ),
26
+ ]
133
27
134
28
setup (
135
29
name = "TensorArray" ,
136
- version = "0.0.4" ,
30
+ version = __version__ ,
137
31
description = "A machine learning package" ,
138
- long_description = long_description ,
139
- long_description_content_type = "text/markdown" ,
140
- author = "TensorArray-Creators" ,
141
- url = "https://github.com/Tensor-Array/Tensor-Array-Python" ,
142
- packages = packages ,
143
- ext_modules = [
144
- CMakeExtension ("tensor2" )
145
- ],
32
+ long_description = long_description ,
33
+ long_description_content_type = "text/markdown" ,
34
+ author = "TensorArray-Creators" ,
35
+ url = "https://github.com/Tensor-Array/Tensor-Array-Python" ,
146
36
classifiers = [
147
37
"Development Status :: 2 - Pre-Alpha" ,
148
38
@@ -158,16 +48,33 @@ def main():
158
48
159
49
"Environment :: GPU :: NVIDIA CUDA :: 12" ,
160
50
],
161
- license = "MIT" ,
162
- cmdclass = {
163
- "build_ext" : CMakeBuild
51
+ packages = [
52
+ "tensor_array" ,
53
+ "tensor_array_data.c_data.include" ,
54
+ "tensor_array_data.c_data.lib" ,
55
+ "tensor_array_data.c_data.scripts" ,
56
+ "tensor_array_data.local.scripts" ,
57
+ ],
58
+ package_dir = {
59
+ "tensor_array" : "src/tensor_array" ,
60
+ "tensor_array_data.c_data.include" : "tensor-array-repo/Tensor-Array/include" ,
61
+ "tensor_array_data.c_data.lib" : "tensor-array-repo/Tensor-Array/lib" ,
62
+ "tensor_array_data.c_data.scripts" : "tensor-array-repo/Tensor-Array/scripts" ,
63
+ "tensor_array_data.local.scripts" : "scripts" ,
64
+ },
65
+ package_data = {
66
+ "tensor_array" : ["**/*.py" ],
67
+ "tensor_array_data.c_data.include" : ["**/*.hh" ],
68
+ "tensor_array_data.c_data.lib" : ["**/*.so" ],
69
+ "tensor_array_data.c_data.scripts" : ["**/*.sh" ],
70
+ "tensor_array_data.local.scripts" : ["**/*.sh" ],
164
71
},
165
- package_dir = {
166
- "" : "src" ,
167
- "pybind11" : "third_party/pybind11/pybind11" ,
168
- "tests" : "tests"
72
+ ext_modules = ext_modules ,
73
+ cmdclass = {
74
+ "build_ext" : build_ext ,
169
75
},
170
- python_requires = ">=3.8" ,
76
+ license = "MIT" ,
77
+ python_requires = ">=3.8" ,
171
78
)
172
79
173
80
if __name__ == "__main__" :
0 commit comments