I see there was conversation a few month back abou...
# general
g
I see there was conversation a few month back about using a WSGI or ASGI worker as your entry_point, is there an example of this working if it is? For example:
gunicorn main:app
(Pants 2.0)
h
We have examples internally, I'm working on a public example.
m
That would be really helpful @happy-kitchen-89482
@happy-kitchen-89482 can you share the snippet of python_binary, especially the entry_point for the executable as the executable is gunicorn. Refactoring an existing python project using Pants and blocked on it
h
It's a bit of a hack. The target is
Copy code
python_binary(
  name = 'foo-gunicorn',
  entry_point = foo.gunicorn_main',
  zip_safe=False,
  dependencies = [...],
)
And
foo/gunicorn_main.py
is a wrapper around the gunicorn entry point that sets up Django and injects the gunicorn config.
So that file, very roughly, does some setup and calls
gunicorn.app.wsgiapp.WSGIApplication.run()
More specifically, we subclass
WSGIApplication
and implement
load_config()
to call
self.load_config_from_file(conf_path)
where
conf_path
points to the config for specific app we're running.
This is all a hack so that the Pants entrypoint can be zero-arg
m
got it. Thanks @happy-kitchen-89482
@happy-kitchen-89482 Does this look right? If WSGIApplication.run is invoked, how is the subclass instance picked up by gunicorn to load the asked config file?
h
We have a tiny wrapper for each application, that just contains
Copy code
if __name__ == "__main__":
    CustomGunicornService.from_file_name(__file__).run_gunicorn()
And
from_file_name()
uses that arg to figure out who ran it, and construct an appropriate reference to a config file.