Skip to content

Commit 4bc0567

Browse files
authored
feat: Introduce compatibility with native namespace packages (#933)
1 parent 087107d commit 4bc0567

4 files changed

Lines changed: 44 additions & 46 deletions

File tree

packages/google-cloud-ndb/google/__init__.py

Lines changed: 0 additions & 22 deletions
This file was deleted.

packages/google-cloud-ndb/google/cloud/__init__.py

Lines changed: 0 additions & 22 deletions
This file was deleted.

packages/google-cloud-ndb/setup.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@
2828
assert len(version_candidates) == 1
2929
version = version_candidates[0]
3030

31+
packages = [
32+
package
33+
for package in setuptools.find_namespace_packages()
34+
if package.startswith("google")
35+
]
36+
3137
def main():
3238
package_root = os.path.abspath(os.path.dirname(__file__))
3339
readme_filename = os.path.join(package_root, "README.md")
@@ -73,8 +79,7 @@ def main():
7379
"Topic :: Internet",
7480
],
7581
platforms="Posix; MacOS X; Windows",
76-
packages=setuptools.find_packages(),
77-
namespace_packages=["google", "google.cloud"],
82+
packages=packages,
7883
install_requires=dependencies,
7984
extras_require={},
8085
python_requires=">=3.7",
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Copyright 2023 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import os
16+
import subprocess
17+
import sys
18+
19+
20+
def test_namespace_package_compat(tmp_path):
21+
# The ``google`` namespace package should not be masked
22+
# by the presence of ``google-cloud-ndb``.
23+
google = tmp_path / "google"
24+
google.mkdir()
25+
google.joinpath("othermod.py").write_text("")
26+
env = dict(os.environ, PYTHONPATH=str(tmp_path))
27+
cmd = [sys.executable, "-m", "google.othermod"]
28+
subprocess.check_call(cmd, env=env)
29+
30+
# The ``google.cloud`` namespace package should not be masked
31+
# by the presence of ``google-cloud-ndb``.
32+
google_cloud = tmp_path / "google" / "cloud"
33+
google_cloud.mkdir()
34+
google_cloud.joinpath("othermod.py").write_text("")
35+
env = dict(os.environ, PYTHONPATH=str(tmp_path))
36+
cmd = [sys.executable, "-m", "google.cloud.othermod"]
37+
subprocess.check_call(cmd, env=env)

0 commit comments

Comments
 (0)