Skip to content

✨ Add support for modules with __main__.py #10

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

Closed

Conversation

Olegt0rr
Copy link

@Olegt0rr Olegt0rr commented May 3, 2024

Some projects use __main__.py as the default module entry point:
https://docs.python.org/3/library/__main__.html#main-py-in-python-packages

It would be nice to support it out of the box

@Olegt0rr Olegt0rr marked this pull request as draft May 3, 2024 10:04
@tiangolo
Copy link
Member

tiangolo commented May 7, 2024

Thanks for the interest! Could you please start with a question discussion here? https://github.com/tiangolo/fastapi-cli/discussions/new?category=questions

That will make it easier to understand your use case better.

From my understanding, __main__.py is what is called when calling a module/package directly from the command line, e.g. python -m my_package.some_module.

That would look for a file my_package/some_module/__main__.py, and if found, would just execute/import it, and importing it would have whatever is the intended side effect of calling that module as a script.

This means that in the case of FastAPI, that module would probably have something that would be run directly when imported, instead of just having a variable app or something, that module would probably call uvicorn.run() directly or something similar.

In that case, I don't think it would make sense for FastAPI CLI to import from there...

It was actually in an early version of my local code, but I realized it didn't really make sense to me.

But if you feel there's another use case I'm not seeing, please create a new discussion with your example code and we can continue from there. 🤓

For now, I'll pass on this one. ☕

@tiangolo tiangolo closed this May 7, 2024
patrick91 added a commit to patrick91/fastapi-cli that referenced this pull request Sep 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants