From da48f14fefff25bd948b949bd993d8d33fa66b8a Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 20 Dec 2022 12:29:59 -0500 Subject: [PATCH 1/7] Add xfail test capturing desired expectation. --- tests/test_packaging.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 tests/test_packaging.py diff --git a/tests/test_packaging.py b/tests/test_packaging.py new file mode 100644 index 000000000..abed276cf --- /dev/null +++ b/tests/test_packaging.py @@ -0,0 +1,33 @@ +# 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 + +import pytest + + +@pytest.mark.xfail(reason="known limitation") +def test_namespace_package_compat(tmp_path): + """ + The ``google`` namespace package should not be masked + by the presence of ``google-auth``. + """ + 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) From b606ea231487f683bb56245ce5a4857a59b7de04 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Mon, 19 Dec 2022 16:55:37 -0500 Subject: [PATCH 2/7] Prefer pkgutil for namespace package. Improves compatibility with native namespace packages. --- google/__init__.py | 9 ++------- setup.py | 1 - tests/test_packaging.py | 3 --- 3 files changed, 2 insertions(+), 11 deletions(-) diff --git a/google/__init__.py b/google/__init__.py index 70a7bd995..7655d1509 100644 --- a/google/__init__.py +++ b/google/__init__.py @@ -14,11 +14,6 @@ """Google namespace package.""" -try: - import pkg_resources +import pkgutil - pkg_resources.declare_namespace(__name__) -except ImportError: - import pkgutil - - __path__ = pkgutil.extend_path(__path__, __name__) # type: ignore +__path__ = pkgutil.extend_path(__path__, __name__) # type: ignore diff --git a/setup.py b/setup.py index c89b05d1d..2c6ead626 100644 --- a/setup.py +++ b/setup.py @@ -63,7 +63,6 @@ long_description=long_description, url="https://github.com/googleapis/google-auth-library-python", packages=find_packages(exclude=("tests*", "system_tests*")), - namespace_packages=("google",), install_requires=DEPENDENCIES, extras_require=extras, python_requires=">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*", diff --git a/tests/test_packaging.py b/tests/test_packaging.py index abed276cf..02329846a 100644 --- a/tests/test_packaging.py +++ b/tests/test_packaging.py @@ -16,10 +16,7 @@ import subprocess import sys -import pytest - -@pytest.mark.xfail(reason="known limitation") def test_namespace_package_compat(tmp_path): """ The ``google`` namespace package should not be masked From 2d48fd291e1186053465e2c30117ba7e6648bd45 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Mon, 5 Jun 2023 12:42:26 -0400 Subject: [PATCH 3/7] =?UTF-8?q?=E2=9A=AB=20Fade=20to=20black.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- google/__init__.py | 19 ------------------- tests/test_packaging.py | 6 +++--- 2 files changed, 3 insertions(+), 22 deletions(-) delete mode 100644 google/__init__.py diff --git a/google/__init__.py b/google/__init__.py deleted file mode 100644 index 7655d1509..000000000 --- a/google/__init__.py +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright 2016 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. - -"""Google namespace package.""" - -import pkgutil - -__path__ = pkgutil.extend_path(__path__, __name__) # type: ignore diff --git a/tests/test_packaging.py b/tests/test_packaging.py index 02329846a..e87b3a21b 100644 --- a/tests/test_packaging.py +++ b/tests/test_packaging.py @@ -22,9 +22,9 @@ def test_namespace_package_compat(tmp_path): The ``google`` namespace package should not be masked by the presence of ``google-auth``. """ - google = tmp_path / 'google' + google = tmp_path / "google" google.mkdir() - google.joinpath('othermod.py').write_text('') + google.joinpath("othermod.py").write_text("") env = dict(os.environ, PYTHONPATH=str(tmp_path)) - cmd = [sys.executable, '-m', 'google.othermod'] + cmd = [sys.executable, "-m", "google.othermod"] subprocess.check_call(cmd, env=env) From e6e9a56656d41b574480f79b454c2f0252c76798 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Mon, 5 Jun 2023 12:43:07 -0400 Subject: [PATCH 4/7] Update to prefer native namespace package. --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index bb30a6518..484044a28 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ import io import os -from setuptools import find_packages +from setuptools import find_namespace_packages from setuptools import setup @@ -58,7 +58,7 @@ description="Google Authentication Library", long_description=long_description, url="https://github.com/googleapis/google-auth-library-python", - packages=find_packages(exclude=("tests*", "system_tests*")), + packages=find_namespace_packages(exclude=("tests*", "system_tests*")), install_requires=DEPENDENCIES, extras_require=extras, python_requires=">=3.6", From ceeb60fd0809178ba5fca87c957f520588d2c3e7 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Mon, 5 Jun 2023 13:09:02 -0400 Subject: [PATCH 5/7] Ensure that 'docs' and 'samples' aren't installed as top-level packages. --- setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 484044a28..d59a07e0c 100644 --- a/setup.py +++ b/setup.py @@ -58,7 +58,8 @@ description="Google Authentication Library", long_description=long_description, url="https://github.com/googleapis/google-auth-library-python", - packages=find_namespace_packages(exclude=("tests*", "system_tests*")), + packages=find_namespace_packages( + exclude=("tests*", "system_tests*", "docs*", "samples*")), install_requires=DEPENDENCIES, extras_require=extras, python_requires=">=3.6", From 7a288a58e356458fb0dbf4a833950ea1a1728fa7 Mon Sep 17 00:00:00 2001 From: Carl Lundin Date: Thu, 15 Jun 2023 12:19:15 -0700 Subject: [PATCH 6/7] fix linter. --- setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index cc5fce55a..4a91925dd 100644 --- a/setup.py +++ b/setup.py @@ -59,7 +59,8 @@ long_description=long_description, url="https://github.com/googleapis/google-auth-library-python", packages=find_namespace_packages( - exclude=("tests*", "system_tests*", "docs*", "samples*")), + exclude=("tests*", "system_tests*", "docs*", "samples*") + ), install_requires=DEPENDENCIES, extras_require=extras, python_requires=">=3.6", From 531229ba1f897f1044d83949feeb7b728cbc0b3d Mon Sep 17 00:00:00 2001 From: Carl Lundin Date: Thu, 15 Jun 2023 14:57:47 -0700 Subject: [PATCH 7/7] fix mypy check --- noxfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/noxfile.py b/noxfile.py index 19e162bcc..b9d183385 100644 --- a/noxfile.py +++ b/noxfile.py @@ -82,7 +82,7 @@ def mypy(session): "types-six", "types-mock", ) - session.run("mypy", "google/", "tests/", "tests_async/") + session.run("mypy", "-p", "google", "-p", "tests", "-p", "tests_async") @nox.session(python=["3.6", "3.7", "3.8", "3.9", "3.10", "3.11"])