Skip to content

Commit af7ca87

Browse files
committed
fix: Loader
1 parent 13fb182 commit af7ca87

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

src/c2pa/lib.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
Library loading utilities
33
4-
Takes care only on loading the needed compiled libraries.
4+
Takes care only on loading the needed compiled library.
55
"""
66

77
import os
@@ -40,16 +40,17 @@ def _load_single_library(lib_name: str, search_paths: list[Path]) -> Optional[ct
4040
logger.error(f"Failed to load library from {lib_path}: {e}")
4141
return None
4242

43-
def dynamically_load_library(lib_name: Optional[str] = None, load_c2pa: bool = True) -> Tuple[Optional[ctypes.CDLL], Optional[ctypes.CDLL]]:
43+
def dynamically_load_library(lib_name: Optional[str] = None) -> Optional[ctypes.CDLL]:
4444
"""
45-
Load the dynamic libraries based on the platform.
45+
Load the dynamic library containing the C-API based on the platform.
4646
4747
Args:
4848
lib_name: Optional specific library name to load. If provided, only this library will be loaded.
49-
load_c2pa: Whether to load the c2pa library (default: True). Ignored if lib_name is provided.
49+
This enables to potentially load wrapper libraries of the C-API that may have an other name
50+
(the presence of required symbols will nevertheless be verified once the library is loaded).
5051
5152
Returns:
52-
Tuple of (adobe_lib, c2pa_lib). If load_c2pa is False or lib_name is provided, c2pa_lib will be None.
53+
The loaded library or None if loading failed
5354
"""
5455
if sys.platform == "darwin":
5556
c2pa_lib_name = "libc2pa_c.dylib"
@@ -67,7 +68,7 @@ def dynamically_load_library(lib_name: Optional[str] = None, load_c2pa: bool = T
6768
try:
6869
lib = _load_single_library(env_lib_name, possible_paths)
6970
if lib:
70-
return lib, None
71+
return lib
7172
else:
7273
logger.error(f"Could not find library {env_lib_name} in any of the search paths")
7374
# Continue with normal loading if environment variable library name fails
@@ -94,10 +95,9 @@ def dynamically_load_library(lib_name: Optional[str] = None, load_c2pa: bool = T
9495
raise RuntimeError(f"Could not find {lib_name} in any of the search paths")
9596
return lib
9697

97-
c2pa_lib = None
98-
if load_c2pa:
99-
c2pa_lib = _load_single_library(c2pa_lib_name, possible_paths)
100-
if not c2pa_lib:
101-
raise RuntimeError(f"Could not find {c2pa_lib_name} in any of the search paths")
98+
# Default paht (no library name provided in the environment)
99+
c2pa_lib = _load_single_library(c2pa_lib_name, possible_paths)
100+
if not c2pa_lib:
101+
raise RuntimeError(f"Could not find {c2pa_lib_name} in any of the search paths")
102102

103103
return c2pa_lib

tests/test_unit_tests.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
class TestReader(unittest.TestCase):
3232
def setUp(self):
3333
# Use the fixtures_dir fixture to set up paths
34-
self.data_dir = os.path.join(os.path.dirname(__file__), "fixtures")
34+
self.data_dir = os.path.join(os.path.dirname(__file__), "fixtures")
3535
self.testPath = os.path.join(self.data_dir, "C.jpg")
36-
36+
3737
def test_stream_read(self):
3838
with open(self.testPath, "rb") as file:
3939
reader = Reader("image/jpeg",file)
@@ -78,9 +78,9 @@ def setUp(self):
7878
ta_url=b"http://timestamp.digicert.com"
7979
)
8080
self.signer = Signer.from_info(self.signer_info)
81-
81+
8282
self.testPath = os.path.join(self.data_dir, "C.jpg")
83-
83+
8484
# Define a manifest as a dictionary
8585
self.manifestDefinition = {
8686
"claim_generator": "python_test",

0 commit comments

Comments
 (0)