powerful-city-61287
04/29/2024, 6:29 PMpex_binary entry_point and must use a script instead (because it runs streamlit, which calls my main.py.)
However, I can't figure out how to get pex_binary to treat my main.py as a "source script" from the perspective of the pex tool, that is, a script that will be included in the call to "RUN PEX_TOOLS=1 /usr/local/bin/python3.10 /binary-srcs.pex venv --scope=srcs --compile /bin/app" (as opposed to --scope=deps.)
How does pex_binary determine which assets are "source" assets and which are "requirements"? That is, what determines which assets are included when you pass include_sources=True, include_requirements=False and its inverse? And how can I convince pex_binary to treat an asset as a source rather than a requirement?square-psychiatrist-19087
04/29/2024, 7:20 PMpython_sources and requirements are python_requirements. But what is not working exactly? Could you share a reproducible example?powerful-city-61287
04/30/2024, 2:32 PMpants run //:dev launches streamlit with main.py.
pants run //:image should behave the same way except wrapped in a container, but it does not:
jake@Jakes-MacBook-Pro streamlit-demo % pants run //:image
10:31:44.93 [INFO] Initializing scheduler...
10:31:47.19 [INFO] Scheduler initialized.
10:31:50.88 [INFO] Completed: Building docker image image:latest
Usage: pex run [OPTIONS] TARGET [ARGS]...
Try 'pex run --help' for help.
Error: Invalid value: File does not exist: main.pypowerful-city-61287
04/30/2024, 2:34 PMpowerful-city-61287
04/30/2024, 3:32 PMmain.py anywhere in /usr/bin/appsquare-psychiatrist-19087
04/30/2024, 3:34 PMsquare-psychiatrist-19087
04/30/2024, 3:35 PMpowerful-city-61287
04/30/2024, 5:31 PMsquare-psychiatrist-19087
04/30/2024, 6:46 PMsquare-psychiatrist-19087
04/30/2024, 6:46 PMsquare-psychiatrist-19087
04/30/2024, 6:50 PMpowerful-city-61287
04/30/2024, 7:09 PMso there is no main.py when you run your pexInteresting. Do you know why
pants run :dev works (that is, the app starts) and pants run :py-bin works (if I temporarily comment out my complete_platforms line) but pants run :image does not? Thanks for talking through this with me, BTWpowerful-city-61287
04/30/2024, 7:10 PMdoes streamlit support modules?Not in the same way that uvicorn does as I understand
square-psychiatrist-19087
04/30/2024, 7:41 PMDo you know whybecause run executes in your current directory. Try thisworks (that is, the app starts) andpants run :devworks (if I temporarily comment out mypants run :py-binline) butcomplete_platformsdoes not?pants run :image
pants package :dev, this will build the pex, then do ./dist/dev.pex - this is essentially what happens when you run pants runsquare-psychiatrist-19087
04/30/2024, 7:41 PMcd ~ and try running the same pex again - it will not work because you don't have main.py in your ~powerful-city-61287
04/30/2024, 7:42 PMpowerful-city-61287
04/30/2024, 7:44 PMpy-bin.pex does contain main.py :
jake@Jakes-MacBook-Pro Desktop % cd py-bin.pex
jake@Jakes-MacBook-Pro py-bin.pex % ls
PEX-INFO __main__.py __pex__ __pycache__ hello.py main.py
jake@Jakes-MacBook-Pro py-bin.pex %square-psychiatrist-19087
04/30/2024, 7:44 PMsquare-psychiatrist-19087
04/30/2024, 7:45 PMsquare-psychiatrist-19087
04/30/2024, 7:45 PMpowerful-city-61287
04/30/2024, 7:45 PMsquare-psychiatrist-19087
04/30/2024, 7:46 PMcat main.py or smthpowerful-city-61287
04/30/2024, 7:49 PMpowerful-city-61287
04/30/2024, 7:53 PMargs=["run", "main.py"],
This reference to main.py is basically "out of context" – it isn't understood by Pants to be a dependency of any kind. And though the args do seem to be baked into the pex (as arguments,) main.py itself is not available outside the pex when the pex is moved away from my pants repo. Is that correct?powerful-city-61287
04/30/2024, 7:53 PMsquare-psychiatrist-19087
04/30/2024, 7:54 PMsquare-psychiatrist-19087
04/30/2024, 7:55 PMimport main in your pex, and it should find the main.py inside the pexpowerful-city-61287
04/30/2024, 7:56 PMyou could dothis feels close to my solution 🤣. What do you mean by "in your pex?"in your peximport main
square-psychiatrist-19087
04/30/2024, 7:58 PMpex_binary(entry_point="my_entrypoint:main")
and then my_entrypoint.py
from main import main
then it should be able to import main.py from my_entrypoint.pypowerful-city-61287
04/30/2024, 7:58 PMsquare-psychiatrist-19087
04/30/2024, 8:00 PMpowerful-city-61287
04/30/2024, 8:01 PMthousands-hair-85964
07/31/2024, 8:07 PMflat-sunset-36133
07/31/2024, 8:18 PM