MCPcopy Index your code
hub / github.com/python/cpython / setup_module

Function setup_module

Lib/test/test_importlib/test_windows.py:56–84  ·  view source on GitHub ↗
(machinery, name, path=None)

Source from the content-addressed store, hash-verified

54
55@contextmanager
56def setup_module(machinery, name, path=None):
57 if machinery.WindowsRegistryFinder.DEBUG_BUILD:
58 root = machinery.WindowsRegistryFinder.REGISTRY_KEY_DEBUG
59 else:
60 root = machinery.WindowsRegistryFinder.REGISTRY_KEY
61 key = root.format(fullname=name,
62 sys_version='%d.%d' % sys.version_info[:2])
63 base_key = "Software\\Python\\PythonCore\\{}.{}".format(
64 sys.version_info.major, sys.version_info.minor)
65 assert key.casefold().startswith(base_key.casefold()), (
66 "expected key '{}' to start with '{}'".format(key, base_key))
67 try:
68 with temp_module(name, "a = 1") as location:
69 try:
70 OpenKey(HKEY_CURRENT_USER, base_key)
71 if machinery.WindowsRegistryFinder.DEBUG_BUILD:
72 delete_key = os.path.dirname(key)
73 else:
74 delete_key = key
75 except OSError:
76 delete_key = base_key
77 subkey = CreateKey(HKEY_CURRENT_USER, key)
78 if path is None:
79 path = location + ".py"
80 SetValue(subkey, "", REG_SZ, path)
81 yield
82 finally:
83 if delete_key:
84 delete_registry_tree(HKEY_CURRENT_USER, delete_key)
85
86
87@unittest.skipUnless(sys.platform.startswith('win'), 'requires Windows')

Callers 2

test_module_foundMethod · 0.70
test_module_not_foundMethod · 0.70

Calls 6

temp_moduleFunction · 0.90
delete_registry_treeFunction · 0.85
casefoldMethod · 0.80
formatMethod · 0.45
startswithMethod · 0.45
dirnameMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…