sdfr 2.6.1__py3-none-musllinux_1_2_x86_64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sdfr/SDF.py +644 -0
- sdfr/__init__.py +41 -0
- sdfr/libsdfc_shared.so +0 -0
- sdfr/loadlib.py +66 -0
- sdfr/sdf_helper.py +2084 -0
- sdfr-2.6.1.dist-info/METADATA +12 -0
- sdfr-2.6.1.dist-info/RECORD +10 -0
- sdfr-2.6.1.dist-info/WHEEL +5 -0
- sdfr-2.6.1.dist-info/licenses/LICENSE +31 -0
- sdfr-2.6.1.dist-info/licenses/LICENSE_README.txt +4 -0
sdfr/loadlib.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# coding: utf-8
|
|
3
|
+
|
|
4
|
+
# Copyright 2022 University of Warwick, University of York
|
|
5
|
+
#
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
|
|
18
|
+
import sys
|
|
19
|
+
import ctypes as ct
|
|
20
|
+
from contextlib import suppress
|
|
21
|
+
from itertools import product
|
|
22
|
+
from pathlib import Path
|
|
23
|
+
from site import getsitepackages
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _loadlib():
|
|
27
|
+
"""Finds and load the library ``libsdfc_shared.so``, or an alternative.
|
|
28
|
+
|
|
29
|
+
Searches first in the current file's directory, then iterates through site
|
|
30
|
+
packages. This enables the library to be found even on an editable install.
|
|
31
|
+
Raises a ``RuntimeError`` if it is missing.
|
|
32
|
+
"""
|
|
33
|
+
# Try finding library using import.
|
|
34
|
+
# Expect this to fail, but it will trigger a rebuild if the project is
|
|
35
|
+
# installed in editable mode.
|
|
36
|
+
with suppress(ImportError):
|
|
37
|
+
import sdfr
|
|
38
|
+
|
|
39
|
+
# Find library in site-packages or local to this module
|
|
40
|
+
local_dir = Path(__file__).resolve().parent
|
|
41
|
+
site_dirs = [Path(x) / "sdfr" for x in getsitepackages()]
|
|
42
|
+
path_dirs = [Path(x) for x in sys.path]
|
|
43
|
+
exts = ("so", "dylib", "dll")
|
|
44
|
+
for lib_dir, ext in product([local_dir, *site_dirs, *path_dirs], exts):
|
|
45
|
+
if (lib := lib_dir / f"libsdfc_shared.{ext}").exists():
|
|
46
|
+
return ct.cdll.LoadLibrary(str(lib))
|
|
47
|
+
raise RuntimeError("Could not find library 'libsdfc_shared'")
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
sdf_lib = _loadlib()
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _get_lib_commit_id():
|
|
54
|
+
global sdf_lib
|
|
55
|
+
sdf_lib.sdf_get_library_commit_id.restype = ct.c_char_p
|
|
56
|
+
return sdf_lib.sdf_get_library_commit_id().decode()
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def _get_lib_commit_date():
|
|
60
|
+
global sdf_lib
|
|
61
|
+
sdf_lib.sdf_get_library_commit_date.restype = ct.c_char_p
|
|
62
|
+
return sdf_lib.sdf_get_library_commit_date().decode()
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
__library_commit_id__ = _get_lib_commit_id()
|
|
66
|
+
__library_commit_date__ = _get_lib_commit_date()
|