Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions magent2/c_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@
def _load_lib():
"""Load library in local."""
cur_path = os.path.dirname(os.path.abspath(os.path.expanduser(__file__)))
lib_path = os.path.join(cur_path, "..", "venv", "Lib", "site-packages", "magent2")
lib_path = cur_path
if platform.system() == "Darwin":
path_to_so_file = os.path.join(lib_path, "libmagent.dylib")
import sysconfig

filename = f"libmagent.{sysconfig.get_config_var('SOABI')}.dylib"
path_to_so_file = os.path.join(lib_path, filename)
elif platform.system() == "Linux":
path_to_so_file = os.path.join(lib_path, "libmagent.so")
import sysconfig

filename = f"libmagent.{sysconfig.get_config_var('SOABI')}.so"
path_to_so_file = os.path.join(lib_path, filename)
elif platform.system() == "Windows":
path_to_so_file = os.path.join(lib_path, "magent.dll")
else:
Expand Down
28 changes: 19 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import platform
import shutil
import subprocess
from subprocess import check_output

Expand Down Expand Up @@ -74,35 +75,44 @@ def build_extensions(self):
print(extdir)
subprocess.check_call(["ls"])

# lib_ext = ""
# lib_name = ""

if platform.system() == "Darwin":
# lib_ext = ".dylib"
# lib_name = "libmagent"
lib_ext = ".dylib"
lib_name = "libmagent"
thread_num = check_output(["sysctl", "-n", "hw.ncpu"], encoding="utf-8")
subprocess.check_call(
["make", "-C", make_location, "-j", str(thread_num).rstrip()],
cwd=extdir,
)
elif platform.system() == "Linux":
# lib_ext = ".so"
# lib_name = "libmagent"
lib_ext = ".so"
lib_name = "libmagent"
thread_num = check_output(["nproc"], encoding="utf-8")
subprocess.check_call(
["make", "-C", make_location, "-j", str(thread_num).rstrip()],
cwd=extdir,
)
elif platform.system() == "Windows":
# lib_ext = ".dll"
# lib_name = "magent"
lib_ext = ".dll"
lib_name = "magent"
thread_num = 1
# cmake --build . --target ALL_BUILD --config Release
subprocess.check_call(
["cmake", "--build", ".", "--target", "ALL_BUILD", "--config", cfg],
cwd=make_location,
shell=True,
)
else:
raise RuntimeError("unsupported system: " + platform.system())

# copy generic object file to expected cpython object file
cmake_lib = os.path.join(self.build_lib, "magent2", f"{lib_name}.{lib_ext}")
if not os.path.exists(cmake_lib):
raise FileNotFoundError(
f"Expected CMake build output {cmake_lib} not found."
)
ext_fullpath = self.get_ext_fullpath(ext.name)
shutil.copyfile(cmake_lib, ext_fullpath)

# build_res_dir = extdir + "/magent/build/"
# if not os.path.exists(build_res_dir):
# os.makedirs(build_res_dir)
Expand Down