Skip to content

Commit 77468df

Browse files
authored
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
1 parent 9b92925 commit 77468df

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

docs/deployment.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ Options:
8787
[default: TLSv1]
8888
--header TEXT Specify custom default HTTP response headers
8989
as a Name:Value pair
90+
--app-dir TEXT Look for APP in the specified directory, by
91+
adding this to the PYTHONPATH. Defaults to
92+
the current working directory.
9093
--help Show this message and exit.
9194
```
9295

uvicorn/main.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,13 @@ def print_version(ctx, param, value):
256256
is_eager=True,
257257
help="Display the uvicorn version and exit.",
258258
)
259+
@click.option(
260+
"--app-dir",
261+
"app_dir",
262+
default=".",
263+
show_default=True,
264+
help="Look for APP in the specified directory, by adding this to the PYTHONPATH. Defaults to the current working directory.",
265+
)
259266
def main(
260267
app,
261268
host: str,
@@ -290,8 +297,9 @@ def main(
290297
ssl_ciphers: str,
291298
headers: typing.List[str],
292299
use_colors: bool,
300+
app_dir: str,
293301
):
294-
sys.path.insert(0, ".")
302+
sys.path.insert(0, app_dir)
295303

296304
kwargs = {
297305
"app": app,

0 commit comments

Comments
 (0)