Is there a way to make `pants run` function as `po...
# general
a
Is there a way to make
pants run
function as
poetry run
would, or am I attacking the problem from the wrong angle? E.g. I want to start
prefect
which is as simple as running
poetry run prefect server start
, however
pants run //:root#prefect -- server start
does not yield the same result and throws an error
ImportError: No module named prefect.__main__; 'prefect' is a package and cannot be directly executed
. I really enjoyed this feature of Poetry when debugging stuff locally and testing out new packages and am hoping for an alternative that is pants-native.
1
e
Is the target a
pex_binary
? If so have you set
execution_mode="venv"
?
a
No, I should have clarified. I've only added the package to my dependencies and generated the lockfiles. The target here is the dependency definition from the
poetry_requirements
(haven't migrated away from Poetry just yet).
e
You'll need a
pex_binary
binary target with that as a manual dep and a script="prefect", like ~so:
Copy code
pex_binary(
    name="foo",
    dependencies=["//:root#prefect],
    script="prefect",
    execution_mode="venv"
)
The
execution_mode
may not be needed, but is generally a good idea for maximum compatibility with the wider Python ecosystem of tools. You then
pants run
this new target.
a
Amazing! That works as I would expect!
e
... or
pants export
and then activate the exported venv in
dist/...
and go about normal venv business.
👍 3
a
Yeah, I thought about that one as well, but it felt like a very long way for a short drink of water. Nice to know that it's possible nonetheless. Really enjoying the flexibility of Pants