Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Content-Length: 268160 | pFad | http://github.com/ets-labs/python-dependency-injector/discussions/724
80Fetched URL: http://github.com/ets-labs/python-dependency-injector/discussions/724
Alternative Proxies:
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I am developing a package which can be imported or can be executed from command line as an module. I am currently wiring all the packages inside the
__init__.py
file. So when I import the package the__init__.py
file helps to initialize the resources in my container and wires it -And when my package is ran like an module then the control should go to
__main__.py
file and helps with initializing container resources and wiring the packages.I noticed when I added
__main__.py
file and imported my package, the control will go to__init__.py
to initialize the resources and post wiring control it again goes to the__main__.py
file. This is causing the container to be initialized twice and wires the packages.Also vice-versa, when I run my package as an module the control is going to
__init__.py
and later to the__main__.py
. Is this expected?Expected behavior should be -
__init__.py
file.__main__.py
file.EDIT:
So I figured if I run the package with
-m
then it will run the__init__.py
file. But still I am not able to figure out when I import my package and run it, why it is still running the__main__.py
? I am not importing__main__.py
anywhere.EDIT 2:
I figured it is
container.wire(packages=[__name__])
causing to run__main__.py
content.Beta Was this translation helpful? Give feedback.
All reactions