Skip to content

Commit

Permalink
Add --app-dir option for running uvicorn from any location (#619)
Browse files Browse the repository at this point in the history
Add '--app-dir' option to specify application directory when running uvicorn from any location
Closes #549
  • Loading branch information
yezyilomo authored Jun 9, 2020
1 parent 9b92925 commit 77468df
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions docs/deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
```

Expand Down
10 changes: 9 additions & 1 deletion uvicorn/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 77468df

Please sign in to comment.