early-twilight-26336
06/21/2024, 7:48 PMpex_binary target, that, when run, reads some files from the local file system. I can't count on those files being present on the local file system, so would like to always run a script to populate those files before the pex_binary is run with pants run :the_pex_binary .
I have a feeling this may be somewhat antithetical to Pants' design, or out of scope, but wanted to check.early-twilight-26336
06/21/2024, 7:49 PMrun_shell_command and adhoc_tool but they don't seem quite right. For one, if I define:
run_shell_command(
name="script",
command="echo hello"
)
and then make it a dependency of the pex_binary, it doesn't seem to run.wide-midnight-78598
06/21/2024, 7:55 PMearly-twilight-26336
06/21/2024, 8:03 PMyou want a side-effect to run before your pex_binary.that's right. The binary won't contain the newly created files. At least, it doesn't need to. But if that's a way to do this, I'm game to try it.
wide-midnight-78598
06/21/2024, 8:04 PMearly-twilight-26336
06/21/2024, 8:07 PMwide-midnight-78598
06/21/2024, 8:11 PMwide-midnight-78598
06/21/2024, 8:11 PMearly-twilight-26336
06/21/2024, 8:16 PMearly-twilight-26336
06/21/2024, 8:18 PMwide-midnight-78598
06/21/2024, 8:22 PMearly-twilight-26336
06/21/2024, 8:25 PMearly-twilight-26336
06/21/2024, 8:26 PMwide-midnight-78598
06/21/2024, 8:30 PMscie https://github.com/a-scie/jump
I'm pretty sure this would all be do-able in a plugin. Natively though, I'm a little less sure. You've tried shell, which didn't work out (https://www.pantsbuild.org/2.21/docs/shell#testing-your-packaging-pipeline), and adhoc tool would be my next place to look.
I'm curious if archive might be an optionwide-midnight-78598
06/21/2024, 8:31 PMwide-midnight-78598
06/21/2024, 8:32 PMwide-midnight-78598
06/21/2024, 8:32 PMearly-twilight-26336
06/21/2024, 8:32 PMwide-midnight-78598
06/21/2024, 8:33 PMwide-midnight-78598
06/21/2024, 8:34 PMearly-twilight-26336
06/21/2024, 8:36 PMwide-midnight-78598
06/21/2024, 8:41 PMwide-midnight-78598
06/21/2024, 8:42 PMwide-midnight-78598
06/21/2024, 8:43 PMadhoc_tool example, this is one of me building a sveltekit project, so you can see the steps - all of which are technically side-effects, but some of those effects are pulled back into the sandboxes
https://gist.github.com/sureshjoshi/98fb09f2a340f7c1dad270c4887865a0early-twilight-26336
06/21/2024, 8:49 PMAthis sounds like what I want. I can basically put the BentoML model files into the repo dir in the expected structure, and have the code load from there. and as far as I understand it,target is for loose files that are copied into the chroot where Pants runs your code. You can then load these files through direct mechanisms like Python'sfileor Java'sopen()FileInputStream
shell_command essentially gives you files, is that right? So I could then use that to run the BentoML CLI to create the files instead of having to put them in manually.early-twilight-26336
06/21/2024, 8:50 PMwide-midnight-78598
06/21/2024, 8:54 PMand as far as I understand it,I don't know about BentoML - but if there is some way to have loose files in your repo, using files/resources is how you would collect them into the systemessentially gives youshell_command, is that right? So I could then use that to run the BentoML CLI to create thefilesinstead of having to put them in manually.files
wide-midnight-78598
06/21/2024, 8:55 PMearly-twilight-26336
06/21/2024, 8:55 PMwide-midnight-78598
06/22/2024, 12:55 AMwide-midnight-78598
06/22/2024, 1:02 AMhttp_source ) and then the closest I could think to make an easy example of what you want to do.
adhoc_tool might be a cleaner way to do it, with more reliably caching, but I used a shell command to call a script to read from a manifest.txt file, and then download an image, and stick it into the pexwide-midnight-78598
06/22/2024, 1:03 AMearly-twilight-26336
06/22/2024, 1:31 AMwide-midnight-78598
06/22/2024, 1:54 AMoutput_xyz to the next layer.
That was also the first time I'd needed to use experimental_wrap_as_resource since otherwise, a file is generated, and it's kinda loose in the pex_binary targetearly-twilight-26336
06/22/2024, 1:55 AMfile in the end, the code that loads the model is doing regular FS accessearly-twilight-26336
06/22/2024, 2:07 AM:run-downloader, I get this warning when running:
⯠pants run src:bin
22:00:53.21 [WARN] The target src:bin (`pex_binary`) transitively depends on the below `files` targets, but Pants will not include them in the built package. Filesystem APIs like `open()` may be not able to load files within the binary itself; instead, they read from the current working directory.
Instead, use `resources` targets. See <https://www.pantsbuild.org/resources>.
Files targets dependencies: ['src:run-downloader']
and the run-downloader.sh doesn't actually run! (I can tell because I added exit 1 to the beginning). Is that expected? I get that the PEX won't contain the files, but shouldn't they still be available in the working dir?wide-midnight-78598
06/22/2024, 2:11 AMwide-midnight-78598
06/22/2024, 2:12 AMearly-twilight-26336
06/22/2024, 2:20 AMpex_binary(
name="bin",
dependencies=[
":lib",
":archive"
],
entry_point="main.py"
)
archive(
name="archive",
format="zip",
files=[":run-downloader"],
)
python_sources(
name="lib",
dependencies=[
":local-file",
":downloaded-image",
],
sources=["**/*.py"],
)
# experimental_wrap_as_resources(
# name="wrapped_downloader_output",
# inputs=[":run-downloader"],
# )
shell_command(
name="run-downloader",
command="./downloader.sh",
execution_dependencies=[":scripts", ":manifest"],
output_files=["dilbert-rng.gif"], # This must match your expected file(s) (or use output_directory)
tools=["curl", "head"],
)wide-midnight-78598
06/22/2024, 2:22 AMearly-twilight-26336
06/22/2024, 2:22 AMearly-twilight-26336
06/22/2024, 2:22 AMpants package src:archive it does runwide-midnight-78598
06/22/2024, 2:23 AMwide-midnight-78598
06/22/2024, 2:24 AMwide-midnight-78598
06/22/2024, 2:28 AMwide-midnight-78598
06/22/2024, 2:30 AMpants run src:bin you want to ensure the shell command is runwide-midnight-78598
06/22/2024, 2:30 AMearly-twilight-26336
06/22/2024, 2:30 AMearly-twilight-26336
06/22/2024, 2:31 AMfile, somewhereearly-twilight-26336
06/22/2024, 2:33 AMentry_point to get a REPL, and then poke around with os I'm in the source tree. So, maybe I guess I want to put the files into the source tree?wide-midnight-78598
06/22/2024, 2:35 AMearly-twilight-26336
06/22/2024, 2:35 AMearly-twilight-26336
06/22/2024, 4:02 AMadhoc_tool has the same issues as shell_command. But, run_shell_command will just let me write files to the project tree which should probably be enough.
The only sad part is I still can't make the pex_binary depend on the run_shell_command so I have to do pants run src:the_run_shell_command; pants run src:bin . Was hoping a cli.alias would help, but pants run only accepts one target. Would be nice if you could do pants run target1 target2 and just have them run in sequence.