You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The node must implement the `__call__` method to run the node.
18
18
"""
19
19
20
-
dependencies: list[str] =[]
20
+
dependencies: set[str] =set()
21
21
"""The pip dependencies of the node (python packages). On initialization of the node a check is performed if the dependencies are installed with importlib. If not an error is raised."""
22
22
23
23
@classmethod
24
24
defcheck_dependencies(cls) ->None:
25
25
"""
26
26
Checks if the dependencies of the node are installed.
27
+
28
+
Raises:
29
+
ImportError: If a dependency is not installed.
27
30
"""
28
31
fordependencyincls.dependencies:
29
32
try:
30
33
metadata.version(dependency)
31
34
exceptmetadata.PackageNotFoundError:
32
35
raiseImportError(f"Dependency {dependency} not found but required by node {cls.__name__}. Please install it with pip install {dependency}")
33
36
37
+
def__init_subclass__(cls) ->None:
38
+
"""
39
+
Called when a subclass is created. This is used to collect the dependencies of the node from parent classes.
40
+
41
+
Works recursively because it is called on each inheritance level. Therefore the dependencies of all parent classes are collected and stored in the class variable `dependencies` of the child class.
42
+
"""
43
+
super().__init_subclass__()
44
+
45
+
cls.dependencies=cls.dependencies.copy() # To not modify the class variable of the parent
46
+
47
+
forbaseincls.__bases__: # Called on each inheritance level, therefore its recursive
0 commit comments