diff --git a/python/.gitignore b/python/.gitignore index ecf7820..787414d 100644 --- a/python/.gitignore +++ b/python/.gitignore @@ -9,6 +9,6 @@ __pycache__ *.pyc build-result/ dist/ -kcl_lib/lib +kcl_lib/bin kcl_lib.egg-info/ .eggs/ diff --git a/python/Makefile b/python/Makefile index c6e2c81..731b5d1 100644 --- a/python/Makefile +++ b/python/Makefile @@ -4,9 +4,9 @@ dist: rm -rf build rm -rf dist rm -rf kcl_lib.egg-info - rm -rf kcl_lib/lib/** + rm -rf kcl_lib/bin/** for platform in $(PLATFORMS); do \ - rm -rf build && rm -rf kcl_lib/lib && python3 setup.py bdist_wheel --plat-name $$platform; \ + rm -rf build && rm -rf kcl_lib/bin && python3 setup.py bdist_wheel --plat-name $$platform; \ done python3 -m twine upload dist/kcl_lib-* diff --git a/python/kcl_lib/api/service.py b/python/kcl_lib/api/service.py index 38b0030..7c360ba 100644 --- a/python/kcl_lib/api/service.py +++ b/python/kcl_lib/api/service.py @@ -5,7 +5,7 @@ from kcl_lib.bootstrap import ( KCLVM_CLI_INSTALL_PATH_ENV_VAR, KCLVM_CLI_BIN_PATH_ENV_VAR, - KCLVM_CLI_USE_RELEASE_ENV_VAR, + KCLVM_CLI_USE_TEST_ENV_VAR, lib_full_name, install_kclvm, ) @@ -104,7 +104,7 @@ def __init__(self): self._dir = tempfile.TemporaryDirectory() env_path = os.environ.get(KCLVM_CLI_BIN_PATH_ENV_VAR) env_install_path = os.environ.get(KCLVM_CLI_INSTALL_PATH_ENV_VAR) - env_use_release = os.environ.get(KCLVM_CLI_USE_RELEASE_ENV_VAR) + env_use_test = os.environ.get(KCLVM_CLI_USE_TEST_ENV_VAR) if env_path: self.lib = ctypes.CDLL(os.path.join(env_path, lib_full_name())) elif env_install_path: @@ -112,15 +112,16 @@ def __init__(self): self.lib = ctypes.CDLL( os.path.join(env_install_path, "bin", lib_full_name()) ) - elif env_use_release: - # The release lib is located at "kcl_lib/lib/" - lib_path = LIB_ROOT.joinpath("lib") - os.environ[KCLVM_CLI_BIN_PATH_ENV_VAR] = str(lib_path) - self.lib = ctypes.CDLL(str(lib_path.joinpath(lib_full_name()))) - else: + # Default test cases + elif env_use_test: # Install temp path. install_kclvm(self._dir.name) self.lib = ctypes.CDLL(self._dir.name + "/bin/" + lib_full_name()) + else: + # The release lib is located at "kcl_lib/bin/" + lib_path = LIB_ROOT.joinpath("bin") + os.environ[KCLVM_CLI_BIN_PATH_ENV_VAR] = str(lib_path) + self.lib = ctypes.CDLL(str(lib_path.joinpath(lib_full_name()))) # Assuming the shared library exposes a function `kclvm_service_new` self.lib.kclvm_service_new.argtypes = [ctypes.c_uint64] self.lib.kclvm_service_new.restype = ctypes.c_void_p diff --git a/python/kcl_lib/bootstrap/__init__.py b/python/kcl_lib/bootstrap/__init__.py index 9c66930..1eee179 100644 --- a/python/kcl_lib/bootstrap/__init__.py +++ b/python/kcl_lib/bootstrap/__init__.py @@ -6,7 +6,7 @@ KCLVM_VERSION = "0.8.0-alpha.5" # You should replace this with actual version KCLVM_CLI_BIN_PATH_ENV_VAR = "KCLVM_CLI_BIN_PATH" KCLVM_CLI_INSTALL_PATH_ENV_VAR = "KCLVM_CLI_INSTALL_PATH" -KCLVM_CLI_USE_RELEASE_ENV_VAR = "KCLVM_CLI_USE_RELEASE" +KCLVM_CLI_USE_TEST_ENV_VAR = "KCLVM_CLI_USE_TEST" LIB_NAME = "kclvm_cli_cdylib" diff --git a/python/setup.py b/python/setup.py index 8038c83..eed8d7e 100644 --- a/python/setup.py +++ b/python/setup.py @@ -107,13 +107,13 @@ def copyfile(src: pathlib.Path, dst: pathlib.Path) -> str: return str(dst.relative_to(pathlib.Path(__file__).parent)) -# Copy libs to the kcl_lib/lib folder +# Copy libs to the kcl_lib/bin folder def copy_libs(): source_dir = pathlib.Path(__file__).parent.parent - target_dir = pathlib.Path(__file__).parent.joinpath("kcl_lib").joinpath("lib") + target_dir = pathlib.Path(__file__).parent.joinpath("kcl_lib").joinpath("bin") data_files = [] data_files.append(copyfile(source_dir / cli_lib(), target_dir / lib_name())) - if PLATFORM in ["windows"]: + if PLATFORM in ["win32", "windows"]: data_files.append( copyfile(source_dir / export_lib(), target_dir / export_lib_name()) ) @@ -134,7 +134,7 @@ def copy_libs(): setup( name="kcl_lib", author="KCL Authors", - version="0.8.0-alpha.5", + version="0.8.0-alpha.6", license="Apache License 2.0", python_requires=">=3.7", description="KCL Artifact Library for Python", diff --git a/python/tests/exec_test.py b/python/tests/exec_test.py index d7b8d20..1e45aed 100644 --- a/python/tests/exec_test.py +++ b/python/tests/exec_test.py @@ -1,3 +1,9 @@ +import os +import kcl_lib.bootstrap as bootstrap + +os.environ[bootstrap.KCLVM_CLI_USE_TEST_ENV_VAR] = "ok" + + def test_exec_api(): import kcl_lib.api as api