-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
83 lines (65 loc) · 2.61 KB
/
setup.py
File metadata and controls
83 lines (65 loc) · 2.61 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
import setuptools
from setuptools import sandbox
import distutils
import textwrap
import os
cPythonExtDir = os.path.join(os.path.dirname(__file__), 'src', 'nettensorpat')
class Desc:
comp = "Compiles the C Python extension module"
class Pnt_Cmds:
def compile():
fileList = '\t ' + '\n\t '.join([file for file in sorted(os.listdir(os.path.join(os.path.dirname(__file__), 'src', 'c'))) if file.endswith(".c") or file.endswith(".h")])
print(textwrap.dedent(
f"""
⚙️ Starting compilation of:
\t{os.path.join(os.path.dirname(__file__), 'src', 'c')}
📝 Files scanned:
__FILE_LIST__
📝 Command:
\tsh compile.sh
"""
).replace("__FILE_LIST__", fileList)[1:-1])
cwd = os.getcwd()
os.chdir(os.path.dirname(__file__))
print(f"📂 {'Changed directory to `' + os.getcwd() + '` from `' + cwd + '`.' if cwd != os.getcwd() else 'Directory remains unchanged.'}")
print("📝 Running compilation...")
print("----------------------------------------\n")
sandbox.run_setup("build_lib.py", ["build_ext", "--inplace"])
print("\n----------------------------------------")
# Check if compiled .so file exists
if (os.path.exists(os.path.join(cPythonExtDir, 'Tensor_Python.so'))):
print(f"🟢 Successfully compiled C Python extension module located in `{cPythonExtDir}`.")
else:
print(f"🔴 Failed to compile C Python extension module located in `{cPythonExtDir}`.")
raise RuntimeError("Failed to compile C Python extension module.")
class pnt(setuptools.Command):
description = "Runs pattern net tensor commands"
user_options = [
('compile', None, Desc.comp)
]
fnMap = {
"compile": Pnt_Cmds.compile
}
def initialize_options(self) -> None:
self.subcommands = []
self.compile = 0 # type: pathlib.Path
def finalize_options(self) -> None:
if (self.compile == 1):
self.fnMap["compile"]()
def run(self):
print("🏁 Finished")
moduleName = "nettensorpat"
setuptools.setup(
name=moduleName,
version="1.0",
description=textwrap.dedent("""
A package for finding the local clustering patterns in a given series of networks utilizing either local or global
""")[1:-1],
package_dir={"": f"src"},
packages=["src"],
include_package_data=True,
scripts=["compile.sh"],
cmdclass={
"pnt": pnt
}
)