https://pantsbuild.org/ logo
#general
Title
# general
p

proud-dentist-22844

03/28/2023, 6:12 PM
I want to create a
pex_binary
that gets built based on a set of
python_distribution
targets so that the pex includes all of the entry_points metadata. The purpose of this pex is not to run a binary or script (so,
entry_point=None
); its purpose is to create a virtualenv from its contents (so,
include_tools=True
). I tried just depending on the
python_distribution
targets, but then pants looks at the transitive deps which includes things like a
relocated_file(source="LICENSE")
target. Because the
python_distribution
has transitive deps that are
files
instead of
resources
, I get a warning telling me to use
resources
instead. If I use
include_sources=False
, I still get the warning about transitive
files
targets. Oddly enough, the generated wheels still get installed in the pex, which I guess is fine since they are not sources (they are generated). So, is there a way to prevent the warning for this
pex_binary
target? Having that warning on other
pex_binary
targets that are meant to be executable is fine. But, in this case, I want an “I know what I’m doing” flag to signal that I expect pex to just use the generated wheels and install whatever the wheel includes, whether or not that wheel happened to somehow include a
files
target. So, is there a way to prevent that warning for a particular
pex_binary
target?
h

happy-kitchen-89482

03/28/2023, 6:58 PM
How are you generating this virtualenv?
Trying to understand why this
pex_binary
is needed, because this seems a bit out of scope for what
pex_binary
is supposed to be
p

proud-dentist-22844

03/28/2023, 7:22 PM
Now that I know I can use a pex to create an installable self-contained venv that has the versions locked in my lockfile, I’m trying to generate the pex with
pex_binary
because that’s the canonical way to create a pex in pants, isn’t it?
ooh. I’ll have to try `emit_warnings`: https://www.pantsbuild.org/v2.16/docs/reference-pex_binary#codeemit_warningscode Oh wait. no. That’s for warnings that pex itself emits. https://github.com/pantsbuild/pants/blob/527a066bcebd80a3cb26b72e9f03413df406f463/src/python/pants/backend/python/goals/package_pex_binary.py#L131-L150 Does it make sense to emit that warning when
pex_target(include_sources=False)
? Maybe what should happen is: • if field_set.include_sources: check for
files
targets in the transitive dependencies closure • else (include_sources == False): check for
files
targets ONLY in the direct dependencies, since only those will get materialized in the sandbox for pex to use.
How are you generating this virtualenv?
PEX_TOOLS=1 dist/st2.pex venv /opt/stackstorm/st2
h

happy-kitchen-89482

03/29/2023, 7:07 AM
Ah, so Pants stops at building a pex
👍 1
p

proud-dentist-22844

03/29/2023, 11:54 PM
@happy-kitchen-89482 https://github.com/pantsbuild/pants/pull/18619 This makes the warning account for use of
include_sources=False
. Wdyt?
2 Views