Hi everyone, I have a `python_test` that depends o...
# general
f
Hi everyone, I have a
python_test
that depends on a
shell_command
(which generates a Python extension module needed by the test).
pants test
uses that dependency: it calls the
shell_command
as needed and puts its output in the sandbox when executing the test. The problem:
pants check
does not use that dependency: it does not run the
shell_command
before running the type-checker and it does not put the output of the shell command into the sandbox -> the type-checker fails to find that import and complains. Does anyone have any suggestions on how to convince pants to place that generated extension module in the sandbox in which
pants check
is run?
f
right, so for the tests this indeed is expected to work; https://github.com/AlexTereshenkov/cheeseshop-query/blob/main/tests/pantstests/BUILD I use this in my hobby project. as for the
check
goal, I am not sure whether this approach would work. I have seen a few similar attempts to make
python_sources
depend on some shell related logic, see https://pantsbuild.slack.com/archives/C0D7TNJHL/p1671827626536889 https://pantsbuild.slack.com/archives/C046T6T9U/p1699964896277789 Maybe those could be of help.
f
there is no supported way to have
pants check
depend on a generated file? pants would just have to...not ignore the dependency 😬
I'll take a look at the links, thank you
f
I am not sure you can just add your
shell_command
as a dependency in https://www.pantsbuild.org/2.18/reference/targets/python_sources#dependencies?
I mean the
python_sources
which would require those files you generate
f
I'll try
f
if you could share the minimal BUILD files with your shell_command and how your Python source import this "extension module", I could try to experiment as well
f
actually
experimental_wrap_as_python_sources
(mentioned in your first link) seems to be exactly what I was looking for! somehow my web and pants docs searches hadn't turned it up
f
glad that was helpful. Please do share here the final configuration (minimally) so that I could update the docs with your example (tweaked as appropriate); I think this may be a fairly common task we'd love to have in the docs!
f
I think what's at https://pantsbuild.slack.com/archives/C0D7TNJHL/p1671827626536889 is the best/clearest example
I'm basically doing that with extra steps
f
ok cool, thanks!
g
Are you building a native extension module @flaky-match-48400? 🙂
f
Yep