https://pantsbuild.org/ logo
#general
Title
# general
a

abundant-analyst-12845

11/25/2022, 4:39 PM
hi another poetry related question. normally if i want to execute something from poetry i would be able to run something like
poetry run <dependency
with pants being able to detect my 3rd party dependencies. is there a need to either run
poetry install
to prep my local dev before running my
poetry
commands or does pants support sort of running something from
./pants run poetry
e

enough-analyst-54434

11/25/2022, 4:49 PM
For local entry points you can
./pants run path/to/file.py
or
./pants run the/pex_binary/target:here
. For 3rdparty entry points you'll need to define a
pex_binary
target somewhere that encapsulates the entry point:
Copy code
$ cat <<EOF > BUILD.cowsay
python_requirement(name="cowsay", requirements=["cowsay==5.0"])
pex_binary(name="bin", script="cowsay", dependencies=[":cowsay"])
EOF
$ ./pants generate-lockfiles --resolve=python-default
08:49:09.51 [INFO] Completed: Generate lockfile for python-default
08:49:09.52 [INFO] Wrote lockfile for the resolve `python-default` to 3rdparty/python/user_reqs.lock
$ ./pants run //:bin -- 'Moo!'
08:49:23.31 [INFO] Completed: Building 1 requirement for bin.pex from the 3rdparty/python/user_reqs.lock resolve: cowsay==5.0
  ____
| Moo! |
  ====
    \
     \
       ^__^
       (oo)\_______
       (__)\       )\/\
           ||----w |
           ||     ||
a

abundant-analyst-12845

11/25/2022, 5:00 PM
so if I want to run
awsclie
would it look like this?
Copy code
python_requirement(name="awscli", requirements=["awscli==5.0"])
pex_binary(name="awscli-bin", script="awscli", dependencies=[":awscli"])
followed by the generate command
./pants generate-lockfiles
then I can run
./pants run //:awscli-bin <standard awscli commands>
??
e

enough-analyst-54434

11/25/2022, 5:01 PM
Yes. My example is compact, normally the
python_requirement
line would not be needed and that requirement would come from a `requirements.txt`file or a `pytproject.toml`file.
But when running the command, note the
--
, you pass args to the thing you are `./pants run`ing after the
--
a

abundant-analyst-12845

11/25/2022, 5:02 PM
when you ay won't be needed what you mean. given I use poetry what should be removed
ah didn't know so it would be
./pants run awscli-bin -- <what ever arguments original awslci supports>
thanks for the help
e

enough-analyst-54434

11/25/2022, 5:03 PM
So, do you have a `poetry_requirements`target somewhere and is an
awscli
dependency defined in your pyproject.toml?
a

abundant-analyst-12845

11/25/2022, 5:03 PM
yes I would have
e

enough-analyst-54434

11/25/2022, 5:03 PM
If so, the
python_requirement(name="awscli", requirements=["awscli==5.0"])
should not be needed.
a

abundant-analyst-12845

11/25/2022, 5:03 PM
yes that is what I would set up
so with that in mind do I still need the bax_binary part will it just work with the
poetry_requirements
and running
./pants run awscli -- <cli commands>
e

enough-analyst-54434

11/25/2022, 5:05 PM
You need the
pex_binary
target
Pants currently has no way to guess, given just
awscli
on the command line, that that means a console script named
awscli
provided by the awscli==5.0 3rdparty dependency.
a

abundant-analyst-12845

11/25/2022, 5:08 PM
so
Copy code
poetry_requirements(
    name="poetry",
    resolve="common",
    },
)

pex_binary(
    name="awscli",
    entry_point="do i need to know where to point",
    resolve="common",
)
i need to do more reading around some of those things. I guess
e

enough-analyst-54434

11/25/2022, 5:10 PM
Yeah. The pex_binary still needs
dependencies=[":poetry#awscli"]
in your example and you use
entry_point
only if you want to spell out the full entry point
module:function
. If there is a console script available its ~always better to use
script
.
When I bound to the `cowsay`script in my example, that means as long as they never change the script name, I'll be impervious to them changing the actual underlying entrypoint. And it would seem like the name of a console script is a much harder to break public contract than an internal entry point
module:function
that may be subject to rename refactors.
a

abundant-analyst-12845

11/25/2022, 5:14 PM
ok let me try my hand again to see if I follow
Copy code
poetry_requirements(
    name="poetry",
    resolve="common",
    },
)

pex_binary(
    name="awscli",
    dependencies=[":poetry#awscli"]
    script="awscli",
    resolve="common",
)
`./pants run //:awscli -- <rest or argument> or
Copy code
poetry_requirements(
    name="poetry",
    resolve="common",
    },
)

pex_binary(
    name="pants-awscli",
    dependencies=[":poetry#awscli"]
    script="awscli",
    resolve="common",
)
./pants run //:pants-awscli -- <rest of  arguments>
e

enough-analyst-54434

11/25/2022, 5:21 PM
The only difference there is what you named the
pex_binary
target right? Both examples should work. The target name is ~arbitrary and up to you.
FWIW, the `},`line in the `poetry_requirements`target looks bogus and should be removed.
1
One thing to keep keeping in mind is this example was born out of convencience, so I used 1 BUILD file at the top of the repo. The `poetry_requirements`target should go in a BUILD file sibling to the
pyproject.toml
file it describes, but the `pex_binary`target can go in a BUILD file anywhere. You just adjust the dependencies to say
dependencies=["path/from/root/of/repo/to/poetry/build_file:poetry#awscli"]
.
🙌🏿 1
a

abundant-analyst-12845

11/25/2022, 5:55 PM
sweet thanks so much
will defo try this out
this is some amazing stuff. thanks @enough-analyst-54434 will give it these a goo and see what happent
7 Views