-
Notifications
You must be signed in to change notification settings - Fork 17
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
Refactor start script to improve organization of Gunicorn and Uvicorn server settings #30
Conversation
#2 #3 ff9155a The core logic for running the Uvicorn and Gunicorn+Uvicorn servers is located in start.py. The `start.start_server()` method is what actually starts the servers. Uvicorn and Gunicorn are configured differently, so and the `start.start_server()` method ended up getting quite complex in order to handle these differences. This commit will refactor the configuration options passed to Gunicorn and Uvicorn into separate functions. The result is a start script with the same programming API and almost exactly the same line length, but improved readability and separation of concerns. - Refactor Gunicorn and Uvicorn options into separate functions, `start.set_gunicorn_options()` and `start.set_uvicorn_options()`. - Remove `start.set_conf_path()`: this function was written in a general way to find either Gunicorn or logging configuration files. Starting with ff9155a, it became used only for Gunicorn configuration files. Now that the configuration options for Gunicorn are in a separate function, the logic from `set_conf_path()` can be moved there. - Simplify logger type annotations: simply `import logging` and annotate functions with `logging.Logger` instead of having a separate import for `from logging import Logger`. - Reorganize test_start.py to more clearly reflect order of start.py
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 0.46%.
Here are some functions in these files that still need a tune-up:
Legend and ExplanationThe emojis denote the absolute quality of the code:
The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request. Please see our documentation here for details on how these metrics are calculated. We are actively working on this report - lots more documentation and extra metrics to come! Let us know what you think of it by mentioning @sourcery-ai in a comment. |
Codecov Report
@@ Coverage Diff @@
## develop #30 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 9 9
Lines 253 256 +3
=========================================
+ Hits 253 256 +3
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
#30 This commit will add some minor improvements to the refactor of the Gunicorn and Uvicorn setup in start.py (added in #30). - Pass `app_module` into `start.set_gunicorn_options()`, rather than appending later when running the server - Read environment variables earlier in `start.set_uvicorn_options()` to provide consistent syntax when returning the dictionary at the end: this strategy seems opposed to the one taken in `gunicorn_conf.py` (read environment variables when they are used, rather than before), but the end result is similar (consistent syntax in the settings).
Description
The core logic for running the Uvicorn and Gunicorn+Uvicorn servers is located in start.py. The
start.start_server()
method is what actually starts the servers. Gunicorn and Uvicorn are configured differently, so thestart.start_server()
method ended up getting quite complex in order to handle these differences.This PR will refactor the configuration options passed to Gunicorn and Uvicorn into separate functions. The result is a start script with the same programming API and almost exactly the same line length, but improved readability and separation of concerns.
Changes
start.set_gunicorn_options()
andstart.set_uvicorn_options()
.start.set_conf_path()
: this function was written in a general way to find either Gunicorn or logging configuration files. Starting with ff9155a, it became used only for Gunicorn configuration files. Now that the configuration options for Gunicorn are in a separate function, the logic fromset_conf_path()
can be moved there.import logging
and annotate logger objects passed in as function arguments withlogging.Logger
instead of having a separate import forfrom logging import Logger
.Related
#2
#3
ff9155a