Skip to content

Commit

Permalink
feat: add make_question_type_init
Browse files Browse the repository at this point in the history
Trivial init functions needn't be written manually by devs.
  • Loading branch information
MHajoha committed Jul 30, 2024
1 parent c898021 commit fd60891
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
6 changes: 2 additions & 4 deletions examples/full/python/local/full_example/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from questionpy import Package, QuestionTypeWrapper
from questionpy import make_question_type_init

from .question_type import ExampleQuestion


def init(package: Package) -> QuestionTypeWrapper:
return QuestionTypeWrapper(ExampleQuestion, package)
init = make_question_type_init(ExampleQuestion)
6 changes: 2 additions & 4 deletions examples/minimal/python/local/minimal_example/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# This file is part of the QuestionPy SDK. (https://questionpy.org)
# The QuestionPy SDK is free software released under terms of the MIT license. See LICENSE.md.
# (c) Technische Universität Berlin, innoCampus <[email protected]>
from questionpy import Package, QuestionTypeWrapper
from questionpy import make_question_type_init

from .question_type import ExampleQuestion


def init(package: Package) -> QuestionTypeWrapper:
return QuestionTypeWrapper(ExampleQuestion, package)
init = make_question_type_init(ExampleQuestion)
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from questionpy import Package, QuestionTypeWrapper
from questionpy import make_question_type_init

from .question_type import ExampleQuestion


def init(package: Package) -> QuestionTypeWrapper:
return QuestionTypeWrapper(ExampleQuestion, package)
init = make_question_type_init(ExampleQuestion)
8 changes: 8 additions & 0 deletions questionpy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# This file is part of the QuestionPy SDK. (https://questionpy.org)
# The QuestionPy SDK is free software released under terms of the MIT license. See LICENSE.md.
# (c) Technische Universität Berlin, innoCampus <[email protected]>
from collections.abc import Callable

from questionpy_common.api.attempt import (
AttemptFile,
Expand Down Expand Up @@ -87,5 +88,12 @@
"WorkerResourceLimits",
"create_jinja2_environment",
"get_qpy_environment",
"make_question_type_init",
"set_qpy_environment",
]


def make_question_type_init(
question_class: type[Question], *, wrap_question: Callable[[Question], QuestionInterface] = QuestionWrapper
) -> PackageInitFunction:
return lambda package, env: QuestionTypeWrapper(question_class, package, wrap_question=wrap_question)

0 comments on commit fd60891

Please sign in to comment.