def test_pex_execution(self) -> None: input_files_content = InputFilesContent( ( FileContent(path="main.py", content=b'print("from main")'), FileContent(path="subdir/sub.py", content=b'print("from sub")'), ) ) input_files = self.request_single_product(Digest, input_files_content) pex_output = self.create_pex_and_get_all_data(entry_point="main", input_files=input_files) pex_files = pex_output["files"] self.assertTrue("pex" not in pex_files) self.assertTrue("main.py" in pex_files) self.assertTrue("subdir/sub.py" in pex_files) init_subsystem(PythonSetup) python_setup = PythonSetup.global_instance() env = {"PATH": create_path_env_var(python_setup.interpreter_search_paths)} req = ExecuteProcessRequest( argv=("python", "test.pex"), env=env, input_files=pex_output["pex"].directory_digest, description="Run the pex and make sure it works", ) result = self.request_single_product(ExecuteProcessResult, req) self.assertEqual(result.stdout, b"from main\n")
def test_is_python2(constraints, compatibilities): Subsystem.reset() init_subsystem( PythonSetup, { PythonSetup.options_scope: { "interpreter_constraints": RankedValue(Rank.CONFIG, constraints) } }, ) assert is_python2(compatibilities, PythonSetup.global_instance())
def create(cls, builder, log=None): options = cls.global_instance().get_options() setuptools_requirement = f"setuptools=={options.setuptools_version}" log = log or logging.getLogger(__name__) return PexBuilderWrapper( builder=builder, python_repos_subsystem=PythonRepos.global_instance(), python_setup_subsystem=PythonSetup.global_instance(), setuptools_requirement=PythonRequirement( setuptools_requirement), log=log, )
def _acceptable_interpreter_constraints(self): default_constraints = PythonSetup.global_instance( ).interpreter_constraints whitelisted_constraints = self.get_options( ).interpreter_constraints_whitelist # The user wants to lint everything. if whitelisted_constraints == []: return [] # The user did not pass a whitelist option. elif whitelisted_constraints is None: whitelisted_constraints = () return [ version.parse(v) for v in default_constraints + whitelisted_constraints ]
def _python_setup(self): return PythonSetup.global_instance()
def _compatible_interpreter(self, unpacked_whls): constraints = PythonSetup.global_instance( ).compatibility_or_constraints(unpacked_whls.compatibility) allowable_interpreters = PythonInterpreterCache.global_instance( ).setup(filters=constraints) return min(allowable_interpreters)