From 71f35626565f2b8c02a9cc1bbd0b59e8672677e0 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Tue, 14 Nov 2023 10:55:36 +0000 Subject: [PATCH 1/4] feat: Introduce compatibility with native namespace packages --- google/__init__.py | 8 -------- google/cloud/__init__.py | 8 -------- setup.py | 7 +------ tests/unit/test_packaging.py | 37 ++++++++++++++++++++++++++++++++++++ 4 files changed, 38 insertions(+), 22 deletions(-) delete mode 100644 google/__init__.py delete mode 100644 google/cloud/__init__.py create mode 100644 tests/unit/test_packaging.py diff --git a/google/__init__.py b/google/__init__.py deleted file mode 100644 index 2f4b4738ae..0000000000 --- a/google/__init__.py +++ /dev/null @@ -1,8 +0,0 @@ -try: - import pkg_resources - - pkg_resources.declare_namespace(__name__) -except ImportError: - import pkgutil - - __path__ = pkgutil.extend_path(__path__, __name__) diff --git a/google/cloud/__init__.py b/google/cloud/__init__.py deleted file mode 100644 index 2f4b4738ae..0000000000 --- a/google/cloud/__init__.py +++ /dev/null @@ -1,8 +0,0 @@ -try: - import pkg_resources - - pkg_resources.declare_namespace(__name__) -except ImportError: - import pkgutil - - __path__ = pkgutil.extend_path(__path__, __name__) diff --git a/setup.py b/setup.py index 1738eed2ea..1b0ca68c69 100644 --- a/setup.py +++ b/setup.py @@ -62,14 +62,10 @@ packages = [ package - for package in setuptools.PEP420PackageFinder.find() + for package in setuptools.find_namespace_packages() if package.startswith("google") ] -namespaces = ["google"] -if "google.cloud" in packages: - namespaces.append("google.cloud") - setuptools.setup( name=name, version=version, @@ -94,7 +90,6 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - namespace_packages=namespaces, install_requires=dependencies, extras_require=extras, python_requires=">=3.7", diff --git a/tests/unit/test_packaging.py b/tests/unit/test_packaging.py new file mode 100644 index 0000000000..998a02ac2d --- /dev/null +++ b/tests/unit/test_packaging.py @@ -0,0 +1,37 @@ +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import subprocess +import sys + + +def test_namespace_package_compat(tmp_path): + # The ``google`` namespace package should not be masked + # by the presence of ``google-cloud-spanner``. + google = tmp_path / "google" + google.mkdir() + google.joinpath("othermod.py").write_text("") + env = dict(os.environ, PYTHONPATH=str(tmp_path)) + cmd = [sys.executable, "-m", "google.othermod"] + subprocess.check_call(cmd, env=env) + + # The ``google.cloud`` namespace package should not be masked + # by the presence of ``google-cloud-spanner``. + google_cloud = tmp_path / "google" / "cloud" + google_cloud.mkdir() + google_cloud.joinpath("othermod.py").write_text("") + env = dict(os.environ, PYTHONPATH=str(tmp_path)) + cmd = [sys.executable, "-m", "google.cloud.othermod"] + subprocess.check_call(cmd, env=env) From 591e0e3fa4df3b041a196a8c9dfb6295fab6e92b Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Thu, 30 Nov 2023 20:12:11 +0000 Subject: [PATCH 2/4] update .coveragerc to reflect changes --- .coveragerc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.coveragerc b/.coveragerc index dd39c8546c..96f8c9fce9 100644 --- a/.coveragerc +++ b/.coveragerc @@ -17,6 +17,9 @@ # Generated by synthtool. DO NOT EDIT! [run] branch = True +omit = + google/__init__.py + google/cloud/__init__.py [report] fail_under = 100 @@ -32,4 +35,6 @@ omit = */gapic/*.py */proto/*.py */core/*.py - */site-packages/*.py \ No newline at end of file + */site-packages/*.py + google/__init__.py + google/cloud/__init__.py From d41517dd739c276e593fcca6322e1572bb7efaef Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Thu, 30 Nov 2023 22:16:15 +0000 Subject: [PATCH 3/4] remove replacement in owlbot.py --- noxfile.py | 6 +++--- owlbot.py | 10 ---------- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/noxfile.py b/noxfile.py index d76be05265..68b2c7f8cd 100644 --- a/noxfile.py +++ b/noxfile.py @@ -173,9 +173,9 @@ def default(session): session.run( "py.test", "--quiet", - "--cov=google.cloud.spanner", - "--cov=google.cloud", - "--cov=tests.unit", + f"--junitxml=unit_{session.python}_sponge_log.xml", + "--cov=google", + "--cov=tests/unit", "--cov-append", "--cov-config=.coveragerc", "--cov-report=", diff --git a/owlbot.py b/owlbot.py index 90edb8cf86..7c249527b2 100644 --- a/owlbot.py +++ b/owlbot.py @@ -222,16 +222,6 @@ def place_before(path, text, *before_text, escape=None): escape="()", ) -s.replace( - "noxfile.py", - """f"--junitxml=unit_{session.python}_sponge_log.xml", - "--cov=google", - "--cov=tests/unit",""", - """\"--cov=google.cloud.spanner", - "--cov=google.cloud", - "--cov=tests.unit",""", -) - s.replace( "noxfile.py", r"""session.install\("-e", "."\)""", From 0866534e15fd4471103919ca77f5408d447a03ed Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Fri, 1 Dec 2023 01:56:48 +0000 Subject: [PATCH 4/4] exclude coverage for .nox/* and /tmp/* --- .coveragerc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.coveragerc b/.coveragerc index 96f8c9fce9..8e75debec9 100644 --- a/.coveragerc +++ b/.coveragerc @@ -18,8 +18,8 @@ [run] branch = True omit = - google/__init__.py - google/cloud/__init__.py + /tmp/* + .nox/* [report] fail_under = 100 @@ -32,9 +32,9 @@ exclude_lines = # Ignore abstract methods raise NotImplementedError omit = + /tmp/* + .nox/* */gapic/*.py */proto/*.py */core/*.py */site-packages/*.py - google/__init__.py - google/cloud/__init__.py