https://pantsbuild.org/ logo
#general
Title
# general
g

gorgeous-eve-12553

08/01/2020, 7:11 PM
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

happy-kitchen-89482

08/03/2020, 4:37 AM
We have examples internally, I'm working on a public example.
m

miniature-lamp-45970

08/04/2020, 10:41 PM
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

happy-kitchen-89482

08/04/2020, 11:32 PM
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

miniature-lamp-45970

08/05/2020, 12:09 AM
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

happy-kitchen-89482

08/05/2020, 2:13 AM
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.
3 Views