This is an automated email from the ASF dual-hosted git repository.

baunsgaard pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/systemds.git


The following commit(s) were added to refs/heads/main by this push:
     new a487be0114 [SYSTEMDS-3802] Conditionally Load Scuro
a487be0114 is described below

commit a487be0114c5cc18f07dca860bca7101c9e6120b
Author: Christina Dionysio <[email protected]>
AuthorDate: Wed Dec 4 14:46:30 2024 +0100

    [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
---
 src/main/python/systemds/__init__.py | 42 +++++++++++++++++++++++++++++++++---
 1 file changed, 39 insertions(+), 3 deletions(-)

diff --git a/src/main/python/systemds/__init__.py 
b/src/main/python/systemds/__init__.py
index e0f485df79..a618ff6e9d 100644
--- a/src/main/python/systemds/__init__.py
+++ b/src/main/python/systemds/__init__.py
@@ -18,10 +18,46 @@
 # under the License.
 #
 # -------------------------------------------------------------
-
+from importlib.metadata import version, PackageNotFoundError
 from systemds import context
 from systemds import operator
 from systemds import examples
-from systemds import scuro
 
-__all__ = ["context", "operator", "examples", "scuro"]
+__all__ = ["context", "operator", "examples"]
+
+required_packages = [
+    ("torch", "2.5.1"),
+    ("torchvision", "0.20.1"),
+    ("librosa", "0.10.2"),
+    ("opencv-python", "4.10.0.84"),
+    ("opt-einsum", "3.3.0"),
+    ("h5py", "3.11.0"),
+    ("transformers", "4.46.3"),
+    ("nltk", "3.9.1"),
+    ("gensim", "4.3.3"),
+]
+
+
+def check_package_version(package_name, required_version):
+    try:
+        return version(package_name) >= required_version
+    except PackageNotFoundError:
+        return False
+
+
+if all(check_package_version(pkg, version) for pkg, version in 
required_packages):
+    try:
+        from systemds import scuro
+
+        __all__.append("scuro")
+    except ImportError as e:
+        print(f"Scuro could not be imported: {e}")
+else:
+    missing = [
+        f"{pkg} {version}"
+        for pkg, version in required_packages
+        if not check_package_version(pkg, version)
+    ]
+    print(
+        f"Warning: Scuro dependencies missing or wrong version installed: {', 
'.join(missing)}"
+    )

Reply via email to