plain-quill-25213
08/28/2023, 4:18 PMpex_binary . I have a directory structure that looks like so:
app
BUILD
__init__.py
script.py
__init__.py contains the routes for a fastapi server. Now whenever I try to run a pex_binary with script.py as an entrypoint (but no dependencies on the __init__.py module) it also runs the code from the init file. Excluding the python_sources that reference the init module does not change anything.
So my question would be if there is some way to limit the source files for a pex binary.refined-addition-53644
08/28/2023, 4:23 PMplain-quill-25213
08/28/2023, 4:25 PMpython_sources(
name = "lib",
)
pex_binary(
name = "bin",
args = [
"notification:app",
"--host",
"0.0.0.0",
"--port",
"8080",
],
dependencies = [
"//:requirements#uvicorn",
"//:requirements#aiohttp",
"//:requirements#python-multipart",
":lib",
],
platforms = [
"linux_x86_64-cp-39-cp39",
# "macosx-11.0-arm64-cp-39-cp39",
],
script = "uvicorn",
)
pex_binary(
name = "script",
dependencies = [
"!:lib",
],
entry_point = "script.py",
)refined-addition-53644
08/28/2023, 4:32 PMscript pex?
What does pants dependencies for script shows?
It feels bit weird that you are ignoring the :lib target which owns the script.py but later you provide it as an entry point.
python_sources globs all the .py files in current directory except I think test_ or conftestplain-quill-25213
08/28/2023, 4:34 PMpants dependencies shows app/__init__.py:lib as a dependency.refined-addition-53644
08/28/2023, 4:37 PM__init__.py directly inside python_sources and try?
python_sources(name="lib", dependencies=["script.py"])
I am not sure if when fetching a single script as entry point, pants packages the whole target which owns it.refined-addition-53644
08/28/2023, 4:38 PMsources not dependencies
python_sources(name="lib", sources=["script.py"])plain-quill-25213
08/28/2023, 4:40 PMplain-quill-25213
08/28/2023, 5:22 PMenough-analyst-54434
08/28/2023, 5:47 PM--exe script.py and that would slurp in script.py and nothing else.plain-quill-25213
08/28/2023, 5:48 PMscripts directory for a given app.enough-analyst-54434
08/28/2023, 5:54 PMrefined-addition-53644
08/28/2023, 5:57 PM--exeenough-analyst-54434
08/28/2023, 5:59 PMhappy-kitchen-89482
08/28/2023, 7:53 PM__init__.py files. Try setting that to never to see if that helps?happy-kitchen-89482
08/28/2023, 7:53 PMplain-quill-25213
09/05/2023, 8:36 AM.
βββ apps/
βββ BUILD
βββ __init__.py # outer init
βββ scripts/
βββ BUILD
βββ __init__.py # inner init
βββ script.py
But this seems to be expected:
Even if this is set to never or content_only, Pants will still always include any ancestor __init__.py files in the sandbox. Only, they will not be "proper" dependencies, e.g. they will not show up in pants dependencies and their own dependencies will not be used.
Of course I can work around this, but itβs very surprising behavior. Anyway, thank you for Pants and all your work!happy-kitchen-89482
09/05/2023, 12:58 PM__init__.pyhappy-kitchen-89482
09/05/2023, 12:58 PMhappy-kitchen-89482
09/05/2023, 1:00 PMhappy-kitchen-89482
09/05/2023, 1:00 PMplain-quill-25213
09/06/2023, 8:13 AM