marimo-gradescope 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. marimo_gradescope-0.1.0/PKG-INFO +17 -0
  2. marimo_gradescope-0.1.0/pyproject.toml +93 -0
  3. marimo_gradescope-0.1.0/pyproject.toml.orig +82 -0
  4. marimo_gradescope-0.1.0/src/marimo_gradescope/__init__.py +9 -0
  5. marimo_gradescope-0.1.0/src/marimo_gradescope/_assertrewrite.py +44 -0
  6. marimo_gradescope-0.1.0/src/marimo_gradescope/_env.py +26 -0
  7. marimo_gradescope-0.1.0/src/marimo_gradescope/_run.py +111 -0
  8. marimo_gradescope-0.1.0/src/marimo_gradescope/_typst/preview/cmarker/0.1.10/LICENSE +7 -0
  9. marimo_gradescope-0.1.0/src/marimo_gradescope/_typst/preview/cmarker/0.1.10/lib.typ +462 -0
  10. marimo_gradescope-0.1.0/src/marimo_gradescope/_typst/preview/cmarker/0.1.10/plugin.wasm +0 -0
  11. marimo_gradescope-0.1.0/src/marimo_gradescope/_typst/preview/cmarker/0.1.10/typst.toml +11 -0
  12. marimo_gradescope-0.1.0/src/marimo_gradescope/_typst/preview/mitex/0.2.7/LICENSE +176 -0
  13. marimo_gradescope-0.1.0/src/marimo_gradescope/_typst/preview/mitex/0.2.7/lib.typ +1 -0
  14. marimo_gradescope-0.1.0/src/marimo_gradescope/_typst/preview/mitex/0.2.7/mitex.typ +45 -0
  15. marimo_gradescope-0.1.0/src/marimo_gradescope/_typst/preview/mitex/0.2.7/mitex.wasm +0 -0
  16. marimo_gradescope-0.1.0/src/marimo_gradescope/_typst/preview/mitex/0.2.7/specs/latex/standard.typ +1187 -0
  17. marimo_gradescope-0.1.0/src/marimo_gradescope/_typst/preview/mitex/0.2.7/specs/mod.typ +12 -0
  18. marimo_gradescope-0.1.0/src/marimo_gradescope/_typst/preview/mitex/0.2.7/specs/prelude.typ +230 -0
  19. marimo_gradescope-0.1.0/src/marimo_gradescope/_typst/preview/mitex/0.2.7/typst.toml +12 -0
  20. marimo_gradescope-0.1.0/src/marimo_gradescope/build.py +381 -0
  21. marimo_gradescope-0.1.0/src/marimo_gradescope/check.py +252 -0
  22. marimo_gradescope-0.1.0/src/marimo_gradescope/cli.py +115 -0
  23. marimo_gradescope-0.1.0/src/marimo_gradescope/config.py +492 -0
  24. marimo_gradescope-0.1.0/src/marimo_gradescope/export.py +450 -0
  25. marimo_gradescope-0.1.0/src/marimo_gradescope/grader/__init__.py +1 -0
  26. marimo_gradescope-0.1.0/src/marimo_gradescope/grader/_process.py +381 -0
  27. marimo_gradescope-0.1.0/src/marimo_gradescope/grader/_user.py +7 -0
  28. marimo_gradescope-0.1.0/src/marimo_gradescope/grader/bundle.py +320 -0
  29. marimo_gradescope-0.1.0/src/marimo_gradescope/grader/child.py +306 -0
  30. marimo_gradescope-0.1.0/src/marimo_gradescope/grader/datafiles.py +54 -0
  31. marimo_gradescope-0.1.0/src/marimo_gradescope/grader/main.py +132 -0
  32. marimo_gradescope-0.1.0/src/marimo_gradescope/grader/protocol.py +175 -0
  33. marimo_gradescope-0.1.0/src/marimo_gradescope/grader/results.py +269 -0
  34. marimo_gradescope-0.1.0/src/marimo_gradescope/grader/sandbox.py +419 -0
  35. marimo_gradescope-0.1.0/src/marimo_gradescope/grader/templates/__init__.py +38 -0
  36. marimo_gradescope-0.1.0/src/marimo_gradescope/grader/templates/run_autograder +3 -0
  37. marimo_gradescope-0.1.0/src/marimo_gradescope/grader/templates/setup.sh +28 -0
  38. marimo_gradescope-0.1.0/src/marimo_gradescope/loader.py +200 -0
  39. marimo_gradescope-0.1.0/src/marimo_gradescope/pdf.py +511 -0
  40. marimo_gradescope-0.1.0/src/marimo_gradescope/requirements.py +231 -0
  41. marimo_gradescope-0.1.0/src/marimo_gradescope/runner.py +235 -0
  42. marimo_gradescope-0.1.0/src/marimo_gradescope/selfcheck.py +126 -0
  43. marimo_gradescope-0.1.0/src/marimo_gradescope/source.py +853 -0
  44. marimo_gradescope-0.1.0/src/marimo_gradescope/transform.py +495 -0
