Skip to content

Commit 87b3392

Browse files
feat: Introduce compatibility with native namespace packages (#497)
* feat: Introduce compatibility with native namespace packages * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * update replacement in owlbot.py * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 108a05b commit 87b3392

File tree

7 files changed

+41
-55
lines changed

7 files changed

+41
-55
lines changed

google/__init__.py

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

google/cloud/__init__.py

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

mypy.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[mypy]
2-
python_version = 3.6
2+
python_version = 3.8
33
namespace_packages = True
44
ignore_missing_imports = True
55

noxfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def mypy(session):
137137
session.install(
138138
"mypy", "types-setuptools", "types-mock", "types-protobuf", "types-requests"
139139
)
140-
session.run("mypy", "google/")
140+
session.run("mypy", "-p", "google")
141141

142142

143143
@nox.session(python=DEFAULT_PYTHON_VERSION)

owlbot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ def mypy(session):
283283
session.install(
284284
"mypy", "types-setuptools", "types-mock", "types-protobuf", "types-requests"
285285
)
286-
session.run("mypy", "google/")
286+
session.run("mypy", "-p", "google")
287287
288288
289289
@nox.session(python=DEFAULT_PYTHON_VERSION)

setup.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,10 @@
5555
# benchmarks, etc.
5656
packages = [
5757
package
58-
for package in setuptools.PEP420PackageFinder.find()
58+
for package in setuptools.find_namespace_packages()
5959
if package.startswith("google")
6060
]
6161

62-
# Determine which namespaces are needed.
63-
namespaces = ["google"]
64-
if "google.cloud" in packages:
65-
namespaces.append("google.cloud")
66-
67-
6862
setuptools.setup(
6963
name=name,
7064
version=version,
@@ -91,7 +85,6 @@
9185
],
9286
platforms="Posix; MacOS X; Windows",
9387
packages=packages,
94-
namespace_packages=namespaces,
9588
install_requires=dependencies,
9689
extras_require=extras,
9790
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-datastore``.
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-datastore``.
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)