If I install two python packages with the same top directory level name but different package names (as defined by the setup.py or perhaps another method of identification), will that conflict or will the 'namespaces' be merged?
For example, if I have the following structure:
repo1
mypkg/
__init__.py
compiler/...
setup.cfg -> name=repo1
repo2
mypkg/
__init__.py
runner/...
setup.cfg -> name=repo2
Can I install both of these without clashing? If yes, can I then import them like this:
from mypkg.runner import *
from mypkg.compiler import *
By default python would recognise only one of your two packages with one overwriting the other in the session.
If you put the following line in both your init.py files in the mypkg packages, you merge the packages together.
__path__ = __import__("pkgutil").extend_path(__path__, __name__)
What will happen is that instead of overwriting one package with another python puts the content of the packages into the same mypkg namespace.
However be warned, clashing modules or sub packages are not resolved automatically.
So if you create a runner sub package in both mypkg packages only one of the runner packages will be loaded.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With