-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathsetup.py
More file actions
115 lines (92 loc) · 3.99 KB
/
Copy pathsetup.py
File metadata and controls
115 lines (92 loc) · 3.99 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
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
from skbuild import setup
from pathlib import Path
import re
import os
import sys
import platform
def get_install_base():
current_folder = Path(__file__).parent
platform_name = platform.system().lower()
if platform_name == "linux":
architecture = platform.architecture()[0]
if architecture == "64bit":
architecture = "x86_64"
elif architecture == "32bit":
architecture = "i686"
else:
raise RuntimeError(f"Unsupported architecture: {architecture}")
python_version = f"{sys.version_info.major}.{sys.version_info.minor}"
platform_name = f"linux-{architecture}-{python_version}"
elif platform_name == "darwin":
# Get the number of macos version (e.g. 13.0)
version = platform.mac_ver()[0].split(".")
version = f"{version[0]}.0"
architecture = platform.architecture()[0]
if architecture == "64bit":
architecture = "x86_64"
else:
raise RuntimeError(f"Unsupported architecture: {architecture}")
python_version = f"{sys.version_info.major}.{sys.version_info.minor}"
platform_name = f"macosx-{version}-x86_64-{python_version}"
elif platform_name == "windows":
architecture = platform.architecture()[0]
if architecture == "64bit":
architecture = "amd64"
else:
raise RuntimeError(f"Unsupported architecture: {architecture}")
python_version = f"{sys.version_info.major}.{sys.version_info.minor}"
platform_name = f"win-{architecture}-{python_version}"
return f"{current_folder}/_skbuild/{platform_name}/cmake-install"
def get_install_site_packages():
# Keep the Python package install path inside the scikit-build install prefix.
# On Windows, site-packages lives under Lib/site-packages (without pythonX.Y).
if platform.system().lower() == "windows":
return Path("Lib/site-packages")
python_version = f"python{sys.version_info.major}.{sys.version_info.minor}"
return Path(f"lib/{python_version}/site-packages")
dir_path = os.path.dirname(os.path.realpath(__file__))
try:
import pypandoc
long_description = pypandoc.convert("README.md", "r")
except (IOError, ImportError):
long_description = open("README.md").read()
with open(f"{dir_path}/CMakeLists.txt") as file:
for line in file:
match = re.search(re.compile("project\\(biorbd VERSION (\\d*\\.\\d*\\.\\d*)\\)"), line)
if match is not None:
version = match[1]
break
else:
raise RuntimeError("Version not found")
# Create an empty 'biorbd' folder if it doesn't exist (stub for setup.py)
Path("biorbd").mkdir(exist_ok=True)
# Get the MATH_LIBRARY_BACKEND from environment variable
math_library_backend = os.environ.get("MATH_LIBRARY_BACKEND")
if math_library_backend not in ["Casadi", "Eigen3"]:
raise RuntimeError("MATH_LIBRARY_BACKEND environment variable must be set to either 'Casadi' or 'Eigen3'")
if math_library_backend == "Casadi":
raise RuntimeError(
"Casadi backend is not supported via pip install in this workspace. Use the CMake/dev build instead."
)
setup(
# NOTE: Could still add stuff like homepage or author mail, but since this isn't used to redistribute, not important
name="biorbd",
version=version,
author="Michaud, Benjamin and Begon, Mickaël",
description="Biomechanical add-ons to the RigidBody Dynamics Library",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/pyomeca/biorbd",
license="MIT",
packages=["biorbd"],
cmake_args=[
"-DBUILD_EXAMPLE:BOOL=OFF",
"-DBINDER_PYTHON3:BOOL=ON",
"-DCMAKE_INSTALL_BINDIR=biorbd",
"-DCMAKE_INSTALL_LIBDIR=biorbd",
f"-DMATH_LIBRARY_BACKEND={math_library_backend}",
f"-DINSTALL_DEPENDENCIES_PREFIX={get_install_base()}",
f"-DPython3_SITELIB_INSTALL={get_install_site_packages()}",
f"-DOVERRIDE_LIB_SUFFIX=''",
],
)