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
1 change: 1 addition & 0 deletions docs/deployment.md
Expand Up @@ -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.
```

Expand Down
1 change: 1 addition & 0 deletions docs/settings.md
Expand Up @@ -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 `"<module>:<attribute>"`.
* `--app-dir <str>` - Specifty application directory.
yezyilomo marked this conversation as resolved.
Show resolved Hide resolved
yezyilomo marked this conversation as resolved.
Show resolved Hide resolved

## Socket Binding

Expand Down
6 changes: 5 additions & 1 deletion uvicorn/main.py
Expand Up @@ -256,6 +256,9 @@ 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."
yezyilomo marked this conversation as resolved.
Show resolved Hide resolved
)
def main(
app,
host: str,
Expand Down Expand Up @@ -290,8 +293,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