-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_lib.py
More file actions
50 lines (41 loc) · 1.59 KB
/
build_lib.py
File metadata and controls
50 lines (41 loc) · 1.59 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
import os
from distutils import sysconfig
import setuptools
from setuptools import Extension, setup, find_packages
from setuptools.command.build_ext import build_ext
from typing import Literal
moduleName = "Tensor_Main"
cRelativeDir = f"src{os.sep}c"
sourceFiles = [
file for file in os.listdir(os.path.join(os.path.dirname(__file__), cRelativeDir)) if file.endswith(".c")
]
# Autofind header files in ./c
headerFiles = [
file for file in os.listdir(os.path.join(os.path.dirname(__file__), cRelativeDir)) if file.endswith(".h")
]
dependencies = [
"Cython"
]
def setPaths(files: list[str], relativeFolder: str, exclude: list[str] = [], pathType: Literal["absolute", "relative"] = "absolute"):
return [os.path.join(os.path.dirname(__file__), relativeFolder, file) for file in files if file not in exclude] if pathType == "absolute" else [os.path.join(cRelativeDir, file) for file in sourceFiles if file not in ["Tensor_Main.c"]]
modules = [
Extension(
name="Tensor_Python",
sources=setPaths(sourceFiles, cRelativeDir, ["Tensor_Main.c"], "relative"),
# headers=sourceAbsFiles(headerFiles, cRelativeDir),
)
]
class NoSuffixBuilder(build_ext):
def get_ext_filename(self, ext_name):
filename = super().get_ext_filename(ext_name)
suffix = sysconfig.get_config_var('EXT_SUFFIX')
ext = os.path.splitext(filename)[1]
return filename.replace(suffix, '') + ext
setup(
name=moduleName,
version="1.0",
description="...",
ext_modules=modules,
package_dir={"": f"src/nettensorpat"},
cmdclass={'build_ext': NoSuffixBuilder}
)