-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsetup.py
112 lines (90 loc) · 2.95 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
##### Sensemore Communication Protocol : SMCom #######
#
#Required packages
# - pybind11
import os,sys
import subprocess
import pathlib
from distutils import spawn
from setuptools import setup, find_packages, Extension
try:
import pybind11
except ImportError:
if subprocess.call([sys.executable, '-m', 'pip', 'install', 'pybind11']):
raise RuntimeError('pybind11 install failed.')
from pybind11.setup_helpers import Pybind11Extension, build_ext
from pybind11 import get_cmake_dir
# c++ -shared -fPIC $(python3 -m pybind11 --includes) config.cpp SMCom.cpp -o SMCom$(python3-config --extension-suffix)
file_abs_path = os.path.abspath(__file__)
smcompy_directory = os.path.dirname(file_abs_path)
repo_directory = os.path.dirname(smcompy_directory)
so_flags = ["-shared", "-fPIC" ]
module_name = "SMComPy"
source_files = [
os.path.join(repo_directory,"src/SMCom.cpp"),
os.path.join(smcompy_directory,"pybind11_config.cpp")
]
header_files = [
os.path.join(repo_directory,"include")
]
optimization_flag = "-O0"
def generate_so_file():
compiler = spawn.find_executable("g++")
p = subprocess.run(["python3","-m", "pybind11", "--includes"],capture_output=True)
pybind11_includes = str(p.stdout,'utf-8').strip('\n').split()
p = subprocess.run(["python3-config","--extension-suffix"],capture_output=True)
python_extension = str(p.stdout,'utf-8').strip('\n')
subprocess.run([compiler,
optimization_flag,
*so_flags,
*pybind11_includes,
"-I",
*header_files,
*source_files,
"-o",
module_name + python_extension
])
ext_modules = [
Pybind11Extension(module_name,
sources = ["src/SMCom.cpp", "SMComPy_src/pybind11_config.cpp"],
include_dirs = ["include"],
language="c++"
),
]
with open("README.md", "r", encoding="utf-8") as f:
long_description = f.read()
#Read version from header automatically by exec function
version = ""
with open("./include/SMCom.h","r") as f:
vline = f.read().split('\n')[5] #This is constant!
exec(vline.replace("#define SMCOM_VERSION_STRING\t",'version='))
setup(
name=module_name,
version=version,
author="sensemore",
author_email="[email protected]",
url="https://github.com/sensemore/SMCom",
description="SMComPy project",
long_description=long_description,
long_description_content_type="text/markdown",
ext_modules=ext_modules,
license="MIT",
# Currently, build_ext only provides an optional "highest supported C++
# level" feature, but in the future it may provide more features.
cmdclass={"build_ext": build_ext},
zip_safe=False,
python_requires=">=3.6",
install_requires=[
"pybind11==2.7.0",
],
setup_requires=[
"setuptools>=42",
"pybind11==2.7.0",
"wheel",
],
keywords="SMCom, sensemore, communication protocol, uart communication protocol, serial communication protocol",
project_urls={ # Optional
'Bug Reports': 'https://github.com/sensemore/SMCom/issues',
'Source': 'https://github.com/sensemore/SMCom',
},
)