I have 3 questions about `pants run`: 1. In my dir...
# general
b
I have 3 questions about `pants run`: 1. In my directory, I have a .env file that I'm testing the code with. But it looks like pants run will load it into the envvars even before my code runs (I added
print(os.environ)
as the first line of my code, and the vars in .env are already present. Is that the default behavior? 2. It looks like if I use the relative path from source root, I can access data files without making a resource target and dependency. Is that correct? (This is for playing around, I know if I need to package things up, I'll need to create a target and dependency for the pex.) 3. Is the CWD always the source root when I do a
pants run
l
For 2: Joe you will still need to mark a dependency on a file target referring to the data file.
Oh but if you are pants running for 2 you could read any file even without wrapping it. For something like running tests you need to wrap
c
I think the
.env
file will be loaded when pants is bootstrapped (by
scie-pants
) but I wouldn't have expected those to leak through to your executed process unless you have punched holes for them in pants configuration. for running python sources, it depends on this setting: https://www.pantsbuild.org/docs/reference-python_source#coderun_goal_use_sandboxcode the CWD is always repo root when using the pants daemon, but if you don't, it'll be using your current CWD. This is an unfortunate nuance we'd like to make consistent. https://github.com/pantsbuild/pants/issues/19682
b
I have a repo of minimal pants.toml, a single .py file with
print(os.environ)
, and a .env with a single variable. Even in that case, it leaked through.
b
@curved-television-6568 I'm like 80% sure we leak vars through for InteractiveProcess. So yeah scie-pants loads .env, and Pants let's that through
c
Ah, yea I'm surprised. Seems there's an option to run hermetic, but it doesn't seem like it is implemented fully yet? https://github.com/pantsbuild/pants/blob/3632a66bc7918ace25c0aa6f05b4b6a4253d908e/src/python/pants/core/goals/run.py#L261