Question about PEX binaries - is there a way to ru...
# general
b
Question about PEX binaries - is there a way to run a compound/multi-step command on startup (ex:
cmd1 && cmd2
)? Currently I have a binary definition that looks like this:
Copy code
pex_binary(
    name="scrapy",
    script="scrapy",
    dependencies=[
        ":config",
        ":poetry#Scrapy",
        "//:poetry#spacy",
        "scraper/src/py/scraper/scripts:lib",
        "scraper/src/py/scraper/scripts:shell_scripts",
    ],
    environment="linux_docker",
    # Optimal settings for Docker builds
    layout="packed",
    execution_mode="venv",
)
But I want to run another command prior to running
scrapy
for setup like so:
Copy code
python -m spacy download en_core_web_sm && scrapy <args>
My current plan is to create a shell script that downloads the spaCy model and then runs scrapy, and use that as the
entry_point
for the PEX - is that the right way to tackle this problem? Or is there a better solution?
e
Why not create a Python file and make that the entry point? The Python file can go nuts with compound actions.
b
This was my second alternative, which does make sense. Thanks for the pointer
e
I'm not sure why that wasn't your go-to idea, but scies offer that. Pants has no scie plugin yet though.
w
no "official" plugin
🙂
e
If it's not in Pants it effectively doesn't exist since we offer no way to discover plugins besides what you just did.
w
Yep, agreed.
e
@better-van-82973 a scie though, pretty much no matter how its build is packaged up in a plugin will take more lines of configuration and be more obtuse than a Python file for this purpose.
👍 1
b
@wide-midnight-78598 I found your code here for running uvicorn: https://github.com/sureshjoshi/pants-plugins/commit/31e238c638af02c388aaf17081da83afe7725c82 And that’s actually pretty close to what I want! I think the part where I got confused is that packages like uvicorn and scrapy expose external scripts to run and I was trying to run those. But since they’re just Python packages I can invoke them from a script as well
e
Well, I read quickly, but that example requires 0 custom code in Pants 2.16.+ because you can embed default env and args in a PEX: + https://www.pantsbuild.org/v2.16/docs/reference-pex_binary#codeargscode + https://www.pantsbuild.org/v2.16/docs/reference-pex_binary#codeenvcode
You just can embed shell strings like
x && y
.
b
Thanks for the help! I think I found another way around the problem for now but this is really good to know for other packages that expose executable scripts