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

Add --app-dir option for running uvicorn from any location #619

Merged
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