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

Method make_module

Lib/test/test_interpreters/utils.py:430–456  ·  view source on GitHub ↗
(self, name, pathentry=None, text=None)

Source from the content-addressed store, hash-verified

428 return filename
429
430 def make_module(self, name, pathentry=None, text=None):
431 if text:
432 text = dedent(text)
433 if pathentry is None:
434 pathentry = self.temp_dir()
435 else:
436 os.makedirs(pathentry, exist_ok=True)
437 *subnames, basename = name.split('.')
438
439 dirname = pathentry
440 for subname in subnames:
441 dirname = os.path.join(dirname, subname)
442 if os.path.isdir(dirname):
443 pass
444 elif os.path.exists(dirname):
445 raise Exception(dirname)
446 else:
447 os.mkdir(dirname)
448 initfile = os.path.join(dirname, '__init__.py')
449 if not os.path.exists(initfile):
450 with open(initfile, 'w'):
451 pass
452 filename = os.path.join(dirname, basename + '.py')
453
454 with open(filename, 'w', encoding='utf-8') as outfile:
455 outfile.write(text or '')
456 return filename
457
458 @support.requires_subprocess()
459 def run_python(self, *argv):

Callers 1

Calls 9

temp_dirMethod · 0.95
dedentFunction · 0.90
openFunction · 0.50
splitMethod · 0.45
joinMethod · 0.45
isdirMethod · 0.45
existsMethod · 0.45
mkdirMethod · 0.45
writeMethod · 0.45

Tested by 1