Problem Hey I am trying to run Pulumi with wants (...
# general
i
Problem Hey I am trying to run Pulumi with wants (have an infra folder in my repo) but I couldn't get it to work. My project is gonna have a bunch of lambdas and I wanted to have a setup so I can deploy my lambdas to a dev environment without having to run it through CI. What I Found I used the slack search and it seems like a year ago someone dropped a single zip file to a plugin and some other people were talking about using
run_shell_command
. I don't want to rely on someones year old code and it seems that
run_shell_command
doesn't do what I thought. What I Tried Here's what I have: 1. I exported the dependencies to a virtualenv 2. I have an infra folder with a
Pulumi.yaml
that has
virtualenv: ../dist/export/python/virtualenvs/python-default/3.11.4
3. At this point if I run
pulumi up
I get this error `error: failed to discover plugin requirements: calling `python -m pip list -v --format json`: exit status 1` 4. I tried getting into an ipython repl and using
!pulumi up
only to get the same error 5. So I tried to add a
run_shell_command
that looks as follow:
Copy code
# in infra/BUILD
run_shell_command(
    command="pulumi",
    execution_dependencies=[":infra"],
    runnable_dependencies=["/home/me/.pulumi/bin/pulumi"],
)
At this point I can't run the shell command. Running
pants run
lets me know that there are no runnable targets. Using
pants peek infra:infra
gives me this error `InvalidSpecPathError: Invalid address
/home/me/.pulumi/bin/pulumi
from the
runnable_dependencies
field from the target infra:infra. It has an un-normalized path part: `""``. The Questions 1. I don't have a high tolerance for a complicated or brittle solution. Should I just separate this part out and use poetry/etc to manage it? 2. If not, what am I missing to get this to work? 3. I noticed that it doesn't seem that there's an equivalent to
poetry run
or
poetry shell
. Why not?
c
for
run_shell_command
, the PATH is inherited, since it's a "run"able target. (
runnable_dependenices
is for pants' runnable targets that you want to include.)
Copy code
run_shell_command(
    command="pulumi",
    execution_dependencies=[":infra"],
)
^ should work
I haven't used poetry. but for
poetry run
, if you want to run python scripts/code in your repo, you can use
pants run path/to/file.py
; pants will analyse your source code to determine what 3rd party dependencies your code has, bundle them into a PEX, and run PEX. You can also export the full venv with
pants export --resolve=my-resolve
and source it from "dist/export/python/virtualenvs/" There's also
pants repl
for interactive python sessions. You can specify the code to load as a target and pants will pull in the relevant 3rd party dependencies (ex
pants repl src/python/service0::
)
i
The nice thing about
poetry run
and
poetry shell
is that they can run any command not just python that's in your repo. So for instance if I'm using vim and have a plugin that checks the current python environment to provide autocompletion
pants run
wont help me.
I also can't get the pants incantation to run the
run_shell_command
. I cant see the command with
pants peek
and
pants run infra:infra
doesn't work. Also moving out to the root dir and using
pants run infra/infra:infra
doesn't work either.
c
sorry for the late reply. Pants target addresses are relative. You can use an absolute target address, which use "//" at the start. For example, "//infra:infra".
pants peek
works on build files, so I think you'd want to use
pants peek infra
. You can also see all targets with
pants list //::
. If your BUILD file is "infra/BUILD", and your target has the default name, I think the target you want is "infra:infra".
👍 1