It's not possible to generate any files outside of...
# general
p
It's not possible to generate any files outside of the sandbox, is it? I was hoping to have a task that creates and populates a
venv
but I think that can't be done from within Pants, right?
h
Atm, Pants can only itself write to the build root, meaning where your repo is. `Workspace.write_digest()`: https://www.pantsbuild.org/docs/rules-api-file-system#workspacewrite_digest A subprocess can also write wherever it wants - Pants doesn't sandbox that
was hoping to have a task that creates and populates a venv
Have you used Pex before? Note that Pex now has support for acting like a venv - upon the first execution, it will extract itself into a venv and all subsequent runs will have ~no overhead. https://www.pantsbuild.org/docs/reference-pex_binary#codeexecution_modecode
p
I love Pex but didn't know about that feature. That's super cool.
But my main use case is: 1. Have a single
venv
for the whole repo that I can point my IDE at (vim language server) so it can resolve symbols for me. 2. Install the deps into the
venv
so I can
pip freeze
that. I don't think .pex is a good fit for either of those, right?
p
yeah, exactly. Just thought it'd be more user friendly to be able to do something like
pants venv
or
pants requirements
But not a big deal to run the script. Was just wondering if it's possible to write files outside of the sandbox.
h
Just thought it'd be more user friendly to be able to do something like pants venv
Strong agreement. We're starting work soon to support multiple constraints files in a repo, and part of that will involve Pants generating constraints files for you. Possibly creating the venv too for the sake of IDEs. That bash script is not where we want to end up
p
makes sense. But I gather I can't have a Pants rule write outside the sandbox so I couldn't build this myself?
h
You can have it write to the build root, e.g. to the
dist/
folder, which is what
./pants package
does If you want to write outside the build root, atm you would need a subprocess to do that via
Process
. (Probably not relevant to you, but note that doing that would not be safe with Remote Execution - if the remote worker wrote to some global directory via a
Process
, it would mutate the remote worker, but not your local machine)
p
got it. Thanks again for all your help!
❤️ 1
Sorry - one more question for you. I created a super-simple executable (a single
main.py
) and a BUILD file with a single
pex_binary
target. That won't run - it exits with a
ModuleNotFoundError
. If I unzip the .pex file indeed none of my code is there. however, if I add an otherwise empty
python_library
rule to that BUILD file and do nothing else now it works. 'sup with that?
h
You need the
python_library
to teach Pants your code exists. Then, if you set up your
entry_point
for the
pex_binary
to be in the format
main.py
, Pants can use dependency inference to figure out which code you're using
pex_binary
does not have any
sources
, it can only depend on other targets
p
Got it. Thanks.
h
If you haven't yet, it can be helpful to run
./pants tailor
(in a clean git state) https://www.pantsbuild.org/docs/create-initial-build-files
p
yeah - that's how I figured out the
python_library
was needed.
👍 1