|
| 1 | +import traitlets.config |
| 2 | + |
| 3 | +from grader_service.autograding.kube.kube_grader import KubeAutogradeExecutor |
| 4 | +from grader_service.autograding.local_grader import LocalAutogradeExecutor |
1 | 5 | from grader_service.handlers.base_handler import GraderBaseHandler, authorize |
2 | 6 | from grader_service.orm.takepart import Scope |
3 | 7 | from grader_service.registry import VersionSpecifier, register_handler |
4 | 8 |
|
5 | 9 |
|
6 | | -def _get_effective_executor_value(app_cfg, executor_class, trait_name): |
| 10 | +def _get_effective_executor_value( |
| 11 | + app_cfg: traitlets.config.Config, |
| 12 | + executor_class: type[LocalAutogradeExecutor] | type[KubeAutogradeExecutor], |
| 13 | + trait_name, |
| 14 | +): |
7 | 15 | """ |
8 | 16 | Return the configured value for trait_name if present in app_cfg, |
9 | 17 | otherwise return the class default pulled from the trait metadata. |
10 | 18 | """ |
11 | | - # app_cfg is a traitlets.config.Config object (mapping-like) |
12 | | - # executor_class is the class (LocalAutogradeExecutor or similar) |
13 | 19 |
|
14 | | - # 1) look up the per-class node as a mapping (not attribute access) |
15 | | - user_node = app_cfg.get(executor_class.__name__, None) |
| 20 | + # 1) retrieve the provided class field from the config |
| 21 | + executor_class_field = app_cfg.get(executor_class.__name__, None) |
16 | 22 |
|
17 | | - # user_node may be None, or a Config object / dict-like. Use mapping access. |
18 | | - if user_node is not None and trait_name in user_node: |
19 | | - # Use .get to return the exact user-supplied value (won't be a lazy object) |
20 | | - return user_node.get(trait_name) |
| 23 | + # executor_class_field may be None, or a Config object / dict-like. Use mapping access. |
| 24 | + if executor_class_field is not None and trait_name in executor_class_field: |
| 25 | + return executor_class_field.get(trait_name) |
21 | 26 |
|
22 | 27 | # 2) fallback to the trait's default from the class metadata |
23 | 28 | return executor_class.class_traits()[trait_name].default() |
|
0 commit comments