@@ -0,0 +1,17 @@
1
+ Metadata-Version: 2.4
2
+ Name: marimo-gradescope
3
+ Version: 0.1.0
4
+ Summary: Build Gradescope autograders from marimo notebooks.
5
+ Author: Agustinus Kristiadi
6
+ Author-email: Agustinus Kristiadi <agustinus@kristia.de>
7
+ License-Expression: MIT
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Operating System :: OS Independent
10
+ Classifier: Programming Language :: Python :: 3.13
11
+ Classifier: Programming Language :: Python :: 3.14
12
+ Requires-Dist: marimo
13
+ Requires-Dist: packaging>=24
14
+ Requires-Dist: pytest
15
+ Requires-Dist: typst>=0.15,<0.16 ; extra == 'pdf'
16
+ Requires-Python: >=3.13
17
+ Provides-Extra: pdf
@@ -0,0 +1,93 @@
1
+ [project]
2
+ name = "marimo-gradescope"
3
+ version = "0.1.0"
4
+ description = "Build Gradescope autograders from marimo notebooks."
5
+ license = "MIT"
6
+ requires-python = ">=3.13"
7
+ classifiers = [
8
+ "Development Status :: 3 - Alpha",
9
+ "Operating System :: OS Independent",
10
+ "Programming Language :: Python :: 3.13",
11
+ "Programming Language :: Python :: 3.14",
12
+ ]
13
+ dependencies = [
14
+ "marimo",
15
+ "packaging>=24",
16
+ "pytest",
17
+ ]
18
+
19
+ [[project.authors]]
20
+ name = "Agustinus Kristiadi"
21
+ email = "agustinus@kristia.de"
22
+
23
+ [project.scripts]
24
+ marimo-gradescope = "marimo_gradescope.cli:main"
25
+
26
+ [project.optional-dependencies]
27
+ pdf = ["typst>=0.15,<0.16"]
28
+
29
+ [build-system]
30
+ requires = ["uv_build>=0.13.0,<0.14"]
31
+ build-backend = "uv_build"
32
+
33
+ [dependency-groups]
34
+ dev = [
35
+ "pytest>=8",
36
+ "ty>=0.0.104",
37
+ "ruff>=0.14",
38
+ "pypdf>=5",
39
+ "marimo-gradescope[pdf]",
40
+ ]
41
+
42
+ [tool.ty.src]
43
+ include = [
44
+ "src",
45
+ "tests",
46
+ ]
47
+ exclude = ["tests/fixtures"]
48
+
49
+ [tool.ty.environment]
50
+ python-version = "3.13"
51
+
52
+ [tool.ruff]
53
+ line-length = 100
54
+ target-version = "py313"
55
+ extend-exclude = ["tests/fixtures/syntax_error.py"]
56
+
57
+ [tool.ruff.lint]
58
+ select = [
59
+ "E",
60
+ "F",
61
+ "I",
62
+ "UP",
63
+ "B",
64
+ "D",
65
+ ]
66
+ ignore = [
67
+ "D100",
68
+ "D105",
69
+ "D107",
70
+ "D202",
71
+ ]
72
+
73
+ [tool.ruff.lint.pydocstyle]
74
+ convention = "google"
75
+
76
+ [tool.ruff.lint.per-file-ignores]
77
+ "tests/**" = ["D"]
78
+ "examples/**" = ["D"]
79
+
80
+ [tool.pytest.ini_options]
81
+ testpaths = ["tests"]
82
+ markers = [
83
+ "slow: runs marimo in a subprocess through `uv run --with` (network on a cold cache)",
84
+ "network: resolves packages from PyPI through uv (fast with a warm cache)",
85
+ "docker: grades in Gradescope's base image with docker or podman (deselected unless `-m` names `docker`)",
86
+ ]
87
+
88
+ [tool.uv]
89
+ required-environments = [
90
+ "sys_platform == 'linux' and platform_machine == 'x86_64'",
91
+ "sys_platform == 'darwin' and platform_machine == 'arm64'",
92
+ "sys_platform == 'win32' and platform_machine == 'AMD64'",
93
+ ]
@@ -0,0 +1,82 @@
1
+ [project]
2
+ name = "marimo-gradescope"
3
+ version = "0.1.0"
4
+ description = "Build Gradescope autograders from marimo notebooks."
5
+ authors = [{ name = "Agustinus Kristiadi", email = "agustinus@kristia.de" }]
6
+ license = "MIT"
7
+ requires-python = ">=3.13"
8
+ classifiers = [
9
+ "Development Status :: 3 - Alpha",
10
+ "Operating System :: OS Independent",
11
+ "Programming Language :: Python :: 3.13",
12
+ "Programming Language :: Python :: 3.14",
13
+ ]
14
+ dependencies = [
15
+ "marimo",
16
+ "packaging>=24",
17
+ "pytest",
18
+ ]
19
+
20
+ [project.scripts]
21
+ marimo-gradescope = "marimo_gradescope.cli:main"
22
+
23
+ [project.optional-dependencies]
24
+ # The vendored Typst packages in `_typst` need Typst 0.15.
25
+ pdf = ["typst>=0.15,<0.16"]
26
+
27
+ [build-system]
28
+ requires = ["uv_build>=0.13.0,<0.14"]
29
+ build-backend = "uv_build"
30
+
31
+ [dependency-groups]
32
+ dev = [
33
+ "pytest>=8",
34
+ "ty>=0.0.104",
35
+ "ruff>=0.14",
36
+ "pypdf>=5",
37
+ # The PDF tests need the pdf extra.
38
+ "marimo-gradescope[pdf]",
39
+ ]
40
+
41
+ [tool.ty.src]
42
+ include = ["src", "tests"]
43
+ # Fixtures are notebooks under test, not code to type-check.
44
+ exclude = ["tests/fixtures"]
45
+
46
+ [tool.ty.environment]
47
+ python-version = "3.13"
48
+
49
+ [tool.ruff]
50
+ line-length = 100
51
+ target-version = "py313"
52
+ # A fixture that must fail to parse.
53
+ extend-exclude = ["tests/fixtures/syntax_error.py"]
54
+
55
+ [tool.ruff.lint]
56
+ select = ["E", "F", "I", "UP", "B", "D"]
57
+ # D100: not every module needs a docstring. D105, D107: dunders and `__init__` are covered
58
+ # by the class docstring. D202: the house style puts a blank line after a function's docstring.
59
+ ignore = ["D100", "D105", "D107", "D202"]
60
+
61
+ [tool.ruff.lint.pydocstyle]
62
+ convention = "google"
63
+
64
+ [tool.ruff.lint.per-file-ignores]
65
+ "tests/**" = ["D"]
66
+ "examples/**" = ["D"]
67
+
68
+ [tool.pytest.ini_options]
69
+ testpaths = ["tests"]
70
+ markers = [
71
+ "slow: runs marimo in a subprocess through `uv run --with` (network on a cold cache)",
72
+ "network: resolves packages from PyPI through uv (fast with a warm cache)",
73
+ "docker: grades in Gradescope's base image with docker or podman (deselected unless `-m` names `docker`)",
74
+ ]
75
+
76
+ [tool.uv]
77
+ # The lockfile must install on every CI platform: Linux, macOS and Windows.
78
+ required-environments = [
79
+ "sys_platform == 'linux' and platform_machine == 'x86_64'",
80
+ "sys_platform == 'darwin' and platform_machine == 'arm64'",
81
+ "sys_platform == 'win32' and platform_machine == 'AMD64'",
82
+ ]
@@ -0,0 +1,9 @@
1
+ """Gradescope autograding for marimo notebooks."""
2
+
3
+ from importlib.metadata import version
4
+
5
+ from marimo_gradescope.check import check
6
+ from marimo_gradescope.export import export, export_button
7
+
8
+ __all__ = ["check", "export", "export_button"]
9
+ __version__ = version("marimo-gradescope")
@@ -0,0 +1,44 @@
1
+ """Compile test source with pytest's assertion rewriting.
2
+
3
+ This is the only module that imports the private `_pytest` package, so a change in pytest's
4
+ internals breaks one place, and `tests/test_assertrewrite_guard.py` catches it.
5
+ """
6
+
7
+ import ast
8
+ import hashlib
9
+ import linecache
10
+ from types import CodeType
11
+
12
+ from _pytest.assertion.rewrite import rewrite_asserts
13
+
14
+
15
+ def compile_tests(source: str, filename: str) -> CodeType:
16
+ """Compile test source so failing asserts explain their values.
17
+
18
+ The source is registered in `linecache` under `<mgs-tests-H:filename>`, where `H` is a hash
19
+ of the source, and that name is the code's file name, so tracebacks and failure messages
20
+ show its lines. Different sources get different names, so no other source, and no real
21
+ file, can replace these lines. The same source gets the same name, so compiling it again,
22
+ as a re-run notebook check does, reuses the entry instead of adding one.
23
+ Line numbers count from the first line of `source`.
24
+
25
+ Args:
26
+ source: Module-like source, e.g. one or more `def test_*` functions.
27
+ filename: Label kept inside the generated file name.
28
+
29
+ Returns:
30
+ A module code object to run with `exec`.
31
+
32
+ Raises:
33
+ SyntaxError: The source does not parse.
34
+ """
35
+
36
+ digest = hashlib.sha1(source.encode(errors="surrogatepass")).hexdigest()[:12]
37
+ name = f"<mgs-tests-{digest}:{filename}>"
38
+ tree = ast.parse(source, name)
39
+ rewrite_asserts(tree, source.encode())
40
+
41
+ # `mtime=None` keeps the entry through `linecache.checkcache`.
42
+ linecache.cache[name] = (len(source), None, source.splitlines(keepends=True), name)
43
+
44
+ return compile(tree, name, "exec", dont_inherit=True)
@@ -0,0 +1,26 @@
1
+ """Environment of the processes this package starts, and the flag they read."""
2
+
3
+ import os
4
+
5
+ GRADING = "MGS_GRADING"
6
+
7
+
8
+ def clean_env() -> dict[str, str]:
9
+ """The current environment without `PYTEST_CURRENT_TEST`.
10
+
11
+ marimo acts as if under test when that variable is set.
12
+ """
13
+
14
+ return {key: value for key, value in os.environ.items() if key != "PYTEST_CURRENT_TEST"}
15
+
16
+
17
+ def grading_env() -> dict[str, str]:
18
+ """`clean_env()` plus the flag that turns `check` and `export` into no-ops."""
19
+
20
+ return clean_env() | {GRADING: "1"}
21
+
22
+
23
+ def grading() -> bool:
24
+ """Whether this process runs tests for a grader or a self-check, not for a student."""
25
+
26
+ return os.environ.get(GRADING) == "1"
@@ -0,0 +1,111 @@
1
+ """Run a helper command from the student's kernel without risking a hang.
2
+
3
+ Works on Linux, macOS and Windows: no timers, no resource limits.
4
+ """
5
+
6
+ import os
7
+ import signal
8
+ import subprocess
9
+ import sys
10
+ import tempfile
11
+ from pathlib import Path
12
+ from typing import IO
13
+
14
+ from marimo_gradescope._env import grading_env
15
+
16
+
17
+ def run_capped(
18
+ command: list[str], *, cwd: Path, timeout: float
19
+ ) -> subprocess.CompletedProcess[str] | None:
20
+ """Run `command` and capture its output, killing it after `timeout` seconds.
21
+
22
+ Output goes to temporary files, not pipes, so a grandchild that keeps a pipe open cannot
23
+ block the wait. On a timeout or any exception, `KeyboardInterrupt` included, the process
24
+ is killed before the exception propagates: with its whole process group on Linux and
25
+ macOS, with its process tree (`taskkill /T`) on Windows. The command runs with
26
+ `MGS_GRADING=1`, so `check` and `export` cells do nothing if it runs the notebook.
27
+
28
+ Args:
29
+ command: The command and its arguments.
30
+ cwd: Working directory.
31
+ timeout: Seconds to wait before killing the process.
32
+
33
+ Returns:
34
+ The finished process with decoded output, or `None` when it timed out.
35
+ """
36
+
37
+ # Bytecode caches would land next to the student's notebook.
38
+ env = grading_env() | {"PYTHONDONTWRITEBYTECODE": "1", "PYTHONIOENCODING": "utf-8"}
39
+
40
+ with tempfile.TemporaryFile() as out, tempfile.TemporaryFile() as err:
41
+ process = _start(command, cwd, env, out, err)
42
+
43
+ try:
44
+ returncode = process.wait(timeout)
45
+ except subprocess.TimeoutExpired:
46
+ return None
47
+ finally:
48
+ _kill_tree(process)
49
+
50
+ out.seek(0)
51
+ err.seek(0)
52
+
53
+ return subprocess.CompletedProcess(
54
+ command,
55
+ returncode,
56
+ out.read().decode(errors="replace"),
57
+ err.read().decode(errors="replace"),
58
+ )
59
+
60
+
61
+ def _start(
62
+ command: list[str], cwd: Path, env: dict[str, str], out: IO[bytes], err: IO[bytes]
63
+ ) -> subprocess.Popen[bytes]:
64
+ """Start `command` in a process group of its own."""
65
+
66
+ if sys.platform == "win32":
67
+ return subprocess.Popen(
68
+ command,
69
+ cwd=cwd,
70
+ env=env,
71
+ stdin=subprocess.DEVNULL,
72
+ stdout=out,
73
+ stderr=err,
74
+ creationflags=subprocess.CREATE_NEW_PROCESS_GROUP,
75
+ )
76
+
77
+ return subprocess.Popen(
78
+ command,
79
+ cwd=cwd,
80
+ env=env,
81
+ stdin=subprocess.DEVNULL,
82
+ stdout=out,
83
+ stderr=err,
84
+ start_new_session=True,
85
+ )
86
+
87
+
88
+ def _kill_tree(process: subprocess.Popen[bytes]) -> None:
89
+ """Kill the process and what it started, then reap it.
90
+
91
+ On Linux and macOS the whole group goes, even after the process itself exited, so a
92
+ grandchild it left behind does not outlive it.
93
+ """
94
+
95
+ if sys.platform == "win32":
96
+ if process.poll() is None:
97
+ subprocess.run(
98
+ ["taskkill", "/F", "/T", "/PID", str(process.pid)],
99
+ capture_output=True,
100
+ check=False,
101
+ )
102
+ else:
103
+ try:
104
+ os.killpg(process.pid, signal.SIGKILL)
105
+ except (ProcessLookupError, PermissionError):
106
+ pass
107
+
108
+ if process.poll() is None:
109
+ process.kill()
110
+
111
+ process.wait()
@@ -0,0 +1,7 @@
1
+ Copyright 2023 Sabrina Jewson
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.