I’m trying to build a pex, as part of a test, but ...
# general
c
I’m trying to build a pex, as part of a test, but fail due to no python in the env… [SOLVED] Any ideas what I’m missing? (will try to add relevant information in the thread)
The error being:
Copy code
E           Engine traceback:
E             in select
E             in pants.backend.docker.docker_build_context.create_docker_build_context
E             in pants.backend.python.goals.package_pex_binary.package_pex_binary (src/python/proj/cli:bin)
E             in pants.backend.python.util_rules.pex.create_pex
E             in pants.backend.python.util_rules.pex.build_pex (src.python.proj.cli/bin.pex)
E             in pants.engine.process.fallible_to_exec_result_or_raise
E           Traceback (most recent call last):
E             File "/private/var/folders/8j/c8jf_msj009947wyw82xvdkw0000gn/T/process-executionVc609f/src/python/pants/engine/process.py", line 258, in fallible_to_exec_result_or_raise
E               raise ProcessExecutionFailure(
E           pants.engine.process.ProcessExecutionFailure: Process 'Building src.python.proj.cli/bin.pex' failed with exit code 127.
E           stdout:
E           
E           stderr:
E           env: python: No such file or directory
My test is:
Copy code
def test_packaged_pex_path(rule_runner: RuleRunner) -> None:
    rule_runner.write_files(
        {
            "src/docker/BUILD": """docker_image(dependencies=["src/python/proj/cli:bin"])""",
            "src/docker/Dockerfile": """FROM python""",
            "src/python/proj/cli/BUILD": """pex_binary(name="bin", entry_point="main.py")""",
            "src/python/proj/cli/main.py": """print("cli main")""",
        }
    )

    assert_build_context(
        rule_runner,
        Address("src/docker", target_name="docker"),
        expected_files=["src/docker/Dockerfile", "src.python.proj.cli/bin.pex"],
    )
The
assert_build_context
requests this product from the rule runner:
Copy code
context = rule_runner.request(
        DockerBuildContext,
        [
            DockerBuildContextRequest(
                address=address,
                build_upstream_images=False,
            )
        ],
    )
And the rule runner has these rules:
Copy code
return RuleRunner(
        rules=[
            *context_rules(),
            *core_target_types_rules(),
            *package_pex_binary.rules(),
            *pex_from_targets.rules(),
            *target_types_rules.rules(),
            QueryRule(BuiltPackage, [PexBinaryFieldSet]),
            QueryRule(DockerBuildContext, (DockerBuildContextRequest,)),
        ],
        target_types=[DockerImage, Files, PexBinary],
    )
where most of those rules are taken from the
package_pex_binary_integration_test
.
Oh, the answer should be staring me in the eye, of course the tests in that integration test file does what I need already…
Yep, sorry, I tend to not see the answer, until I explain my issues to someone else.
🧠 1
The missing piece, if any one stumbles upon this as well, was this line:
Copy code
rule_runner.set_options([], env_inherit={"PATH", "PYENV_ROOT", "HOME"})
👍 2