limited-art-78990
08/27/2024, 9:47 AMpex_binary(
name = "client",
entry_point = "client.py",
dependencies = [":server"],
)
pex_binary(
name = "server",
entry_point = "server.py",
)
but it seems that the server pex is not part of the client pex binary. I also tried wrapping the server pex with resource
, but that target only supports files not targets. Is there a way to do this currently?happy-kitchen-89482
08/27/2024, 3:11 PMhappy-kitchen-89482
08/27/2024, 3:11 PM--keep-sandboxes=always
and look inside the sandbox where the client
pex is created, you donāt see the server pex in there?happy-kitchen-89482
08/27/2024, 3:12 PMlimited-art-78990
08/27/2024, 4:02 PMlimited-art-78990
08/27/2024, 4:03 PMpython_test
has runtime_package_dependencies which is exactly what I want!limited-art-78990
08/27/2024, 4:03 PMpex_binary
šlimited-art-78990
08/27/2024, 4:06 PMpants package //:server
and copy the server.pex
into the workspace root and use a resource like this:
pex_binary(
name = "client",
entry_point = "client.py",
dependencies = [
":server-pex",
]
)
resource(
name = "server-pex",
source = "server.pex",
)
and package the client pex, the server.pex file is included inside the client.pex!limited-art-78990
08/27/2024, 4:08 PMruntime_package_dependencies
OR
2. support packages inside source
attribute for resource targets OR
3. support adding "packageable" sources in the dependencies
attribute of pex_binary
4. something else I haven't though of?limited-art-78990
08/27/2024, 4:09 PMlimited-art-78990
08/27/2024, 4:10 PMlimited-art-78990
08/27/2024, 4:34 PM.py
instead of .pex
allows it to be included using experimental_wrap_as_python_sources
pex_binary(
name = "client",
entry_point = "client.py",
dependencies = [
":wrap",
]
)
pex_binary(
name = "server",
entry_point = "server.py",
shebang = "#!/usr/bin/env python3",
)
shell_command(
name = "hack",
command = "cp server.pex server.py",
tools = [
"cp"
],
output_files = [
"server.py",
],
execution_dependencies = [
":server"
]
)
experimental_wrap_as_python_sources(
name = "wrap",
inputs = [
":hack",
],
)
limited-art-78990
08/27/2024, 4:34 PMlimited-art-78990
08/27/2024, 4:36 PMexperimental_wrap_as_resources
limited-art-78990
08/27/2024, 4:36 PMlimited-art-78990
08/27/2024, 5:11 PMpex_binary(
name = "client",
entry_point = "client.py",
dependencies = [
":wrap2",
]
)
pex_binary(
name = "server",
entry_point = "server.py",
shebang = "#!/usr/bin/env python3",
)
experimental_wrap_as_resources(
name = "wrap2",
inputs = [
":hack2",
]
)
shell_command(
name = "hack2",
command = "exit 0",
output_files = [
"server.pex",
],
execution_dependencies = [
":server"
]
)
This works as welllimited-art-78990
08/27/2024, 5:13 PMlimited-art-78990
08/27/2024, 5:13 PMpex_binary(
name = "client",
entry_point = "client.py",
dependencies = [
":wrap2",
]
)
pex_binary(
name = "server",
entry_point = "server.py",
shebang = "#!/usr/bin/env python3",
)
experimental_wrap_as_resources(
name = "wrap2",
inputs = [
":server",
]
)
happy-kitchen-89482
08/27/2024, 8:34 PMexperimental_wrap_as_resources
, glad that works!!limited-art-78990
08/28/2024, 7:08 AMdef package_resource(name, source, output_files, description=None, tags=None):
"""
From Pants Build Slack community: <https://pantsbuild.slack.com/archives/C046T6T9U/p1724752064431699>
Macro which enables exposing a package target as a resource target.
This is useful for example wanting to include an archive inside a pex_binary,
but can be used for any packageable target.
"""
if tags is None:
tags = []
shell_name = f"{name}.command"
resource_name = name
shell_command(
name=shell_name,
command="exit 0",
workdir="/",
output_files=output_files,
execution_dependencies=[source],
)
experimental_wrap_as_resources(
name=resource_name,
description=description,
tags=tags,
inputs=[
f":{shell_name}",
],
)
limited-art-78990
08/28/2024, 7:09 AMpex_binary(
name = "client",
dependencies = [
":server-pex",
],
entry_point = "client.py",
)
pex_binary(
name = "server",
entry_point = "server.py",
)
package_resource(
name = "server-pex",
output_files = [
"server.pex",
],
source = ":server",
)
limited-art-78990
08/28/2024, 7:09 AMhappy-kitchen-89482
08/28/2024, 6:57 PMhappy-kitchen-89482
08/28/2024, 7:00 PMlimited-art-78990
08/29/2024, 5:04 AMhappy-kitchen-89482
08/29/2024, 2:34 PMlimited-art-78990
08/29/2024, 8:11 PMlimited-art-78990
08/29/2024, 8:11 PMhappy-kitchen-89482
08/31/2024, 2:15 AM