elegant-florist-94385
01/06/2025, 12:38 PMpython_source
and collecting its output?
I have a python script that runs my app and writes the generated api spec (to stdout, but could easily switch it to a file). I'm trying to figure out how to run this and then use the output file for something (take a diff against the PR target, so as to check for changes to the spec). It seems I need to use something with run_shell_command
, but I can't seem to figure it out (aside from exporting the venv, then having the shell command use ./dist/export/<.......>/bin/python
to run the script, which I would like to avoid because it feels like their ought to be a cleaner way)elegant-florist-94385
01/06/2025, 12:54 PMpants run 3rdparty/python:poetry#python
somehow? despite having python
in my pyproject.toml
, this command gives
pants.build_graph.address.ResolveError: The address `3rdparty/python:poetry#python` from CLI arguments was not generated by the target `3rdparty/python:poetry`. Did you mean one of these addresses?
so it seems that pants actually strips python
out (which I suppose I can see a case for)fast-nail-55400
01/06/2025, 2:38 PMadhoc_tool
.broad-processor-92400
01/07/2025, 4:18 AMadhoc_tool(name="generated", runnable="./script.py", stdout="file_name_to_capture_to.txt")
is a likely starting point.
Depending on path/to/directory:generated
will then act like depending on a file(name="generated", source="file_name_to_capture_to.txt")
if there was a file by that name on disk (i.e. it'll appear in sandboxes).
https://github.com/pantsbuild/pants/discussions/18235#discussioncomment-6655594 might also be relevant to you.elegant-florist-94385
01/07/2025, 11:51 AMpants run /path/to/script.py | tail -n 1 > api_spec.json
since I wanted it to appear directly in my repo (eg. to save as a github artifact afterwards)