Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add support for python -m gunicorn #2344

Merged
merged 1 commit into from
May 29, 2020
Merged

✨ Add support for python -m gunicorn #2344

merged 1 commit into from
May 29, 2020

Conversation

tiangolo
Copy link
Contributor

✨ Add support for python -m gunicorn.

This just adds a simple __main__.py replicating the script defined in setup.py.

That adds support for python -m gunicorn, as described here in the Python docs.

It is useful when python or equivalent is available as a command but gunicorn is not, even though it is installed and available to import. And where the idea is still to call it from the CLI and not importing and running from code... 🤷‍♂️

I know that sounds contrived, but the specific use case is Pex: https://pex.readthedocs.io/

It is based on "zip applications" from this PEP 441.

So, it would be called like:

$ ./some-binary-pex-file -m gunicorn

Copy link
Collaborator

@tilgovi tilgovi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Great idea.

@tilgovi tilgovi merged commit 4bed9e7 into benoitc:master May 29, 2020
@jamadden
Copy link
Collaborator

jamadden commented May 29, 2020

I think this is a great idea too!

Should this be documented (EDIT: and tested) somewhere?

@tilgovi
Copy link
Collaborator

tilgovi commented May 29, 2020

Good point, @jamadden :)

@tiangolo tiangolo deleted the dunder-main branch May 30, 2020 08:28
@tiangolo
Copy link
Contributor Author

Thanks! 🚀


About documenting it, let me know if you would like it to be explicitly stated, probably as a small note somewhere. Right now it would just work like e.g. pip or python -m pip.

I also understand that python -m gunicorn would not be the "canonical form" to call it, and I admit it is a rather "exotic" use case 😅 , so you might also want to just leave it out of the docs, just to not confuse users (I've done that in FastAPI 🤷‍♂️ ), but let me know if you prefer to have it explicit somewhere.


About tests, I didn't find something to test the CLI behavior to try and include this there, the option I would think of would be a subprocess calling Python directly and checking the string from something like:

python -m gunicorn --version
__main__.py (version 20.0.4)

That's what I do for testing some corner cases in Typer. But that could mean an extra layer of complexity and a bit of time increase for the tests (probably just a couple of secs though). If that sounds fine for you, I can sketch a PR with it. On the other side, do you have an idea of a better/different approach that you would prefer?

@di
Copy link
Contributor

di commented Oct 15, 2020

+1 to documenting this somewhere, at the very least in the changelog (but it looks like this just gets updated on release?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants