-
-
Notifications
You must be signed in to change notification settings - Fork 763
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
allow uvicorn.run to also accept app-dir kwarg #1126
Comments
Yes, please! I just ran into this trying to run uvicorn programmatically, with a simple directory structure like:
My uvicorn invocation is in |
PR is already created. Waiting for reviews. |
@command-tab even without this PR, it is not "impossible", you can also easily do the same thing yourself: sys.path.append('app') # or possibly something more absolute like os.path.abspath(os.path.join(__file__, '..', 'app'))
uvicorn.run('main:app') |
Checklist
Is your feature related to a problem? Please describe.
The issue is: I have a script using uvicorn.run, but I can only run it from a specific cwd, else it will fail with ImportError.
Describe the solution you would like.
I would like the --app-dir functionality to be available in uvicorn.run() as well.
I.e.: to be able to run a script containing a call to uvicorn.run regardless of the cwd.
Describe alternatives you considered
Doing it myself, i.e. calling sys.path.insert(0, abs_path_to_my_project_root_folder), but it feels to me that if this functionality is implemented in main() but not in run() (which from reading the code are the same thing) there must be something wrong with the uvicorn code.
Additional context
#549
#619
77468df
My guess is that this commit implemented the behaviour in the wrong place. Instead of 'consuming' the app_dir argument inside main(), it should have been passed down as-is to run() where it will be processed.
(I volunteer to do the job, if we agree that there is a problem)
The text was updated successfully, but these errors were encountered: