I have a namespace package called foo, which contains multiple distribution packages:
Additionally, in the project root, there is another directory also named foo, containing additional packages (e.g., foo.bar_z). (All packages originally started being part of this foo namespace in the project; they are provided by different teams and are stored in separate repos, then rebuilt into the project by adding the source code under the foo namespace. I'm trying to move these packages outside of the projects; but each team will need to have in their projects their own package to keep working on it and provide new versions. These team packages do have dependencies of some of the core packages in the namespace, and sometimes from some of the other team packages). The challenge I'm trying to overcome is how to have a team work on their own package in the project's foo namespace, while depending on the ones installed in site-packages by pip.
The Issue: This setup works as expected on Windows with python 3.x (I can import both foo.bar_one and foo.bar_z), but on Linux, I encounter namespace-related import issues:
If site-packages appears first in PYTHONPATH, I can import foo.bar_one, but foo.bar_z fails, stating that bar_z does not exist within the foo namespace.
If the project root appears first in PYTHONPATH, I can import foo.bar_z, but foo.bar_one fails, stating that bar_one does not exist within the foo namespace.
Questions:
Any insights or recommendations on resolving this would be greatly appreciated!
EDIT:
EDIT 2: I found this regarding the namespaces, which leads me to believe that what I'm trying to do is possible, and in fact it seems to work on Windows.
5.2.2. Namespace packages A namespace package is a composite of various portions, where each portion contributes a subpackage to the parent package. Portions may reside in different locations on the file system. Portions may also be found in zip files, on the network, or anywhere else that Python searches during import. Namespace packages may or may not correspond directly to objects on the file system; they may be virtual modules that have no concrete representation.
Namespace packages do not use an ordinary list for their path attribute. They instead use a custom iterable type which will automatically perform a new search for package portions on the next import attempt within that package if the path of their parent package (or sys.path for a top level package) changes.
With namespace packages, there is no parent/init.py file. In fact, there may be multiple parent directories found during import search, where each one is provided by a different portion. Thus parent/one may not be physically located next to parent/two. In this case, Python will create a namespace package for the top-level parent package whenever it or one of its subpackages is imported.
See also PEP 420 for the namespace package specification. 5.2.2. Namespace packages
In my question, foo is the namespace, bar_one and bar_z are two portions that are not physically located next to each other. Am I reading this correctly?