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

Function make_zip_pkg

Lib/test/support/script_helper.py:274–302  ·  view source on GitHub ↗
(zip_dir, zip_basename, pkg_name, script_basename,
                 source, depth=1, compiled=False)

Source from the content-addressed store, hash-verified

272
273
274def make_zip_pkg(zip_dir, zip_basename, pkg_name, script_basename,
275 source, depth=1, compiled=False):
276 import zipfile
277 unlink = []
278 init_name = make_script(zip_dir, '__init__', '')
279 unlink.append(init_name)
280 init_basename = os.path.basename(init_name)
281 script_name = make_script(zip_dir, script_basename, source)
282 unlink.append(script_name)
283 if compiled:
284 init_name = py_compile.compile(init_name, doraise=True)
285 script_name = py_compile.compile(script_name, doraise=True)
286 unlink.extend((init_name, script_name))
287 pkg_names = [os.sep.join([pkg_name]*i) for i in range(1, depth+1)]
288 script_name_in_zip = os.path.join(pkg_names[-1], os.path.basename(script_name))
289 zip_filename = zip_basename+os.extsep+'zip'
290 zip_name = os.path.join(zip_dir, zip_filename)
291 with zipfile.ZipFile(zip_name, 'w') as zip_file:
292 for name in pkg_names:
293 init_name_in_zip = os.path.join(name, init_basename)
294 zip_file.write(init_name, init_name_in_zip)
295 zip_file.write(script_name, script_name_in_zip)
296 for name in unlink:
297 os.unlink(name)
298 #if test.support.verbose:
299 # with zipfile.ZipFile(zip_name, 'r') as zip_file:
300 # print 'Contents of %r:' % zip_name
301 # zip_file.printdir()
302 return zip_name, os.path.join(zip_name, script_name_in_zip)
303
304
305@support.requires_subprocess()

Calls 8

make_scriptFunction · 0.85
appendMethod · 0.45
basenameMethod · 0.45
compileMethod · 0.45
extendMethod · 0.45
joinMethod · 0.45
writeMethod · 0.45
unlinkMethod · 0.45

Tested by 3

_make_test_zip_pkgFunction · 0.72
_make_test_zip_pkgFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…