I am trying to restructure an old python package that has some code inside its __init__.py
and I want to:
- Raise a deprecation warning when someone does
from mypackage import Foo
- Avoid a deprecation warning when someone does
python -m mypackage
That package can be executed via its __main__.py
, but by the time __main__
file is opened, python already loaded the __init__
file.
Is there a way to detect this and add a conditional into __init__.py
?
The goal is to deprecate all historical code form init and move it in modules, but I am trying to avoid breaking consumers and give them time to migrate their imports.
I should emphasized textmention that minimal version of python supported is py36.