Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/src/resources/jupyter/lang/python/cleanup.py
12923 views
1
2
# reset state
3
%reset
4
5
import sys
6
import types
7
import os
8
import json
9
10
# NOTE: the kernel_deps code is repeated in the setup.py file
11
# (we can't easily share this code b/c of the way it is run).
12
# If you edit this code also edit the same code in setup.py!
13
14
kernel_deps = dict()
15
for module in list(sys.modules.values()):
16
# Some modules play games with sys.modules (e.g. email/__init__.py
17
# in the standard library), and occasionally this can cause strange
18
# failures in getattr. Just ignore anything that's not an ordinary
19
# module.
20
if not isinstance(module, types.ModuleType):
21
continue
22
path = getattr(module, "__file__", None)
23
if not path:
24
continue
25
if path.endswith(".pyc") or path.endswith(".pyo"):
26
path = path[:-1]
27
if not os.path.exists(path):
28
continue
29
kernel_deps[path] = os.stat(path).st_mtime
30
print(json.dumps(kernel_deps))
31
32