Skip to content

Commit 466bca1

Browse files
committed
feat: Update ggml lib install dir
1 parent 9a71ef3 commit 466bca1

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ message(SKBUILD_STATE="${SKBUILD_STATE}")
99

1010
if(SKBUILD_STATE STREQUAL "editable")
1111
# Temporary fix for https://github.com/scikit-build/scikit-build-core/issues/374
12-
set(GGML_PYTHON_INSTALL_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ggml)
12+
set(GGML_PYTHON_INSTALL_DIR ${CMAKE_CURRENT_SOURCE_DIR}/ggml/lib)
1313
else()
14-
set(GGML_PYTHON_INSTALL_DIR ${SKBUILD_PLATLIB_DIR}/ggml)
14+
set(GGML_PYTHON_INSTALL_DIR ${SKBUILD_PLATLIB_DIR}/ggml/lib)
1515
endif()
1616

1717
set(BUILD_SHARED_LIBS "On")
@@ -38,4 +38,4 @@ install(
3838
install(
3939
FILES $<TARGET_RUNTIME_DLLS:ggml>
4040
DESTINATION ${GGML_PYTHON_INSTALL_DIR}
41-
)
41+
)

ggml/ggml.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@
5959
import ctypes
6060
import pathlib
6161
import functools
62-
import importlib.resources
62+
try:
63+
# Python < 3.9
64+
import importlib_resources
65+
except ImportError:
66+
import importlib.resources as importlib_resources
6367
from typing import (
6468
cast,
6569
Any,
@@ -79,7 +83,7 @@
7983
# Load the library
8084
def load_shared_library(module_name: str, lib_base_name: str):
8185
# Construct the paths to the possible shared library names
82-
base_path = pathlib.Path(__file__).parent.resolve()
86+
base_path = pathlib.Path(__file__).parent.resolve() / "lib"
8387
# Searching for the library in the current directory under the name "libggml" (default name
8488
# for ggml) and "ggml" (default name for this repo)
8589
lib_names: List[str] = [
@@ -92,7 +96,8 @@ def load_shared_library(module_name: str, lib_base_name: str):
9296

9397
for lib_name in lib_names:
9498
try:
95-
with importlib.resources.path(module_name, lib_name) as p:
99+
with importlib_resources.as_file(importlib_resources.files(module_name).joinpath("lib", lib_name)) as p: # type: ignore
100+
p = cast(pathlib.Path, p)
96101
if os.path.exists(p):
97102
path = p
98103
break
@@ -107,6 +112,7 @@ def load_shared_library(module_name: str, lib_base_name: str):
107112
cdll_args = dict() # type: ignore
108113
# Add the library directory to the DLL search path on Windows (if needed)
109114
if sys.platform == "win32" and sys.version_info >= (3, 8):
115+
os.environ["PATH"] = str(base_path) + os.pathsep + os.environ["PATH"]
110116
os.add_dll_directory(str(base_path))
111117
cdll_args["winmode"] = 0
112118

@@ -7752,7 +7758,7 @@ class gguf_init_params(ctypes.Structure):
77527758

77537759
if TYPE_CHECKING:
77547760
no_alloc: bool
7755-
ctx: ggml_context_p
7761+
ctx: CtypesPointer[ggml_context_p]
77567762

77577763
_fields_ = [
77587764
("no_alloc", ctypes.c_bool),

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ authors = [
1414
requires-python = ">=3.7"
1515
dependencies = [
1616
"numpy>=1.20.0",
17-
"typing_extensions>=4.6.3"
17+
"typing_extensions>=4.6.3",
18+
"importlib_resources>=6.4.0; python_version < '3.9'",
1819
]
1920
classifiers = [
2021
"Programming Language :: Python :: 3",

0 commit comments

Comments
 (0)