Skip to content

Commit bbc83fb

Browse files
committed
feat(run): allow a custom state dir
1 parent d3a0489 commit bbc83fb

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

questionpy_sdk/commands/run.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
# This file is part of the QuestionPy SDK. (https://questionpy.org)
22
# The QuestionPy SDK is free software released under terms of the MIT license. See LICENSE.md.
33
# (c) Technische Universität Berlin, innoCampus <[email protected]>
4-
54
from pathlib import Path
65

76
import click
87

98
from questionpy_sdk.commands._helper import get_package_location
10-
from questionpy_sdk.webserver.app import WebServer
9+
from questionpy_sdk.webserver.app import DEFAULT_STATE_STORAGE_PATH, WebServer
1110

1211

1312
@click.command()
1413
@click.argument("package")
15-
def run(package: str) -> None:
14+
@click.option(
15+
"--state-storage-path",
16+
type=click.Path(path_type=Path, exists=False, file_okay=False, dir_okay=True, resolve_path=True),
17+
default=DEFAULT_STATE_STORAGE_PATH,
18+
envvar="QPY_STATE_STORAGE_PATH",
19+
)
20+
def run(package: str, state_storage_path: Path) -> None:
1621
"""Run a package.
1722
1823
\b
@@ -22,5 +27,5 @@ def run(package: str) -> None:
2227
- a source directory (built on-the-fly).
2328
""" # noqa: D301
2429
pkg_path = Path(package).resolve()
25-
web_server = WebServer(get_package_location(package, pkg_path))
30+
web_server = WebServer(get_package_location(package, pkg_path), state_storage_path)
2631
web_server.start_server()

questionpy_sdk/webserver/app.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,14 @@ class StateFilename(StrEnum):
5151
LAST_ATTEMPT_DATA = "last_attempt_data.json"
5252

5353

54+
DEFAULT_STATE_STORAGE_PATH = Path(__file__).parent / "question_state_storage"
55+
56+
5457
class WebServer:
5558
def __init__(
5659
self,
5760
package_location: PackageLocation,
58-
state_storage_path: Path = Path(__file__).parent / "question_state_storage",
61+
state_storage_path: Path,
5962
) -> None:
6063
# We import here, so we don't have to work around circular imports.
6164
from questionpy_sdk.webserver.routes.attempt import routes as attempt_routes # noqa: PLC0415

0 commit comments

Comments
 (0)