victorious-twilight-98565
09/05/2024, 8:50 AMpoetry run mypy --strict -p my-package | poetry run mypy-json-report parse --output-file report.json --diff-old-report report.json
)
I'm using run_shell_command
to do this because nothing else seems to put the file in the source tree, probably because it's in the sandbox.
This still isn't working because run_shell_command
is running in an environment with none of the python deps installed. I can start writing commands to install python, poetry, etc - that feels like the wrong path.
Any guidance you have would be appreciated.victorious-twilight-98565
09/05/2024, 1:56 PMdef mypy(service: str, ratchet: str = "mypy-ratchet.json"):
run_shell_command(
name="mypy",
tags=["mypy"],
command=f"poetry run mypy --strict -p {service} | poetry run mypy-json-report parse --diff-old-report {ratchet}",
execution_dependencies=[f"{service}:poetry"],
)
blank = "{}"
run_shell_command(
name="mypy_approve",
tags=["mypy_approve"],
command=f"(cat {ratchet} > /dev/null || echo '{blank}' > {ratchet}); poetry run mypy --strict -p {service} | poetry run mypy-json-report parse --output-file {ratchet} --diff-old-report {ratchet}",
execution_dependencies=[f"{service}:poetry"],
)
mypy("my-service")
broad-processor-92400
09/11/2024, 3:45 AMadhoc_tool
target and/or shell_command
's executable_dependencies
might be what you as you'e tried... but using mypy
as the executable, potentially packaging mypy
into a pex_binary
target.
You can see what I do in my work repo along these lines at https://github.com/pantsbuild/pants/discussions/18235#discussioncomment-6655594victorious-twilight-98565
09/11/2024, 8:21 AMvictorious-twilight-98565
09/30/2024, 9:40 AMpex_binary
to run both mypy and my report tool.
These pex binaries failed to run inside the sandbox. They complained that python3.11
was missing. When I added python3.11
to tools=[...]
on experimental_test_shell_command
I got a python that wouldn't run. I guess it's missing the list of other files that go into making a working python env.
I feel like I'm missing something basic but I don't know the precise question I should be askingvictorious-twilight-98565
09/30/2024, 9:41 AMbroad-processor-92400
09/30/2024, 4:27 PMrunnable_dependencies
above, not executable_dependencies
(which doesn't exist, and I can see that execution_dependencies
is the most sensible correction 🙂 ): https://www.pantsbuild.org/stable/reference/targets/adhoc_tool#runnable_dependencies (similar for shell_command
)
In particular, runnable_dependencies
will do all the Python management. It puts an executable with the target name onto the command's PATH
, so something like runnable_dependencies=[":mypy_pex"]
should be able to call command="...; mypy_pex ...; ..."
victorious-twilight-98565
10/02/2024, 8:06 AMsystem_binary(name="py311", binary_name="python3.11")
as a runnable dependency but that's not working. The python3.11
binary is linked into the sandbox but without the other files it needs to operate. It just doesn't run.victorious-twilight-98565
10/02/2024, 8:09 AMpoetry install
would make me, and that accessing this would allow me to simply run python tools as defined in my pyproject.toml
victorious-twilight-98565
10/02/2024, 8:11 AMOh, I'm sorry, I think I gave you misleading advice.I'm appreciating the advice you're giving. I'm learning plenty of things about pants along the way even with a few rabbit holes 🙂
broad-processor-92400
10/02/2024, 6:00 PMvictorious-twilight-98565
10/03/2024, 6:08 AMrunnable
and python as runnable_dependency
broad-processor-92400
10/03/2024, 5:12 PMvictorious-twilight-98565
10/04/2024, 7:10 AM