Skip to content

Commit c0b033e

Browse files
WIP: initial API endpoint for config
1 parent bccf0a9 commit c0b033e

File tree

1 file changed

+40
-6
lines changed

1 file changed

+40
-6
lines changed

grader_service/handlers/config.py

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,50 @@
33
from grader_service.registry import VersionSpecifier, register_handler
44

55

6+
def _get_trait_default_from_class(cls, trait_name):
7+
traits = cls.class_traits()
8+
return traits[trait_name].default()
9+
10+
11+
def _get_effective_executor_value(app_cfg, executor_class, trait_name):
12+
"""
13+
Return the configured value for trait_name if present in app_cfg,
14+
otherwise return the class default pulled from the trait metadata.
15+
"""
16+
# app_cfg is a traitlets.config.Config object (mapping-like)
17+
# executor_class is the class (LocalAutogradeExecutor or similar)
18+
19+
# 1) look up the per-class node as a mapping (not attribute access)
20+
user_node = app_cfg.get(executor_class.__name__, None)
21+
22+
# user_node may be None, or a Config object / dict-like. Use mapping access.
23+
if user_node is not None and trait_name in user_node:
24+
# Use .get to return the exact user-supplied value (won't be a lazy object)
25+
return user_node.get(trait_name)
26+
27+
# 2) fallback to the trait's default from the class metadata
28+
return _get_trait_default_from_class(executor_class, trait_name)
29+
30+
631
@register_handler(path=r"\/api\/config\/?", version_specifier=VersionSpecifier.ALL)
732
class ConfigHandler(GraderBaseHandler):
833
"""
934
Handler class for requests to /config
1035
"""
1136

12-
@authorize([Scope.student, Scope.tutor, Scope.instructor])
37+
# todo: ask if this is correct
38+
@authorize([Scope.tutor, Scope.instructor])
1339
async def get(self):
14-
"""
15-
Gathers useful config for the grader labextension and returns it.
16-
:return: config in dict
17-
"""
18-
self.write({})
40+
app_cfg = self.application.config
41+
executor_class = app_cfg.RequestHandlerConfig.autograde_executor_class
42+
43+
def resolve(name):
44+
return _get_effective_executor_value(app_cfg, executor_class, name)
45+
46+
self.write_json(
47+
{
48+
"default_cell_timeout": resolve("default_cell_timeout"),
49+
"min_cell_timeout": resolve("min_cell_timeout"),
50+
"max_cell_timeout": resolve("max_cell_timeout"),
51+
}
52+
)

0 commit comments

Comments
 (0)