Hello pants-wearers. I have a Python question. Is ...
# general
f
Hello pants-wearers. I have a Python question. Is there a way to get entrypoint scripts added to the virtualenv created by
pants export
? I have several console scripts that I'd like to make easily accessible for development. I saw in the docs you can declare console scripts via
python_distribution
, but this doesn't seem to have any effect on
pants export
If necessary I suppose I can manually hack in the stuff I need but it would be useful to have this properly automated
e
If you create some scripts anywhere and set them up as
python_sources
you can run them with
pants run /path/to/file
or as
pants run --args="all args going to the script" /path/to/file
and they will follow the standard dependency inference and sandboxing behavior. (You can also use
shell_source
if you want sh/bash scripts instead, but you'll have to manually specify dependencies on whatever python files it needs to call, so they end up in the sandbox)
I found this useful for CI in particular because it meant I didn't actually need to export the venv to run my scripts. Was quite a time-saver
f
These scripts are for development stuff rather than CI so I want the invocation to be as simple as possible, so ideally they should be available in the virtualenv bin folder since calling
. activate
already adds that directory to the PATH. But if that's not possible I can look at other workarounds
e
I understand your point about making invocation simple. I don't have an immediate solution, but I'd guess you could do something like having an
export_venv.sh
script that looks something like:
Copy code
pants export --whatever

# make symlinks of scripts to venv/bin
You'd have to "register" any new scripts by updating this script to add their symlinks.
Alternatively, if all your scripts live in some kind of
src/tools/scripts
location, you could have your
export_venv.sh
script update the exported
activate
script to also add this directory to the PATH
a
not super convenient but you can define your scripts as aliases so
pants run path/to/file --args
is shorthanded as
pants cool_script
💟 1