in xar/py_util.py [0:0]
def extract_python_archive_info(archive):
"""
Extracts the shebang (if any) from a python archive, along with the entry
point (if any). Returns a tuple (python_interpreter, entry_point).
Avoids interpreting the shebang in it doesn't contain 'python'.
"""
python = None
with open(archive, "rb") as f:
if f.read(2) == b"#!":
shebang = f.readline().decode("utf-8").strip()
if "python" in shebang:
python = shebang
with zipfile.ZipFile(archive) as zf:
# Ignores __pycache__ since .pyc in __pycache__ aren't executable
# without the .py.
MAIN = "__main__"
main_exists = any(xar_util.file_in_zip(zf, MAIN + ext) for ext in PYTHON_EXTS)
if main_exists:
return (python, MAIN)
return (python, None)