-
-
Notifications
You must be signed in to change notification settings - Fork 65
✨ Add --factory
option
#64
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
base: main
Are you sure you want to change the base?
Conversation
This pull request has a merge conflict that needs to be resolved. |
@rasputyashka, thanks for working on this! This feature looks highly requested: #45 Could you please resolve merge conflicts and add tests? |
@YuriiMotov yeah, sure. |
34aa51a
to
a81980f
Compare
it tuned out that the only thing that should've been added is the factory argument to the cli. (btw uvicorn can detect whether passed object is a factory and call it, but it still recommends setting the factory flag explicitly). so recommended way of running an app with factory is |
We can also run the app as How about enabling this too? - if not isinstance(app, FastAPI):
+ if (not isinstance(app, FastAPI)) and (not inspect.isfunction(app)):
raise FastAPICLIException(
- f"The app name {app_name} in {mod_data.module_import_str} doesn't seem to be a FastAPI app"
+ f"The app name {app_name} in {mod_data.module_import_str} doesn't seem to be a FastAPI app or factory"
) Surprisingly, we can run server passing factory function that returns string (instead of FastAPI app) and it will not complain until it tries to handle first request.. But, it works the same way with Uvicorn, so I'm not sure we can handle this now |
I feel like there's need to rename '--app' argument to something like 'candidate' because factory is not an app (and i do NOT like this idea), that's why i decided not to implement --factory support for --app argument. (I mean user would do something like As of string behavior, I think uvicorn should handle these cases since we need to get the returned value (call the factory), check if this is an instance or a subclass of a FastAPI class (this would cause confusion during debugging) |
I actually don't see any problem with I think we can limit this PR to only support
|
Well, the --app issue sounds more like a naming issue for me, that's why I'd like to wait for the owner\contributor (all these fixes require owner's interventions) I'm OK with having this MR as an entrypoint's option but not sure if this is all we can do for now (since patching current implementation is easy and quick). Let's wait for anybody who can merge the changes to hear their opinion. |
This comment was marked as resolved.
This comment was marked as resolved.
To sum up: Extra arg to the cli (--factory) was added (works only with --entrypoint argument). Recommended way of running an app with factory is I considered not to add factory argument to the use case when user runs
because @YuriiMotov suggested this to improve current behavior:
|
I thought a bit more and I think suggested |
I do like the idea, let's see what maintainers think about this |
It's up to you, but I would recommend you edit this PR to make it ready to be merged. |
I have seen sort of the same implementation in one of pull requests, but I didn't like it, so I've written my own, simpler one.
I haven't written any tests, but I have some spare time to do so if needed. I am not sure if the help messages look good, but I can consider thinking of it if you want to merge this request (or you can do it yourself).