Skip to content

Commit

Permalink
Make patch release 4.1.1 (#555)
Browse files Browse the repository at this point in the history
* Restore support for Python 3.8

* PyPy compatibility patch

* Load libtreelite.so with symbols visible globally

* Make 4.1.1 release
  • Loading branch information
hcho3 committed Feb 22, 2024
1 parent 70b4206 commit 64e5651
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 14 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cmake_policy(SET CMP0091 NEW)
set(CMAKE_FIND_NO_INSTALL_PREFIX TRUE FORCE)
cmake_minimum_required(VERSION 3.16 FATAL_ERROR)

project(treelite LANGUAGES CXX C VERSION 4.1.0)
project(treelite LANGUAGES CXX C VERSION 4.1.1)

# Check compiler versions
# Use latest compilers to ensure that std::filesystem is available
Expand Down
2 changes: 1 addition & 1 deletion python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ build-backend = "packager.pep517"

[project]
name = "treelite"
version = "4.1.0"
version = "4.1.1"
authors = [
{name = "Hyunsu Cho", email = "chohyu01@cs.washington.edu"}
]
Expand Down
2 changes: 1 addition & 1 deletion python/treelite/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.1.0
4.1.1
2 changes: 1 addition & 1 deletion python/treelite/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def _load_lib():
os.add_dll_directory(
os.path.join(os.path.normpath(sys.base_prefix), "Library", "bin")
)
lib = ctypes.cdll.LoadLibrary(lib_path[0])
lib = ctypes.CDLL(lib_path[0], mode=ctypes.RTLD_GLOBAL)
lib.TreeliteGetLastError.restype = ctypes.c_char_p
lib.log_callback = _log_callback
lib.warn_callback = _warn_callback
Expand Down
26 changes: 18 additions & 8 deletions python/treelite/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import ctypes
import pathlib
import platform
import warnings
from typing import Any, List, Optional, Union

Expand Down Expand Up @@ -419,17 +420,20 @@ class _PyBuffer(ctypes.Structure): # pylint: disable=R0902,R0903
)


ctypes.pythonapi.PyMemoryView_FromBuffer.argtypes = [ctypes.POINTER(_PyBuffer)]
ctypes.pythonapi.PyMemoryView_FromBuffer.restype = ctypes.py_object
ctypes.pythonapi.PyObject_GetBuffer.argtypes = [
ctypes.py_object,
ctypes.POINTER(_PyBuffer),
ctypes.c_int,
]
ctypes.pythonapi.PyObject_GetBuffer.restype = ctypes.c_int
if platform.python_implementation() == "CPython":
ctypes.pythonapi.PyMemoryView_FromBuffer.argtypes = [ctypes.POINTER(_PyBuffer)]
ctypes.pythonapi.PyMemoryView_FromBuffer.restype = ctypes.py_object
ctypes.pythonapi.PyObject_GetBuffer.argtypes = [
ctypes.py_object,
ctypes.POINTER(_PyBuffer),
ctypes.c_int,
]
ctypes.pythonapi.PyObject_GetBuffer.restype = ctypes.c_int


def _pybuffer2numpy(frame: _TreelitePyBufferFrame) -> np.ndarray:
if platform.python_implementation() != "CPython":
raise NotImplementedError("_pybuffer2numpy() not supported on PyPy")
if not frame.buf:
if frame.format == b"=l":
dtype = "int32"
Expand Down Expand Up @@ -466,6 +470,8 @@ def _pybuffer2numpy(frame: _TreelitePyBufferFrame) -> np.ndarray:


def _numpy2pybuffer(array: np.ndarray) -> _TreelitePyBufferFrame:
if platform.python_implementation() != "CPython":
raise NotImplementedError("_numpy2pybuffer() not supported on PyPy")
if len(array.shape) != 1:
raise ValueError("Cannot handle NumPy array that has more than 1 dimension")
view: memoryview = array.data
Expand Down Expand Up @@ -516,6 +522,8 @@ def get_field(self, name: str) -> Union[np.ndarray, str]:
Value in the field
(``str`` for a string field, ``np.ndarray`` for other fields)
"""
if platform.python_implementation() != "CPython":
raise NotImplementedError("get_field() not supported on PyPy")
obj = _TreelitePyBufferFrame()
_check_call(
_LIB.TreeliteGetHeaderField(
Expand All @@ -542,6 +550,8 @@ def set_field(self, name: str, value: Union[np.ndarray, str]):
New value for the field
(``str`` for a string field, ``np.ndarray`` for other fields)
"""
if platform.python_implementation() != "CPython":
raise NotImplementedError("set_field() not supported on PyPy")
if isinstance(value, str):
value = np.frombuffer(value.encode("utf-8"), dtype="S1")
_check_call(
Expand Down
3 changes: 1 addition & 2 deletions python/treelite/model_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import ctypes
import dataclasses
import json
from collections.abc import Sequence
from typing import Any, Dict, List, Optional, Tuple, Union
from typing import Any, Dict, List, Optional, Sequence, Tuple, Union

from .core import _LIB, _check_call
from .model import Model
Expand Down

0 comments on commit 64e5651

Please sign in to comment.