Skip to content

Commit 33bc65b

Browse files
committed
feat: Introduce compatibility with native namespace packages
1 parent 0baf3ef commit 33bc65b

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

setup.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@
3030
with io.open(readme_filename, encoding="utf-8") as readme_file:
3131
readme = readme_file.read()
3232

33+
packages = [
34+
package
35+
for package in setuptools.find_namespace_packages()
36+
if package.startswith("google")
37+
]
38+
3339
setuptools.setup(
3440
name="google-cloud-documentai-toolbox",
3541
author="Google LLC",
@@ -39,8 +45,7 @@
3945
license="Apache 2.0",
4046
long_description=readme,
4147
long_description_content_type="text/x-rst",
42-
packages=setuptools.PEP420PackageFinder.find(),
43-
namespace_packages=("google", "google.cloud"),
48+
packages=packages,
4449
platforms="Posix; MacOS X; Windows",
4550
include_package_data=True,
4651
package_data={

tests/unit/test_packaging.py

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-documentai-toolbox``.
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-documentai-toolbox``.
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)