I've had a bit of an overall challenge when portin...
# general
i
I've had a bit of an overall challenge when porting over our
uvicorn
usage over to a pex/pants friendly world and would like some thoughts. I'm worried that our usage of
dramatiq
are going to hit even more sever issues when I get that far. Previous to trying out pants we evoke
uvicorn
via the cli. Evocation looking something like
Copy code
uvicorn --port 3001 --no-access-log --proxy-headers swizzler:app
I tried for a while to get it so the
pex_binary
target would be doing this basic thing for me. However I couldn't find anyway to both execute a cli as my entry point -and- give it options. I've gotten into a decent spot by instantiating unicorn programmatically, but I am concerned that for something like
dramatiq
I will need to be able to use the CLI with arguments. Is there a reasonable way to achieve that (or does anyone know if I can start
dramatiq
programmatically?)
b
However I couldn't find anyway to both execute a cli as my entry point -and- give it options.
Can you elaborate? Is
./pants run path/to/dir:target -- --port 3001 ...
not working?
i
well
uvicorn
and
dramatiq
are executables provided by the packages of the same name.
b
AH yeah. pretty sure that's doable in PEX but I'm not the PEX wizard 🧙‍♂️
i
Another example
Copy code
dramatiq swizzler.tasks:redis_broker -p 1 -t 8
e
Josh has it right, but, in more detail:
Copy code
./pants run path/to/dir:target -- --port 3001 --no-access-log --proxy-headers swizzler:app
Where path/to/dir/BUILD has:
Copy code
pex_binary(
    name="target",
    script="uvicorn",
    ...
)
What would be nice is to be able to seal in the
swizzler:app
argument to the PEX binary such that it always ran your
swizzler:app
via
uvicorn
without you having to type that. That feature idea is tracked here but it's had no one yet motivated to actually add the feature: https://github.com/pantsbuild/pex/issues/987
b
@enough-analyst-54434 is there a way to have the PEX contain multiple packages with scripts, and allow for executing one of them via the cmd-line? I think thats the intent here. One PEX, but
./pants run <pex_binary> -- script1 --arg1
as well as
./pants run <pex_binary> -- script2 --arg1
e
If
PEX_SCRIPT=script_name ...
or
PEX_MODULE=entry:point ...
aren't appealing, there is always https://pypi.org/project/conscript/
👀 1
I think the intent is actually exactly the pex issue I linked to.
b
Maintainers
John.Sirois
I know that guy!
🤣 1
👀 1
i
I did try with the script flag, but didn't see anyway to embed the arguments into it or the like, which is what I was kinda looking for.
It didn't even occur to me that you could then pass in arguments like that as part of the pants run command
e
Right, exactly. Maybe you'll be the person motivated enough to contribute https://github.com/pantsbuild/pex/issues/987!
i
for production environments it would be fine to do it that way, but for dev it'd be pretty annoying to have to do it that way 😕
e
s/fine & annoying/dangerous & error prone/! in my opinion. As far as I know Pants users currently write a thin shim script to bake things in that should be baked in as a result.
Not awesome.