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

Upgrade to Uvicorn 0.15 and implement new reload options #39

Merged
merged 4 commits into from
Aug 24, 2021

Conversation

br3ndonland
Copy link
Owner

@br3ndonland br3ndonland commented Aug 24, 2021

Description

PR #21 implemented the Uvicorn reload_dirs setting, enabling file watching and hot-reloading with watchgod for development.

In encode/uvicorn#820 and Uvicorn 0.15, additional reload configuration options were added:

  • reload_delay (CLI equivalent: --reload-delay)
  • reload_excludes (CLI equivalent: --reload-exclude)
  • reload_includes (CLI equivalent: --reload-include)

This PR will implement the new Uvicorn reload options. The options will be configured with the following environment variables:

  • RELOAD_DELAY
  • RELOAD_EXCLUDES
  • RELOAD_INCLUDES

Changes

Related

#21
encode/uvicorn#820
https://github.com/encode/uvicorn/releases/tag/0.15.0

This commit will implement the new Uvicorn 0.15 reload options:

- `reload_delay` (env: `RELOAD_DELAY`, CLI: `--reload-delay`)
- `reload_excludes` (env: `RELOAD_EXCLUDES`, CLI: `--reload-exclude`)
- `reload_includes` (env: `RELOAD_INCLUDES`, CLI: `--reload-include`)

The following auxiliary updates will also be made:

- Move the string splitting logic previously used for `reload_dirs` into
  a separate helper method in `start.py` to avoid code duplication
- Move the Uvicorn options customized for testing into a class attribute
  on `test_start.py::TestSetUvicornOptions`
- Remove unnecessary test assertions (such as asserting that monkeypatch
  actually sets environment variables)
- Parametrize tests with tuples instead of lists (lists unnecessary)
This commit will document the new Uvicorn 0.15 reload options:

- `reload_delay` (env: `RELOAD_DELAY`, CLI: `--reload-delay`)
- `reload_excludes` (env: `RELOAD_EXCLUDES`, CLI: `--reload-exclude`)
- `reload_includes` (env: `RELOAD_INCLUDES`, CLI: `--reload-include`)
@vercel
Copy link

vercel bot commented Aug 24, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/br3ndonland/inboard/5haxC2uzy9QxrWZrGZKeCiiKdnxH
✅ Preview: https://inboard-git-uvicorn-015-br3ndonland.vercel.app

@codecov
Copy link

codecov bot commented Aug 24, 2021

Codecov Report

Merging #39 (75b81a4) into develop (8b0ef55) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##           develop       #39   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           10        10           
  Lines          271       276    +5     
=========================================
+ Hits           271       276    +5     
Flag Coverage Δ
unit 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
inboard/start.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8b0ef55...75b81a4. Read the comment docs.

* 'Refactored by Sourcery'

* Fix formatting of @sourcery-ai[bot] refactoring

#40

The Sourcery refactoring is acceptable, but code was not formatted with
Black. This commit will fix the formatting to pass the pre-commit hooks.

Co-authored-by: Sourcery AI <>
Co-authored-by: Brendon Smith <bws@bws.bio>
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Aug 24, 2021

Sourcery Code Quality Report

✅  Merging this PR will increase code quality in the affected files by 0.54%.

Quality metrics Before After Change
Complexity 0.95 ⭐ 1.01 ⭐ 0.06 👎
Method Length 69.08 🙂 65.44 🙂 -3.64 👍
Working memory 7.94 🙂 8.03 🙂 0.09 👎
Quality 75.16% 75.70% 0.54% 👍
Other metrics Before After Change
Lines 488 491 3
Changed files Quality Before Quality After Quality Change
inboard/start.py 74.88% 🙂 74.22% 🙂 -0.66% 👎
tests/test_start.py 75.26% ⭐ 76.38% ⭐ 1.12% 👍

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
tests/test_start.py TestStartServer.test_start_server_uvicorn_reload_dirs 2 ⭐ 158 😞 12 😞 56.47% 🙂 Try splitting into smaller methods. Extract out complex expressions
inboard/start.py set_app_module.set_uvicorn_options 2 ⭐ 94 🙂 14 😞 61.22% 🙂 Extract out complex expressions
tests/test_start.py TestStartServer.test_start_server_uvicorn_gunicorn 0 ⭐ 110 🙂 10 😞 67.66% 🙂 Extract out complex expressions
tests/test_start.py TestStartServer.test_start_server_uvicorn_gunicorn_custom_config 0 ⭐ 122 😞 9 🙂 68.19% 🙂 Try splitting into smaller methods
tests/test_start.py TestSetUvicornOptions.test_set_uvicorn_options_custom 1 ⭐ 57 ⭐ 11 😞 72.48% 🙂 Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

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!

Help us improve this quality report!

@br3ndonland br3ndonland merged commit 043c929 into develop Aug 24, 2021
@br3ndonland br3ndonland deleted the uvicorn-0.15 branch August 24, 2021 00:54
br3ndonland added a commit that referenced this pull request Aug 29, 2021
#39
#41

Uvicorn 0.15 introduced new configuration options. If these options are
set when Uvicorn < 0.15 is installed, exceptions may be raised.

This commit will update start.py to only set Uvicorn 0.15 options when
Uvicorn >= 0.15 is installed.
br3ndonland added a commit that referenced this pull request Aug 29, 2021
#21
#39
#41

PR #21 introduced support for the `reload_dirs` Uvicorn option. In order
to support this option, the `RELOAD_DIRS` environment variable was split
into a list of directories to watch and reload.

This commit will clarify the syntax used to split the variable value.
Rather than using single-letter variable names, the names will be:

- `option`: environment variable key
- `option_value`: environment variable value
- `option_item`: each item in value after it has been split into a list
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.

1 participant