Skip to content

Commit a487be0

Browse files
christinadionysioBaunsgaard
authored andcommitted
[SYSTEMDS-3802] Conditionally Load Scuro
This commits refine the __init__.py file for systemds, to conditionally load the Scuro library. Previeously, more packages would have to be installed to run SystemDS via the Python API. Now it is more lean with an informative warning listing the required packages if Scuro is required. Closes #2150
1 parent 742eec8 commit a487be0

File tree

1 file changed

+39
-3
lines changed

1 file changed

+39
-3
lines changed

src/main/python/systemds/__init__.py

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,46 @@
1818
# under the License.
1919
#
2020
# -------------------------------------------------------------
21-
21+
from importlib.metadata import version, PackageNotFoundError
2222
from systemds import context
2323
from systemds import operator
2424
from systemds import examples
25-
from systemds import scuro
2625

27-
__all__ = ["context", "operator", "examples", "scuro"]
26+
__all__ = ["context", "operator", "examples"]
27+
28+
required_packages = [
29+
("torch", "2.5.1"),
30+
("torchvision", "0.20.1"),
31+
("librosa", "0.10.2"),
32+
("opencv-python", "4.10.0.84"),
33+
("opt-einsum", "3.3.0"),
34+
("h5py", "3.11.0"),
35+
("transformers", "4.46.3"),
36+
("nltk", "3.9.1"),
37+
("gensim", "4.3.3"),
38+
]
39+
40+
41+
def check_package_version(package_name, required_version):
42+
try:
43+
return version(package_name) >= required_version
44+
except PackageNotFoundError:
45+
return False
46+
47+
48+
if all(check_package_version(pkg, version) for pkg, version in required_packages):
49+
try:
50+
from systemds import scuro
51+
52+
__all__.append("scuro")
53+
except ImportError as e:
54+
print(f"Scuro could not be imported: {e}")
55+
else:
56+
missing = [
57+
f"{pkg} {version}"
58+
for pkg, version in required_packages
59+
if not check_package_version(pkg, version)
60+
]
61+
print(
62+
f"Warning: Scuro dependencies missing or wrong version installed: {', '.join(missing)}"
63+
)

0 commit comments

Comments
 (0)