I'm having some issues porting an app that uses uv...
# general
a
I'm having some issues porting an app that uses uvicorn to Pants. My BUILD-file is similar to this:
Copy code
resources(sources=[".env"], name=".env")

pex_binary(
    script="uvicorn",
    dependencies=[
        "python/my-package/my_package",
        "3rdparty/python#uvicorn",
        ":.env",
    ],
)
I try to run it as:
./dist/python.my-package/my_package.pex --env-file python/my-package/.env my_package.main:app
But get the following error:
Copy code
INFO:     Loading environment from 'python/tag2-backend-web/.env'
usage: my_package.pex [-h] [--host HOST] [--port PORT] [--reload RELOAD] [--workers WORKERS] [--log-level LOG_LEVEL] [--log-file LOG_FILE] [--log-format LOG_FORMAT] [--log-rotation LOG_ROTATION]
                            [--env-file ENV_FILE] [--rmq-host RMQ_HOST] [--rmq-port RMQ_PORT] [--rmq-username RMQ_USERNAME] [--rmq-password RMQ_PASSWORD]
my_package.pex: error: unrecognized arguments: my_package.main:app
I've also tried running it as:
./dist/python.my-package/my_package.pex -- --env-file python/my-package/.env my_package.main:app
1
h
The error message is telling you what the problem is.
Look at the expected command line in that help message. That my_package.main:app arg is not expected.
The pex is running correctly AFAICT and the code it executes is erroring and giving you that message
a
Yeah, but I couldn't figure out why because the app would seemingly start OK and then crash, and I've never had this problem with Uvicorn on other projects. From further inspection (I inherited this codebase from someone else) they were doing some strange things with argparse and normally starting Uvicorn from the code itself. As a result they had never passed in the app directly on the command line as I was doing now. So you're absolutely correct, it was the running code, not the PEX itself that had an issue.