high-psychiatrist-4761
06/26/2025, 7:02 PMnamespace package
. I have following project structure. I make src/python/some_package
as namespace package. Then I do pants package src/python/some_package/package1:dist
, it generate the whl and tar files. When I check the package1-0.1.0.dist-info/namespace_packages.txt
inside the dist/package1-0.1.0-py3-none-any.whl
, it is empty. I am wondering if pants support namespace package correctly?
.
├── 3rdparty
│ └── python
│ └── python-default.lock
├── dist
│ ├── package1-0.1.0-py3-none-any.whl
│ └── package1-0.1.0.tar.gz
├── pants.toml
├── src
│ └── python
│ └── some_package
│ ├── lib1
│ │ ├── __init__.py
│ │ ├── BUILD
│ │ ├── lib1.py
│ │ └── pyproject.toml
│ ├── package1
│ │ ├── __init__.py
│ │ ├── BUILD
│ │ ├── package1.py
│ │ └── pyproject.toml
│ └── package2
│ ├── __init__.py
│ ├── BUILD
│ ├── package2.py
│ └── pyproject.toml
└── test
└── python
└── tests
└── some_package
└── package1
├── __init__.py
├── BUILD
├── pyproject.toml
└── test_package1.py
high-psychiatrist-4761
06/26/2025, 7:03 PMsrc/python/some_package/package1/BUILD
python_sources(
name="package1",
dependencies=[
"//src/python/some_package/lib1:lib1",
]
)
python_requirements(
name="reqs",
source="pyproject.toml",
)
python_distribution(
name="dist",
provides=python_artifact(
name="package1",
version="0.1.0",
),
dependencies=[
":package1", # Reference your code
],
wheel_config_settings={"--python-tag": ["py39"]},
)
high-psychiatrist-4761
06/26/2025, 7:04 PM% unzip -l dist/package1-0.1.0-py3-none-any.whl
Archive: dist/package1-0.1.0-py3-none-any.whl
Length Date Time Name
--------- ---------- ----- ----
0 06-26-2025 18:59 some_package/package1/__init__.py
89 06-26-2025 18:59 some_package/package1/package1.py
138 06-26-2025 18:59 package1-0.1.0.dist-info/METADATA
91 06-26-2025 18:59 package1-0.1.0.dist-info/WHEEL
1 06-26-2025 18:59 package1-0.1.0.dist-info/namespace_packages.txt
13 06-26-2025 18:59 package1-0.1.0.dist-info/top_level.txt
577 06-26-2025 18:59 package1-0.1.0.dist-info/RECORD
--------- -------
909 7 files
% unzip -p dist/package1-0.1.0-py3-none-any.whl package1-0.1.0.dist-info/namespace_packages.txt
high-psychiatrist-4761
06/26/2025, 7:04 PMhigh-psychiatrist-4761
06/26/2025, 7:13 PMsource
setting in pants.toml
[source]
root_patterns = [
"/src/python",
"/test/python"
]
high-psychiatrist-4761
06/26/2025, 10:25 PMhappy-kitchen-89482
06/26/2025, 10:35 PMhappy-kitchen-89482
06/26/2025, 10:36 PMhappy-kitchen-89482
06/26/2025, 10:36 PMhappy-kitchen-89482
06/26/2025, 10:37 PM__init__.py
. But Python3 has “implicit namespace packages” - any package with no __init__.py
is implicitly a namespace package.happy-kitchen-89482
06/26/2025, 10:37 PMhappy-kitchen-89482
06/26/2025, 10:37 PMhappy-kitchen-89482
06/26/2025, 10:38 PMhappy-kitchen-89482
06/26/2025, 10:39 PMhigh-psychiatrist-4761
06/26/2025, 10:39 PMsome_package
is the namespace package. Underneth are lib1, package1 and package2 need to be published/released separately. I think my understanding is the same as yours, isn’t it?happy-kitchen-89482
06/26/2025, 10:40 PMhigh-psychiatrist-4761
06/26/2025, 10:40 PMsome_package
is not listed in namespace_package.txt, when user include both pakcage1 and packge2, how python know these two packages should be merged into some_package
instead of override each other?happy-kitchen-89482
06/26/2025, 10:40 PMhappy-kitchen-89482
06/26/2025, 10:40 PMnamespace_package.txt
is for pkg_resources-style namespace packages, where otherwise the import mechanism can’t figure it out…happy-kitchen-89482
06/26/2025, 10:40 PMhappy-kitchen-89482
06/26/2025, 10:40 PMhigh-psychiatrist-4761
06/26/2025, 10:42 PMnamespace_package.txt
. Need to take a look.
So basically you are saying if user include both package1 and package2, there is no collision, right?happy-kitchen-89482
06/26/2025, 10:45 PM__init__.py
then things should work as you expecthigh-psychiatrist-4761
06/26/2025, 10:50 PM