From 29c08335f7aa2c01e45c51819ab88af4f8c8b69a Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Tue, 14 Nov 2023 17:08:09 +0000 Subject: [PATCH 1/2] feat: Introduce compatibility with native namespace packages --- google/__init__.py | 24 ---------- google/identity/__init__.py | 24 ---------- .../identity/accesscontextmanager/__init__.py | 0 setup.py | 5 -- tests/.gitkeep | 0 tests/test_packaging.py | 48 +++++++++++++++++++ 6 files changed, 48 insertions(+), 53 deletions(-) delete mode 100644 google/__init__.py delete mode 100644 google/identity/__init__.py delete mode 100644 google/identity/accesscontextmanager/__init__.py delete mode 100644 tests/.gitkeep create mode 100644 tests/test_packaging.py diff --git a/google/__init__.py b/google/__init__.py deleted file mode 100644 index 9a1b64a..0000000 --- a/google/__init__.py +++ /dev/null @@ -1,24 +0,0 @@ -# -*- coding: utf-8 -*- -# -# Copyright 2020 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 -# -# https://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. - -try: - import pkg_resources - - pkg_resources.declare_namespace(__name__) -except ImportError: - import pkgutil - - __path__ = pkgutil.extend_path(__path__, __name__) diff --git a/google/identity/__init__.py b/google/identity/__init__.py deleted file mode 100644 index 9a1b64a..0000000 --- a/google/identity/__init__.py +++ /dev/null @@ -1,24 +0,0 @@ -# -*- coding: utf-8 -*- -# -# Copyright 2020 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 -# -# https://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. - -try: - import pkg_resources - - pkg_resources.declare_namespace(__name__) -except ImportError: - import pkgutil - - __path__ = pkgutil.extend_path(__path__, __name__) diff --git a/google/identity/accesscontextmanager/__init__.py b/google/identity/accesscontextmanager/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/setup.py b/setup.py index 72517dd..bac83de 100644 --- a/setup.py +++ b/setup.py @@ -45,10 +45,6 @@ package for package in setuptools.find_packages() if package.startswith("google") ] -# Determine which namespaces are needed. -namespaces = ["google"] -namespaces.append("google.identity") - setuptools.setup( name=name, version=version, @@ -72,7 +68,6 @@ ], platforms="Posix; MacOS X; Windows", packages=packages, - namespace_packages=namespaces, install_requires=dependencies, python_requires=">=3.7", include_package_data=True, diff --git a/tests/.gitkeep b/tests/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/tests/test_packaging.py b/tests/test_packaging.py new file mode 100644 index 0000000..8f75d50 --- /dev/null +++ b/tests/test_packaging.py @@ -0,0 +1,48 @@ +# Copyright 2023 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-access-context-manager``. + 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.identity`` namespace package should not be masked + # by the presence of ``google-cloud-access-context-manager``. + google_identity = tmp_path / "google" / "identity" + google_identity.mkdir() + google_identity.joinpath("othermod.py").write_text("") + env = dict(os.environ, PYTHONPATH=str(tmp_path)) + cmd = [sys.executable, "-m", "google.identity.othermod"] + subprocess.check_call(cmd, env=env) + + + # The ``google.identity.accesscontextmanager`` namespace package should not be masked + # by the presence of ``google-cloud-access-context-manager``. + google_identity_accesscontextmanager = tmp_path / "google" / "identity" / "accesscontextmanager" + google_identity_accesscontextmanager.mkdir() + google_identity_accesscontextmanager.joinpath("othermod.py").write_text("") + env = dict(os.environ, PYTHONPATH=str(tmp_path)) + cmd = [sys.executable, "-m", "google.identity.accesscontextmanager.othermod"] + subprocess.check_call(cmd, env=env) + From ca42ccfe9001eab21e28c7776dcc6896f8e36018 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Tue, 14 Nov 2023 17:11:34 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20po?= =?UTF-8?q?st-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- tests/test_packaging.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_packaging.py b/tests/test_packaging.py index 8f75d50..01905d7 100644 --- a/tests/test_packaging.py +++ b/tests/test_packaging.py @@ -36,13 +36,13 @@ def test_namespace_package_compat(tmp_path): cmd = [sys.executable, "-m", "google.identity.othermod"] subprocess.check_call(cmd, env=env) - # The ``google.identity.accesscontextmanager`` namespace package should not be masked # by the presence of ``google-cloud-access-context-manager``. - google_identity_accesscontextmanager = tmp_path / "google" / "identity" / "accesscontextmanager" + google_identity_accesscontextmanager = ( + tmp_path / "google" / "identity" / "accesscontextmanager" + ) google_identity_accesscontextmanager.mkdir() google_identity_accesscontextmanager.joinpath("othermod.py").write_text("") env = dict(os.environ, PYTHONPATH=str(tmp_path)) cmd = [sys.executable, "-m", "google.identity.accesscontextmanager.othermod"] subprocess.check_call(cmd, env=env) -