markdown-exec 1.8.1__py3-none-any.whl → 1.8.2__py3-none-any.whl
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.
- markdown_exec/formatters/python.py +12 -0
- {markdown_exec-1.8.1.dist-info → markdown_exec-1.8.2.dist-info}/METADATA +1 -1
- {markdown_exec-1.8.1.dist-info → markdown_exec-1.8.2.dist-info}/RECORD +6 -6
- {markdown_exec-1.8.1.dist-info → markdown_exec-1.8.2.dist-info}/WHEEL +1 -1
- {markdown_exec-1.8.1.dist-info → markdown_exec-1.8.2.dist-info}/entry_points.txt +0 -0
- {markdown_exec-1.8.1.dist-info → markdown_exec-1.8.2.dist-info}/licenses/LICENSE +0 -0
@@ -2,10 +2,13 @@
|
|
2
2
|
|
3
3
|
from __future__ import annotations
|
4
4
|
|
5
|
+
import re
|
6
|
+
import sys
|
5
7
|
import traceback
|
6
8
|
from collections import defaultdict
|
7
9
|
from functools import partial
|
8
10
|
from io import StringIO
|
11
|
+
from types import ModuleType
|
9
12
|
from typing import Any
|
10
13
|
|
11
14
|
from markdown_exec.formatters.base import ExecutionError, base_format
|
@@ -51,6 +54,15 @@ def _run_python(
|
|
51
54
|
_code_blocks[code_block_id] = code.split("\n")
|
52
55
|
exec_globals = _sessions_globals[session] if session else {}
|
53
56
|
|
57
|
+
# Other libraries expect functions to have a valid `__module__` attribute.
|
58
|
+
# To achieve this, we need to add a `__name__` attribute to the globals.
|
59
|
+
# We compute the name from the code block ID, replacing invalid characters with `_`.
|
60
|
+
# We also create a module object with the same name and add it to `sys.modules`,
|
61
|
+
# because that's what yet other libraries expect (`dataclasses` for example).
|
62
|
+
module_name = re.sub(r"[^a-zA-Z\d]+", "_", code_block_id)
|
63
|
+
exec_globals["__name__"] = module_name
|
64
|
+
sys.modules[module_name] = ModuleType(module_name)
|
65
|
+
|
54
66
|
buffer = StringIO()
|
55
67
|
exec_globals["print"] = partial(_buffer_print, buffer)
|
56
68
|
|
@@ -1,7 +1,7 @@
|
|
1
|
-
markdown_exec-1.8.
|
2
|
-
markdown_exec-1.8.
|
3
|
-
markdown_exec-1.8.
|
4
|
-
markdown_exec-1.8.
|
1
|
+
markdown_exec-1.8.2.dist-info/METADATA,sha256=tx7RBQpDl8CiB4TV2Zm8xFjldQKCDCuClMd17bth-l8,4954
|
2
|
+
markdown_exec-1.8.2.dist-info/WHEEL,sha256=vnE8JVcI2Wz7GRKorsPArnBdnW2SWKWGow5gu5tHlRU,90
|
3
|
+
markdown_exec-1.8.2.dist-info/entry_points.txt,sha256=W-JWRoZzS5TXRcyVnxYmsaVBV4HSl7B_7uTgtaZ-Pms,81
|
4
|
+
markdown_exec-1.8.2.dist-info/licenses/LICENSE,sha256=eZQBcJKqlN0QepmOi0u09hlqKMPFdzWjY6NUWYeJGZs,754
|
5
5
|
markdown_exec/__init__.py,sha256=cdQDNiSeWnQ8NK3hqNOfyxKT8uoxLkKm4VI_8E7ztcM,4366
|
6
6
|
markdown_exec/ansi.css,sha256=6PTJxTSsExVgPbMySCuKjih0gr-fdfx2aZ9--u7zWf0,8090
|
7
7
|
markdown_exec/debug.py,sha256=dy0bTd9mTTyTaWuUGNkH0UUdMp2ZThsmGh5q9wt9O0c,2840
|
@@ -12,7 +12,7 @@ markdown_exec/formatters/console.py,sha256=D2JBIC4MU0ct2MiRCkBO-qo4MiH6Hjy6LXjYA
|
|
12
12
|
markdown_exec/formatters/markdown.py,sha256=pd0akvFGUXrc41NABcHUTTkKFA3k5Ju8im-b3kzOvIw,276
|
13
13
|
markdown_exec/formatters/pycon.py,sha256=F9xpSRKFWsVpGu5XXybtCkMMJ_PAfyd48Qqo1SWl6RA,854
|
14
14
|
markdown_exec/formatters/pyodide.py,sha256=fsAkEq9cgI_-AipV4tS4iXbaOcqQVi-HjJ-VcfMv6aE,2898
|
15
|
-
markdown_exec/formatters/python.py,sha256=
|
15
|
+
markdown_exec/formatters/python.py,sha256=Jm-_yUxJgeQcP80nom_NXS2juaeU34mRSluIUmxJUCg,3029
|
16
16
|
markdown_exec/formatters/sh.py,sha256=41kmwFjkyisWYmfJeBMC40kqhEe7sI2E0vvbO9ixjCg,876
|
17
17
|
markdown_exec/formatters/tree.py,sha256=4XU1KaNqChkkNxMYanwy6glTE2uwcY8Mz9jBZiIf3zY,2046
|
18
18
|
markdown_exec/logger.py,sha256=e06Ih9EonG3KCAPbwraCEYmS0Nt9yRytyMjVJMAREIQ,2109
|
@@ -22,4 +22,4 @@ markdown_exec/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
22
22
|
markdown_exec/pyodide.css,sha256=rJ-HW-ymcgUfrZ9Mm6QB1qo6eE-I3YQcqSxTmG1NhvM,849
|
23
23
|
markdown_exec/pyodide.js,sha256=6iL-9xA4b9UeZgsxVYq_BiCE-Bwu58NfYwYCzz9C9j0,3845
|
24
24
|
markdown_exec/rendering.py,sha256=ssWg6U-7Ez45N6sLak-oGD2e55qtEkPY8T8l7h1RbDM,9459
|
25
|
-
markdown_exec-1.8.
|
25
|
+
markdown_exec-1.8.2.dist-info/RECORD,,
|
File without changes
|
File without changes
|