Path: blob/main/src/resources/jupyter/lang/python/cleanup.py
12923 views
1# reset state2%reset34import sys5import types6import os7import json89# NOTE: the kernel_deps code is repeated in the setup.py file10# (we can't easily share this code b/c of the way it is run).11# If you edit this code also edit the same code in setup.py!1213kernel_deps = dict()14for module in list(sys.modules.values()):15# Some modules play games with sys.modules (e.g. email/__init__.py16# in the standard library), and occasionally this can cause strange17# failures in getattr. Just ignore anything that's not an ordinary18# module.19if not isinstance(module, types.ModuleType):20continue21path = getattr(module, "__file__", None)22if not path:23continue24if path.endswith(".pyc") or path.endswith(".pyo"):25path = path[:-1]26if not os.path.exists(path):27continue28kernel_deps[path] = os.stat(path).st_mtime29print(json.dumps(kernel_deps))303132