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

Function _copy_archive

Lib/zipapp.py:53–73  ·  view source on GitHub ↗

Copy an application archive, modifying the shebang line.

(archive, new_archive, interpreter=None)

Source from the content-addressed store, hash-verified

51
52
53def _copy_archive(archive, new_archive, interpreter=None):
54 """Copy an application archive, modifying the shebang line."""
55 with _maybe_open(archive, 'rb') as src:
56 # Skip the shebang line from the source.
57 # Read 2 bytes of the source and check if they are #!.
58 first_2 = src.read(2)
59 if first_2 == b'#!':
60 # Discard the initial 2 bytes and the rest of the shebang line.
61 first_2 = b''
62 src.readline()
63
64 with _maybe_open(new_archive, 'wb') as dst:
65 _write_file_prefix(dst, interpreter)
66 # If there was no shebang, "first_2" contains the first 2 bytes
67 # of the source file, so write them before copying the rest
68 # of the file.
69 dst.write(first_2)
70 shutil.copyfileobj(src, dst)
71
72 if interpreter and isinstance(new_archive, str):
73 os.chmod(new_archive, os.stat(new_archive).st_mode | stat.S_IEXEC)
74
75
76def create_archive(source, target=None, interpreter=None, main=None,

Callers 1

create_archiveFunction · 0.85

Calls 7

_maybe_openFunction · 0.85
_write_file_prefixFunction · 0.85
readMethod · 0.45
readlineMethod · 0.45
writeMethod · 0.45
chmodMethod · 0.45
statMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…