Skip to content

Commit 3548957

Browse files
committed
feat: Introduce compatibility with native namespace packages
1 parent ae72add commit 3548957

File tree

6 files changed

+40
-58
lines changed

6 files changed

+40
-58
lines changed

google/__init__.py

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

google/cloud/__init__.py

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

noxfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def mypy(session):
106106
# TODO: Only check the hand-written layer, the generated code does not pass
107107
# mypy checks yet.
108108
# https://github.com/googleapis/gapic-generator-python/issues/1092
109-
session.run("mypy", "google/cloud")
109+
session.run("mypy", "-p", "google.cloud")
110110

111111

112112
@nox.session(python=DEFAULT_PYTHON_VERSION)

owlbot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ def mypy(session):
383383
# TODO: Only check the hand-written layer, the generated code does not pass
384384
# mypy checks yet.
385385
# https://github.com/googleapis/gapic-generator-python/issues/1092
386-
session.run("mypy", "google/cloud")'''
386+
session.run("mypy", "-p", "google.cloud")'''
387387
),
388388
)
389389

@@ -399,7 +399,7 @@ def mypy(session):
399399
)
400400
s.replace(
401401
"noxfile.py",
402-
r'session\.run\("mypy", "google/cloud"\)',
402+
r'session\.run\("mypy", "-p", "google.cloud"\)',
403403
textwrap.dedent(
404404
''' \g<0>
405405

setup.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@
6060
if package.startswith("google")
6161
]
6262

63-
namespaces = ["google"]
64-
if "google.cloud" in packages:
65-
namespaces.append("google.cloud")
66-
6763
setuptools.setup(
6864
name=name,
6965
version=version,
@@ -89,7 +85,6 @@
8985
],
9086
platforms="Posix; MacOS X; Windows",
9187
packages=packages,
92-
namespace_packages=namespaces,
9388
install_requires=dependencies,
9489
extras_require=extras,
9590
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 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-pubsub``.
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-pubsub``.
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)