From 77468df7697ec2f2962e77d7a02e0bc22b6f9c79 Mon Sep 17 00:00:00 2001 From: Yezy Ilomo Date: Tue, 9 Jun 2020 13:36:32 +0300 Subject: [PATCH] Add --app-dir option for running uvicorn from any location (#619) Add '--app-dir' option to specify application directory when running uvicorn from any location Closes #549 --- docs/deployment.md | 3 +++ uvicorn/main.py | 10 +++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/docs/deployment.md b/docs/deployment.md index d2e94b7ea..6ff8144f1 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -87,6 +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, by + adding this to the PYTHONPATH. Defaults to + the current working directory. --help Show this message and exit. ``` diff --git a/uvicorn/main.py b/uvicorn/main.py index 7d63c0f77..25eb54adb 100644 --- a/uvicorn/main.py +++ b/uvicorn/main.py @@ -256,6 +256,13 @@ def print_version(ctx, param, value): is_eager=True, help="Display the uvicorn version and exit.", ) +@click.option( + "--app-dir", + "app_dir", + default=".", + show_default=True, + help="Look for APP in the specified directory, by adding this to the PYTHONPATH. Defaults to the current working directory.", +) def main( app, host: str, @@ -290,8 +297,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,