Does anyone have any other general Django + Pants ...
# general
n
Does anyone have any other general Django + Pants references that they like outside of https://github.com/pantsbuild/example-django/ ?
Ok much more specifically now - Im trying to build static files with
collectstatic
and package them with the pex file that is eventually included in our dockerfile. I think what I want is an
adhoc_tool
definition that calls
collectstatc
as a dependency of the
pex_build
but that doesn't seem to produce any output in the sandbox
c
have you looked at the adhoc_tool process sandbox and run the
__run.sh
script in there and obeserved it doesn’t produce the files? or just that those files are not picked up later on?
n
Does the
adhoc_tool
get its own sandbox? Maybe Im just looking in the wrong place if so
c
a couple of notes worth having, if you want files in the pex, you need them as
resource
targets, while for docker you need them as
file
targets…
I’ve not used
adhoc_tool
myself, so take what I’m guessing with a good pinch of salt, but my hunch is that that target runs your tool as a process, in which case it does so in a sandbox, dedicated for that tool yes.
any outputs captured will then be included as required (as dependencies) in other sandboxes that follows.
n
Hrm I think its something to do with
pex_binary
or my particular config. I can make a new
python_source
that runs a debug script which depends on the same
adhoc_tool
and the sandbox contains the files I expect
c
if adhoc tool produces
files
, you may try this new experimental target to convert them into `resources`: https://www.pantsbuild.org/docs/reference-experimental_wrap_as_resources (this relates to my comment above regarding files/resources for docker vs pex)
n
Is the
source
field in
python_sources
a file or a resource?
c
neither. the
python_sources
target generates one
python_source
for each source file.
n
sorry that should have been singular 🙂
python_source
Here's my very stripped down test case
c
ah, so
file
and
resource
are target types, as is
python_source
n
Copy code
python_source(name="debug", source="debug.py", dependencies=[":adhoc_collectstatic"])
    adhoc_tool(
        name="adhoc_collectstatic",
        runnable=":collectstatic",
        execution_dependencies=[":lib"],
        output_directories=["static"],
    )
Where debug.py is a trivial script that just prints the contents of the
static
directory
The above example works great
However when I try
Copy code
pex_binary(name="debug-bin", entry_point="debug.py", dependencies=[":lib", ":adhoc_collectstatic"])
The sandbox is missing only the static dir 🤔
c
yes, so here you want to interject the wrap_as_resource target between the pex and your adhoc tool
because pex silently ignores
file
targets…. (which is what I think the adhoc tool captures the output files as)
n
ahhhh ok I think I get that
👌 1
So I would just define a new
experimental_wrap_as_resources
target whose
inputs
were the
adhoc_tool
target name and the outputs are a new target name that is resource-wrapped-file?
and that new target name is what the pex should depend on?
👍 1
c
yea, and you don’t need to specify the outputs so it will default to wrap all input sources for you
n
So something like
Copy code
pex_binary(name="debug-bin", entry_point="debug.py", dependencies=[":lib", ":foo"])
    experimental_wrap_as_resources(name="foo", inputs=[":adhoc_collectstatic"])
    adhoc_tool(
        name="adhoc_collectstatic",
        runnable=":collectstatic",
        execution_dependencies=[":lib"],
        output_directories=["static"],
    )
?
c
looks about right, try it out 😉 (as I said, I’ve not used adhoc tool, nor the wrap as targets, before so I’m really making mostly educated guesses here) 😉
n
Heh thanks I appreciate it
😅 1