MCPcopy Index your code
hub / github.com/RustPython/RustPython / _make_pkg

Method _make_pkg

Lib/test/test_runpy.py:230–257  ·  view source on GitHub ↗
(self, source, depth, mod_base="runpy_test",
                     *, namespace=False, parent_namespaces=False)

Source from the content-addressed store, hash-verified

228 return pkg_fname
229
230 def _make_pkg(self, source, depth, mod_base="runpy_test",
231 *, namespace=False, parent_namespaces=False):
232 # Enforce a couple of internal sanity checks on test cases
233 if (namespace or parent_namespaces) and not depth:
234 raise RuntimeError("Can't mark top level module as a "
235 "namespace package")
236 pkg_name = "__runpy_pkg__"
237 test_fname = mod_base+os.extsep+"py"
238 pkg_dir = sub_dir = os.path.realpath(tempfile.mkdtemp())
239 if verbose > 1: print(" Package tree in:", sub_dir)
240 sys.path.insert(0, pkg_dir)
241 if verbose > 1: print(" Updated sys.path:", sys.path[0])
242 if depth:
243 namespace_flags = [parent_namespaces] * depth
244 namespace_flags[-1] = namespace
245 for namespace_flag in namespace_flags:
246 sub_dir = os.path.join(sub_dir, pkg_name)
247 pkg_fname = self._add_pkg_dir(sub_dir, namespace_flag)
248 if verbose > 1: print(" Next level in:", sub_dir)
249 if verbose > 1: print(" Created:", pkg_fname)
250 mod_fname = os.path.join(sub_dir, test_fname)
251 with open(mod_fname, "w") as mod_file:
252 mod_file.write(source)
253 if verbose > 1: print(" Created:", mod_fname)
254 mod_name = (pkg_name+".")*depth + mod_base
255 mod_spec = importlib.util.spec_from_file_location(mod_name,
256 mod_fname)
257 return pkg_dir, mod_fname, mod_name, mod_spec
258
259 def _del_pkg(self, top):
260 for entry in list(sys.modules):

Calls 8

_add_pkg_dirMethod · 0.95
realpathMethod · 0.80
mkdtempMethod · 0.80
printFunction · 0.50
openFunction · 0.50
insertMethod · 0.45
joinMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected