I'm struggling to get gunicorn running a server fo...
# general
m
I'm struggling to get gunicorn running a server for me because I can't figure out how to include my python when using the
pex_binary
's
script
tag. I get the sense that I'm missing something obvious. Example:
Copy code
# my/code/BUILD

python_sources()

pex_binary(
    name="my_server",
    script="gunicorn",
    args=[
        "--timeout",
        "120",
        "my.code.server:create_app()",
    ],
    dependencies=[
        "//.build/requirements:reqs#gunicorn",
        # What do I put here to include the my.code.server + depenencies?
    ],
)
Basically, I'm getting a "No module found" error when I try to run the resulting PEX, and indeed, the
my.code.server
module does not seem to be packaged in the PEX file. There are two
gunicorn
examples that I was able to find. The one I based this on appears here, but doesn't seem to be complete. (Unless I'm missing something, I don't think the required code would be packaged?) The second example I found appears in the Django example, but it requires a lot of shim code that the
script
tag is supposed to avoid. Thanks in advance!
I think I've figured this out, but it seems highly non-obvious to me (maybe someone can point me in the direction of documentation that can help me understand target names):
Copy code
# my/code/BUILD

python_sources(name="my_code_src")

pex_binary(
    name="my_server",
    script="gunicorn",
    args=[
        "--timeout",
        "120",
        "my.code.server:create_app()",
    ],
    dependencies=[
        "//.build/requirements:reqs#gunicorn",
        "//my/code/server.py:my_code_src", # This was not obvious to me...
    ],
)
c
normally, when you use the
entry_point
for a
pex_binary
pants figures out the dependency for you, but here the dependency is embedded in the
args
which pants doesn't introspect, hence you need to add the dependency on your application code explicitly, otherwise pants doesn't know it should be included.