Skip to content

Commit

Permalink
add manual build & fix errors in different platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
binh-vu committed May 12, 2024
1 parent 793f553 commit f14e95b
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ if [[ "$OSTYPE" == "linux-gnu"* ]]; then
else
# centos
# https://developers.redhat.com/blog/2018/07/07/yum-install-gcc7-clang#
yum install -y llvm-toolset-7
source /opt/rh/llvm-toolset-7/enable
yum install -y llvm-toolset-7.0
source /opt/rh/llvm-toolset-7.0/enable
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
echo "Skip on MacOS. Assuming you have CLang and LLVM installed."
Expand Down
17 changes: 17 additions & 0 deletions .github/workflows/manual_build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
set -ex

#
# This script is used to build aarch64 binary as Github does not supported it yet
# you run it in the root of the project


if [ -d "$(pwd)/dist" ]; then
rm -r $(pwd)/dist
fi

docker run --rm -w /project -v $(pwd):/project \
-e EXTRA_PATH=/opt/python/cp38-cp38/bin \
-e PYTHON_HOME=/opt/python \
-e CARGO_NET_GIT_FETCH_WITH_CLI=false \
quay.io/pypa/manylinux2014_aarch64:latest \
bash /project/.github/workflows/build.sh -t aarch64-unknown-linux-gnu
6 changes: 5 additions & 1 deletion .github/workflows/pydiscovery.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from __future__ import print_function
import os, subprocess, re, argparse

import argparse
import os
import re
import subprocess
from typing import Tuple


Expand Down
28 changes: 26 additions & 2 deletions hugedict/sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from hugedict.types import F, HugeMutableMapping, V

SqliteKey = TypeVar("SqliteKey", bound=Union[str, int, bytes])
TupleValue = TypeVar("TupleValue", bound=tuple)


class SqliteDictFieldType(str, Enum):
Expand All @@ -38,8 +39,8 @@ def __init__(
self,
path: Union[str, Path],
keytype: SqliteDictFieldType,
ser_value: Callable[[V], bytes] | Callable[[V], V],
deser_value: Callable[[bytes], V] | Callable[[V], V],
ser_value: Callable[[V], bytes],
deser_value: Callable[[bytes], V],
valuetype: SqliteDictFieldType = SqliteDictFieldType.bytes,
timeout: float = 5.0,
):
Expand Down Expand Up @@ -223,3 +224,26 @@ def fn(*args, **kwargs):
return fn

return wrapper_fn # type: ignore


class SqliteDictTuple(HugeMutableMapping[SqliteKey, TupleValue]):
def __init__(
self,
path: Union[str, Path],
keytype: SqliteDictFieldType,
ser_value: Callable[[TupleValue], bytes],
deser_value: Callable[[bytes], TupleValue],
valuetype: SqliteDictFieldType = SqliteDictFieldType.bytes,
timeout: float = 5.0,
):
self.dbfile = Path(path)
need_init = not self.dbfile.exists()
self.db = sqlite3.connect(str(self.dbfile), timeout=timeout)
if need_init:
with self.db:
self.db.execute(
f"CREATE TABLE data(key {keytype.value} PRIMARY KEY, value {valuetype.value})"
)

self.ser_value = ser_value
self.deser_value = deser_value
2 changes: 1 addition & 1 deletion src/rocksdb/dict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ pub fn pydeser_value<V: AsRef<[u8]>>(val: V, deser: &Py<PyAny>, py: Python) -> P
let v = unsafe {
let p = val.as_ref();
let mv = pyo3::ffi::PyMemoryView_FromMemory(
p.as_ptr() as *mut i8,
p.as_ptr() as *mut std::os::raw::c_char,
p.len() as isize,
pyo3::ffi::PyBUF_READ,
);
Expand Down

0 comments on commit f14e95b

Please sign in to comment.