Skip to content

Commit 5d80ab0

Browse files
authored
feat: Introduce compatibility with native namespace packages (#1036)
* feat: Introduce compatibility with native namespace packages * update .coveragerc to reflect changes * remove replacement in owlbot.py * exclude coverage for .nox/* and /tmp/*
1 parent b28dc9b commit 5d80ab0

File tree

7 files changed

+47
-36
lines changed

7 files changed

+47
-36
lines changed

.coveragerc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
# Generated by synthtool. DO NOT EDIT!
1818
[run]
1919
branch = True
20+
omit =
21+
/tmp/*
22+
.nox/*
2023

2124
[report]
2225
fail_under = 100
@@ -29,7 +32,9 @@ exclude_lines =
2932
# Ignore abstract methods
3033
raise NotImplementedError
3134
omit =
35+
/tmp/*
36+
.nox/*
3237
*/gapic/*.py
3338
*/proto/*.py
3439
*/core/*.py
35-
*/site-packages/*.py
40+
*/site-packages/*.py

google/__init__.py

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

google/cloud/__init__.py

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

noxfile.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,9 @@ def default(session):
173173
session.run(
174174
"py.test",
175175
"--quiet",
176-
"--cov=google.cloud.spanner",
177-
"--cov=google.cloud",
178-
"--cov=tests.unit",
176+
f"--junitxml=unit_{session.python}_sponge_log.xml",
177+
"--cov=google",
178+
"--cov=tests/unit",
179179
"--cov-append",
180180
"--cov-config=.coveragerc",
181181
"--cov-report=",

owlbot.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -222,16 +222,6 @@ def place_before(path, text, *before_text, escape=None):
222222
escape="()",
223223
)
224224

225-
s.replace(
226-
"noxfile.py",
227-
"""f"--junitxml=unit_{session.python}_sponge_log.xml",
228-
"--cov=google",
229-
"--cov=tests/unit",""",
230-
"""\"--cov=google.cloud.spanner",
231-
"--cov=google.cloud",
232-
"--cov=tests.unit",""",
233-
)
234-
235225
s.replace(
236226
"noxfile.py",
237227
r"""session.install\("-e", "."\)""",

setup.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,10 @@
6363

6464
packages = [
6565
package
66-
for package in setuptools.PEP420PackageFinder.find()
66+
for package in setuptools.find_namespace_packages()
6767
if package.startswith("google")
6868
]
6969

70-
namespaces = ["google"]
71-
if "google.cloud" in packages:
72-
namespaces.append("google.cloud")
73-
7470
setuptools.setup(
7571
name=name,
7672
version=version,
@@ -97,7 +93,6 @@
9793
],
9894
platforms="Posix; MacOS X; Windows",
9995
packages=packages,
100-
namespace_packages=namespaces,
10196
install_requires=dependencies,
10297
extras_require=extras,
10398
python_requires=">=3.7",

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 2022 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-spanner``.
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-spanner``.
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)