From 7973a0e0b5a43d812fd077485f080a7244bd35f8 Mon Sep 17 00:00:00 2001 From: yezy Date: Thu, 9 Apr 2020 19:38:58 +0300 Subject: [PATCH 01/12] Add '--app-dir' option to specify application directory when running uvicorn from any location Closes #549 --- uvicorn/main.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/uvicorn/main.py b/uvicorn/main.py index 46c3d9427..a22e88d05 100644 --- a/uvicorn/main.py +++ b/uvicorn/main.py @@ -256,6 +256,12 @@ def print_version(ctx, param, value): is_eager=True, help="Display the uvicorn version and exit.", ) +@click.option( + "--app-dir", + "app_dir", + default=".", + help="Specifty application directory.", +) def main( app, host: str, @@ -290,8 +296,9 @@ def main( ssl_ciphers: str, headers: typing.List[str], use_colors: bool, + app_dir: str, ): - sys.path.insert(0, ".") + sys.path.insert(0, app_dir) kwargs = { "app": app, From 669ec949507d48233a915eaa3c72be861142e664 Mon Sep 17 00:00:00 2001 From: yezy Date: Thu, 9 Apr 2020 19:40:47 +0300 Subject: [PATCH 02/12] Add documentation for '--app-dir' option --- docs/deployment.md | 1 + docs/settings.md | 1 + 2 files changed, 2 insertions(+) diff --git a/docs/deployment.md b/docs/deployment.md index d07e64177..12706aecf 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -87,6 +87,7 @@ Options: [default: TLSv1] --header TEXT Specify custom default HTTP response headers as a Name:Value pair + --app-dir TEXT Specifty application directory. --help Show this message and exit. ``` diff --git a/docs/settings.md b/docs/settings.md index b8b29b668..5289d075b 100644 --- a/docs/settings.md +++ b/docs/settings.md @@ -8,6 +8,7 @@ equivalent keyword arguments, eg. `uvicorn.run("example:app", port=5000, reload= ## Application * `APP` - The ASGI application to run, in the format `":"`. +* `--app-dir ` - Specifty application directory. ## Socket Binding From 815e9560b2e164dc863b4fffdbd36280b8e51493 Mon Sep 17 00:00:00 2001 From: yezy Date: Thu, 9 Apr 2020 20:18:07 +0300 Subject: [PATCH 03/12] Format code with black --- uvicorn/main.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/uvicorn/main.py b/uvicorn/main.py index a22e88d05..d97e505e5 100644 --- a/uvicorn/main.py +++ b/uvicorn/main.py @@ -257,10 +257,7 @@ def print_version(ctx, param, value): help="Display the uvicorn version and exit.", ) @click.option( - "--app-dir", - "app_dir", - default=".", - help="Specifty application directory.", + "--app-dir", "app_dir", default=".", help="Specifty application directory." ) def main( app, From c4ee8569e2156093461684ac7181e3d12052eca7 Mon Sep 17 00:00:00 2001 From: Yezy Ilomo Date: Fri, 10 Apr 2020 14:09:37 +0300 Subject: [PATCH 04/12] Update docs/settings.md Update --app-dir description Co-Authored-By: Florimond Manca --- docs/settings.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/settings.md b/docs/settings.md index 5289d075b..f45afa660 100644 --- a/docs/settings.md +++ b/docs/settings.md @@ -8,7 +8,7 @@ equivalent keyword arguments, eg. `uvicorn.run("example:app", port=5000, reload= ## Application * `APP` - The ASGI application to run, in the format `":"`. -* `--app-dir ` - Specifty application directory. +* `--app-dir ` - Look for `APP` in the specified directory. Defaults to `.`. ## Socket Binding From 06f45b62a61b04d7d83ec6271d6ee086c752e10a Mon Sep 17 00:00:00 2001 From: yezy Date: Fri, 10 Apr 2020 14:32:44 +0300 Subject: [PATCH 05/12] Remove --app-dir from application settings section --- docs/settings.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/settings.md b/docs/settings.md index f45afa660..b8b29b668 100644 --- a/docs/settings.md +++ b/docs/settings.md @@ -8,7 +8,6 @@ equivalent keyword arguments, eg. `uvicorn.run("example:app", port=5000, reload= ## Application * `APP` - The ASGI application to run, in the format `":"`. -* `--app-dir ` - Look for `APP` in the specified directory. Defaults to `.`. ## Socket Binding From de57311886980a4c0993348cf4a63ecef2e922fb Mon Sep 17 00:00:00 2001 From: yezy Date: Fri, 10 Apr 2020 14:33:51 +0300 Subject: [PATCH 06/12] Update --app-dir help message and set show_default=True --- uvicorn/main.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/uvicorn/main.py b/uvicorn/main.py index d97e505e5..e1d27ca66 100644 --- a/uvicorn/main.py +++ b/uvicorn/main.py @@ -257,7 +257,11 @@ def print_version(ctx, param, value): help="Display the uvicorn version and exit.", ) @click.option( - "--app-dir", "app_dir", default=".", help="Specifty application directory." + "--app-dir", + "app_dir", + default=".", + show_default=True, + help="Look for APP in the specified directory. Defaults to '.'", ) def main( app, From 6f60120d7726625e3c162940e6b8112110cafd82 Mon Sep 17 00:00:00 2001 From: yezy Date: Fri, 10 Apr 2020 14:34:34 +0300 Subject: [PATCH 07/12] Update --app-dir description --- docs/deployment.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/deployment.md b/docs/deployment.md index 12706aecf..1f238ebe5 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -87,7 +87,7 @@ Options: [default: TLSv1] --header TEXT Specify custom default HTTP response headers as a Name:Value pair - --app-dir TEXT Specifty application directory. + --app-dir TEXT Look for APP in the specified directory. Defaults to '.' --help Show this message and exit. ``` From 582e66422157aae4bfae8806cb189a773f653ecd Mon Sep 17 00:00:00 2001 From: yezy Date: Tue, 9 Jun 2020 12:40:27 +0300 Subject: [PATCH 08/12] Rephrase --app-dir help text --- docs/deployment.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/deployment.md b/docs/deployment.md index bcebe2302..49af94021 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -87,7 +87,7 @@ Options: [default: TLSv1] --header TEXT Specify custom default HTTP response headers as a Name:Value pair - --app-dir TEXT Look for APP in the specified directory. Defaults to '.' + --app-dir TEXT Look for APP in the specified directory. Defaults to the current working directory --help Show this message and exit. ``` From d87000d979d8adb4def11513b9e2f4fa51e75257 Mon Sep 17 00:00:00 2001 From: yezy Date: Tue, 9 Jun 2020 12:46:12 +0300 Subject: [PATCH 09/12] Rephrase --app-dir help text --- uvicorn/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uvicorn/main.py b/uvicorn/main.py index cb10c4e31..908009bdb 100644 --- a/uvicorn/main.py +++ b/uvicorn/main.py @@ -261,7 +261,7 @@ def print_version(ctx, param, value): "app_dir", default=".", show_default=True, - help="Look for APP in the specified directory. Defaults to '.'", + help="Look for APP in the specified directory. Defaults to the current working", ) def main( app, From 912057202129de0219fdc815735a9c77efbf55b6 Mon Sep 17 00:00:00 2001 From: yezy Date: Tue, 9 Jun 2020 13:27:04 +0300 Subject: [PATCH 10/12] Edit --app-dir help text --- uvicorn/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uvicorn/main.py b/uvicorn/main.py index 908009bdb..6280db132 100644 --- a/uvicorn/main.py +++ b/uvicorn/main.py @@ -261,7 +261,7 @@ def print_version(ctx, param, value): "app_dir", default=".", show_default=True, - help="Look for APP in the specified directory. Defaults to the current working", + help="Look for APP in the specified directory. Defaults to the current working directory", ) def main( app, From dd63a408b230c883960c86d1fc08bb654ec46eaa Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Tue, 9 Jun 2020 11:29:55 +0100 Subject: [PATCH 11/12] Update main.py --- uvicorn/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uvicorn/main.py b/uvicorn/main.py index 6280db132..25eb54adb 100644 --- a/uvicorn/main.py +++ b/uvicorn/main.py @@ -261,7 +261,7 @@ def print_version(ctx, param, value): "app_dir", default=".", show_default=True, - help="Look for APP in the specified directory. Defaults to the current working directory", + help="Look for APP in the specified directory, by adding this to the PYTHONPATH. Defaults to the current working directory.", ) def main( app, From 4e0565e658a47a09582c87604f52c5780035a46f Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Tue, 9 Jun 2020 11:30:49 +0100 Subject: [PATCH 12/12] Update deployment.md --- docs/deployment.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/deployment.md b/docs/deployment.md index 49af94021..6ff8144f1 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -87,7 +87,9 @@ Options: [default: TLSv1] --header TEXT Specify custom default HTTP response headers as a Name:Value pair - --app-dir TEXT Look for APP in the specified directory. Defaults to the current working directory + --app-dir TEXT Look for APP in the specified directory, by + adding this to the PYTHONPATH. Defaults to + the current working directory. --help Show this message and exit. ```