hello community :wave: I am trying to use a cli to...
# general
b
hello community ๐Ÿ‘‹ I am trying to use a cli tool (defined as a 3rd party python dependency i.e. not in the system path) with the run goal, with little success so far. Tried with
run_shell_command
target, however the tool must be already available in my path (e.g., using an exported venv ) for this to work. That beats the purpose IMO as I can interact with the tool directly in that case. Any suggestions on how to do this? Thanks in advance!
d
I'm not sure if this would work for your use case, but what we've done is define
pex_binary
targets in a
tools/BUILD
file. Then we can do
pants run tools:$tool_name
. e.g. something like:
Copy code
pex_binary(
    name="http",
    entry_point="httpie.__main__:main",
    dependencies=[
        "3rdparty/python#httpie",
    ]
)
and then
pants run tools:http
. Theoretically, you could also invoke it directly with
pants run "3rdparty/python#httpie"
but that doesn't always work if pex doesn't know the right entrypoint. It's also useful to have the ability to specify multiple dependencies/plugins. An annoyance is that you have to put all the args after
--
e.g.:
pants run tools:http -- PUT <http://httpbin.org/put|httpbin.org/put> hello=world
b
hah, running directly the requirement is a nice trick ๐Ÿ‘Œ. Tried the pex binary angle as well, unfortunately neither works in this case, getting
Copy code
ImportError: No module named feast.__main__; 'feast' is a package and cannot be directly executed
my current (dirty) workaround is a python script invoking the cli with
subprocess.run
d
It should work if you set the right entry point. Thereโ€™s also a way to do that via an override in requirements
๐Ÿ‘€ 1
b
It does work! This is what I did:
Copy code
pex_binary(
    name="feast",
    entry_point="feast.cli",
    execution_mode="venv",
    dependencies=["python/feast:reqs"],
)
Awesome, thanks for the help @dazzling-pizza-75442 ๐Ÿ™