|
3 | 3 | import inspect |
4 | 4 | import os |
5 | 5 | import sys |
6 | | -# from . import Example |
7 | 6 |
|
8 | 7 |
|
9 | 8 | example_classes: list[type] = [] |
10 | 9 |
|
11 | 10 | dir_containing_this_module = os.path.dirname(os.path.abspath(__file__)) |
12 | | -all_packages = pkgutil.walk_packages([dir_containing_this_module + "/client"]) |
13 | | -for package in all_packages: |
14 | | - print(package) |
15 | | - module = importlib.import_module("." + package.name, ".examples.client") |
16 | | - for name, obj in inspect.getmembers(module, inspect.isclass): |
17 | | - if obj.__module__ != module.__name__: |
18 | | - continue |
19 | | - print("Class found:", obj) |
20 | | - # print(Example is obj.__bases__[0]) |
21 | | - # TODO - comparing the same class imported two different ways fails |
22 | | - # There might a better way to do this |
23 | | - if obj.__bases__[0].__name__ != "Example": |
24 | | - continue |
25 | | - example_classes.append(obj) |
| 11 | + |
| 12 | +for folder in ["client", "string_ops"]: |
| 13 | + all_packages = pkgutil.walk_packages([ |
| 14 | + dir_containing_this_module + "/" + folder, |
| 15 | + ]) |
| 16 | + for package in all_packages: |
| 17 | + print(package) |
| 18 | + module = importlib.import_module("." + package.name, ".examples." + folder) |
| 19 | + for name, obj in inspect.getmembers(module, inspect.isclass): |
| 20 | + if obj.__module__ != module.__name__: |
| 21 | + continue |
| 22 | + # print(Example is obj.__bases__[0]) |
| 23 | + # TODO - comparing the same class imported two different ways fails |
| 24 | + # There might a better way to do this |
| 25 | + print("Found class has these base classes:", obj.__mro__) |
| 26 | + if "Example" not in [obj.__name__ for obj in obj.__mro__]: |
| 27 | + continue |
| 28 | + if not hasattr(obj, "run") or not callable(getattr(obj, "run")): |
| 29 | + continue |
| 30 | + |
| 31 | + print("Class found:", obj) |
| 32 | + example_classes.append(obj) |
26 | 33 |
|
27 | 34 | if len(sys.argv) == 2: |
28 | 35 | example_classes = [cls for cls in example_classes if cls.__name__ == sys.argv[1]] |
|
0 commit comments