MCPcopy
hub / github.com/pex-tool/pex / execute_script

Function execute_script

tests/test_interpreter.py:540–569  ·  view source on GitHub ↗
(
        max_shebang_length,  # type: int
        *extra_args  # type: str
    )

Source from the content-addressed store, hash-verified

538 python_exe = sys.executable
539
540 def execute_script(
541 max_shebang_length, # type: int
542 *extra_args # type: str
543 ):
544 # type: (...) -> str
545 with open(os.path.join(str(tmpdir), "script.py"), "w") as fp:
546 fp.write(
547 dedent(
548 """\
549 {shebang}
550
551 import json
552 import sys
553
554
555 with open(sys.argv[0]) as fp:
556 json.dump(dict(shebang=fp.readline(), argv=sys.argv), sys.stdout)
557 """
558 ).format(
559 shebang=create_shebang(
560 python_exe=python_exe, max_shebang_length=max_shebang_length
561 )
562 )
563 )
564 chmod_plus_x(fp.name)
565 result = json.loads(
566 subprocess.check_output(args=[fp.name] + list(extra_args)).decode("utf-8")
567 )
568 assert [fp.name] + list(extra_args) == result["argv"]
569 return cast(str, result["shebang"])
570
571 assert "#!{python_exe}\n".format(python_exe=python_exe) == execute_script(len(python_exe) * 2)
572 assert "#!{python_exe}\n".format(python_exe=python_exe) == execute_script(

Callers 1

test_create_shebangFunction · 0.85

Calls 6

create_shebangFunction · 0.90
chmod_plus_xFunction · 0.90
castFunction · 0.90
decodeMethod · 0.80
joinMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected