Skip to content

Commit a63e3f2

Browse files
feat: use native namespaces instead of pkg_resources (#463)
* feat: use native namespaces instead of pkg_resources * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Fixed comments in test_packaging.py --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 36c1b59 commit a63e3f2

File tree

2 files changed

+58
-6
lines changed

2 files changed

+58
-6
lines changed

setup.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,10 @@
5454

5555
packages = [
5656
package
57-
for package in setuptools.PEP420PackageFinder.find()
57+
for package in setuptools.find_namespace_packages()
5858
if package.startswith("google")
5959
]
6060

61-
namespaces = ["google"]
62-
if "google.cloud" in packages:
63-
namespaces.append("google.cloud")
64-
6561
setuptools.setup(
6662
name=name,
6763
version=version,
@@ -89,7 +85,6 @@
8985
platforms="Posix; MacOS X; Windows",
9086
packages=packages,
9187
python_requires=">=3.7",
92-
namespace_packages=namespaces,
9388
install_requires=dependencies,
9489
include_package_data=True,
9590
zip_safe=False,

tests/unit/test_packaging.py

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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-error-reporting``.
23+
24+
google = tmp_path / "google"
25+
google.mkdir()
26+
google.joinpath("othermod.py").write_text("")
27+
28+
google_otherpkg = tmp_path / "google" / "otherpkg"
29+
google_otherpkg.mkdir()
30+
google_otherpkg.joinpath("__init__.py").write_text("")
31+
32+
# The ``google.cloud`` namespace package should not be masked
33+
# by the presence of ``google-cloud-error-reporting``.
34+
google_cloud = tmp_path / "google" / "cloud"
35+
google_cloud.mkdir()
36+
google_cloud.joinpath("othermod.py").write_text("")
37+
38+
google_cloud_otherpkg = tmp_path / "google" / "cloud" / "otherpkg"
39+
google_cloud_otherpkg.mkdir()
40+
google_cloud_otherpkg.joinpath("__init__.py").write_text("")
41+
42+
env = dict(os.environ, PYTHONPATH=str(tmp_path))
43+
44+
for pkg in [
45+
"google.othermod",
46+
"google.cloud.othermod",
47+
"google.otherpkg",
48+
"google.cloud.otherpkg",
49+
"google.cloud.error_reporting",
50+
"google.cloud.errorreporting_v1beta1",
51+
]:
52+
cmd = [sys.executable, "-c", f"import {pkg}"]
53+
subprocess.check_output(cmd, env=env)
54+
55+
for module in ["google.othermod", "google.cloud.othermod"]:
56+
cmd = [sys.executable, "-m", module]
57+
subprocess.check_output(cmd, env=env)

0 commit comments

Comments
 (0)