GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat: Introduce compatibility with native namespace packages by jaraco · Pull Request #1205 · googleapis/google-auth-library-python

This repository was archived by the owner on Mar 6, 2026. It is now read-only.

Conversation

@jaraco

@jaraco jaraco commented Dec 20, 2022

Copy link
Copy Markdown
Contributor

This short chain demonstrates a missed expectation, that the google-auth package will mask the presence of other packages in a google namespace when installed. This issue affects corporate packages internally.

The pkg_resources style namespace is the least preferable and least compatible technique indicated in the docs.

By removing the pkg_resources technique, it makes the pkgutil technique the default, adds compatibility with native namespace packages.

After Python 2.7 support is dropped, this package could consider dropping the pkgutil technique as well and instead use native namespace packages, but that's a consideration for a later time.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
jaraco added 2 commits December 20, 2022 12:29
@jaraco
Add xfail test capturing desired expectation.
da48f14
@jaraco
Prefer pkgutil for namespace package. Improves compatibility with nat…
b606ea2
…ive namespace packages.
@jaraco
jaraco requested review from arithmetic1728 and sai-sunder-s as code owners December 20, 2022 17:37
@jaraco
jaraco requested review from a team December 20, 2022 17:37
@jaraco

jaraco commented Dec 20, 2022

Copy link
Copy Markdown
Contributor Author

I'll address the 'conventionalcommits' errors after there's some consent on the general approach.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

clundin25
clundin25 reviewed Dec 20, 2022
View reviewed changes
Comment thread tests/test_packaging.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@clundin25

clundin25 commented Dec 20, 2022

Copy link
Copy Markdown
Contributor

This seems reasonable to me but I think it's best for @parthea to sign off.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@clundin25
clundin25 requested a review from parthea December 20, 2022 23:16
@arithmetic1728 arithmetic1728 assigned parthea Dec 22, 2022
@clundin25

clundin25 commented Jan 25, 2023

Copy link
Copy Markdown
Contributor

Blocked on b/266148789

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jaraco

jaraco commented Jan 25, 2023

Copy link
Copy Markdown
Contributor Author

Blocked on b/266148789

Is it blocked? This change is at least theoretically compatible with Python 2. It may have compatibility concerns with other google.* packages.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@clundin25

clundin25 commented Jan 25, 2023

Copy link
Copy Markdown
Contributor

@jaraco I spoke with @parthea and ideally we want to do this change across the client libraries in conjunction with dropping Python2.7. Please ping us if we need to adjust the priority of this

jaraco reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@clundin25

clundin25 commented Apr 27, 2023

Copy link
Copy Markdown
Contributor

This work is now unblocked and can be picked up. I'll sync up with the team on next steps.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@clundin25

clundin25 commented May 16, 2023

Copy link
Copy Markdown
Contributor

Since we can now drop support for 2.7, I understand the recommended solution is this one https://packaging.python.org/en/latest/guides/packaging-namespace-packages/#native-namespace-packages?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@parthea
Merge branch 'main' into bugfix/namespace-support
2dc9661
@parthea

parthea commented May 19, 2023

Copy link
Copy Markdown
Contributor

python 2.7 is still supported in setup.py . Let's wait until 2.7 is dropped so we can remove __init__.py and pkgutil altogether.

google-auth-library-python/setup.py

Line 70 in 1e6f7d0

python_requires=">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*",

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jaraco

jaraco commented May 21, 2023

Copy link
Copy Markdown
Contributor Author

Since we can now drop support for 2.7, I understand the recommended solution is this one https://packaging.python.org/en/latest/guides/packaging-namespace-packages/#native-namespace-packages?

Yes, that's what I would recommend. But here's the caveat:

If there are other packages installed by the user that implement google.*, those packages may be bringing with them an __init__.py and a different namespace package technique, which could in theory cause these packages not to interoperate. In many cases, they do interoperate due to the way pip omits __init__.py for namespace packages or factors.

Does anyone know if there are other public packages that install behavior into the google.* namespace?

Also, would you like me to amend this PR to utilize the native namespace packages instead?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@clundin25

clundin25 commented May 22, 2023

Copy link
Copy Markdown
Contributor

I'll start work on removing Python 2.7 support in setup.py.

Is it right that the level of risk between the native namespace and the solution in the PR is the same?

I think this will have to be marked as a breaking change (correct me if I am wrong @parthea)? My preference is to go ahead with the native namespace, assuming the risk is the same.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@clundin25 clundin25 mentioned this pull request May 22, 2023
feat: remove python 2.7 from setup.py and nox tests #1301
Merged
@jaraco

jaraco commented Jun 5, 2023

Copy link
Copy Markdown
Contributor Author

I'll start work on removing Python 2.7 support in setup.py.

Is it right that the level of risk between the native namespace and the solution in the PR is the same?

With Python 2.7 support removed, I believe the answer is yes. There are potentially (likely) rare, subtle edge cases, but for the most part, the risks are comparable. Since the pkgutil-style namespaces are older and more mature, they do have better support in older environments, but these concerns are years old and probably ignorable at this point.

I think this will have to be marked as a breaking change (correct me if I am wrong @parthea)? My preference is to go ahead with the native namespace, assuming the risk is the same.

My instinct is to mark it as a breaking change and to indicate that the breaking aspect is ignorable for most users but that the package should not be installed alongside other packages supplying google.* using pkgutil-style namespaces.

I'll update the PR to this new expectation.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jaraco added 3 commits June 5, 2023 12:38
@jaraco
Merge branch 'main' into bugfix/namespace-support
03b3a4f
@jaraco
⚫ Fade to black.
2d48fd2
@jaraco
Update to prefer native namespace package.
e6e9a56
@jaraco

jaraco commented Jun 5, 2023

Copy link
Copy Markdown
Contributor Author

The latest commit proposes instead to use native namespace packages for "google", eliminating the google/__init__.py file and switching to find_namespace_packages to recognize that directory as a package.

I'm not confident that's the correct invocation, because setuptools will pick up any directory as a package (possibly only if it has .py files in it). That means that paths like scripts/ will now be installed as packages where they weren't before.

We'll want to experiment/test to ensure consistency and correctness with this new change.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jaraco

jaraco commented Jun 5, 2023

Copy link
Copy Markdown
Contributor Author

The issue can be illustrated thus:

 ~ $ pip-run git+https://github.com/jaraco/google-auth-library-python@bugfix/namespace-support -- -c "import importlib.metadata as md, pprint; pprint.pprint(md.distribution('google-auth').files)"
[PackagePath('docs/__pycache__/conf.cpython-311.pyc'),
 PackagePath('docs/conf.py'),
 PackagePath('google/auth/__init__.py'),
...
 PackagePath('google_auth-2.19.1.dist-info/top_level.txt'),
 PackagePath('samples/cloud-client/snippets/__pycache__/authenticate_explicit_with_adc.cpython-311.pyc'),
 PackagePath('samples/cloud-client/snippets/__pycache__/authenticate_implicit_with_adc.cpython-311.pyc'),
 PackagePath('samples/cloud-client/snippets/__pycache__/idtoken_from_impersonated_credentials.cpython-311.pyc'),
 PackagePath('samples/cloud-client/snippets/__pycache__/idtoken_from_metadata_server.cpython-311.pyc'),
 PackagePath('samples/cloud-client/snippets/__pycache__/idtoken_from_service_account.cpython-311.pyc'),
 PackagePath('samples/cloud-client/snippets/__pycache__/noxfile.cpython-311.pyc'),
 PackagePath('samples/cloud-client/snippets/__pycache__/noxfile_config.cpython-311.pyc'),
 PackagePath('samples/cloud-client/snippets/__pycache__/snippets_test.cpython-311.pyc'),
 PackagePath('samples/cloud-client/snippets/__pycache__/verify_google_idtoken.cpython-311.pyc'),
 PackagePath('samples/cloud-client/snippets/authenticate_explicit_with_adc.py'),
 PackagePath('samples/cloud-client/snippets/authenticate_implicit_with_adc.py'),
 PackagePath('samples/cloud-client/snippets/idtoken_from_impersonated_credentials.py'),
 PackagePath('samples/cloud-client/snippets/idtoken_from_metadata_server.py'),
 PackagePath('samples/cloud-client/snippets/idtoken_from_service_account.py'),
 PackagePath('samples/cloud-client/snippets/noxfile.py'),
 PackagePath('samples/cloud-client/snippets/noxfile_config.py'),
 PackagePath('samples/cloud-client/snippets/snippets_test.py'),
 PackagePath('samples/cloud-client/snippets/verify_google_idtoken.py')]

It's the docs and samples that end up getting pulled into the package inadvertently.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jaraco
Ensure that 'docs' and 'samples' aren't installed as top-level packages.
ceeb60f
@clundin25

clundin25 commented Jun 6, 2023

Copy link
Copy Markdown
Contributor

It's the docs and samples that end up getting pulled into the package inadvertently.

If I understand correctly, I'm okay with pre-emptively excluding the scripts directory, even though it does not have any *.py files.

How can I assist in testing this feature? The PR looks good to me, and the approach seems sound.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jaraco

jaraco commented Jun 7, 2023

Copy link
Copy Markdown
Contributor Author

How can I assist in testing this feature?

The change includes a test, so the basic functionality is protected by CI.

Where the biggest uncertainly lies in how this change interacts with other libraries in the google.* namespace. I found, for example, python-cloud-core still uses pkg_resources namespaces. Depending on the installation method, a user installing both could encounter issues (and since google-auth-core depends on google-auth, that's a near certainty).

I did some testing to check and indeed the packages seem to work well together in the same environment when installed by pip:

 draft $ py -m venv .venv
 draft $ py -m pip install -q google-cloud-core google-auth@git+https://github.com/jaraco/google-auth-library-python@bugfix/namespace-support
 draft $ ls .venv/lib/python3.12/site-packages/google/__init__.py
ls: .venv/lib/python3.12/site-packages/google/__init__.py: No such file or directory
 draft $ ls .venv/lib/python3.12/site-packages/google/cloud/__init__.py
ls: .venv/lib/python3.12/site-packages/google/cloud/__init__.py: No such file or directory
 draft $ py -c 'import google.cloud, google.auth' && echo done
done

Even though google.cloud still has the pkg_resources namespace packaging behavior:

 draft $ cat .venv/lib/python3.12/site-packages/google_cloud_core-2.3.2-py3.10-nspkg.pth
import sys, types, os;has_mfs = sys.version_info > (3, 5);p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('google',));importlib = has_mfs and __import__('importlib.util');has_mfs and __import__('importlib.machinery');m = has_mfs and sys.modules.setdefault('google', importlib.util.module_from_spec(importlib.machinery.PathFinder.find_spec('google', [os.path.dirname(p)])));m = m or sys.modules.setdefault('google', types.ModuleType('google'));mp = (m or []) and m.__dict__.setdefault('__path__',[]);(p not in mp) and mp.append(p)
import sys, types, os;has_mfs = sys.version_info > (3, 5);p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('google',));importlib = has_mfs and __import__('importlib.util');has_mfs and __import__('importlib.machinery');m = has_mfs and sys.modules.setdefault('google', importlib.util.module_from_spec(importlib.machinery.PathFinder.find_spec('google', [os.path.dirname(p)])));m = m or sys.modules.setdefault('google', types.ModuleType('google'));mp = (m or []) and m.__dict__.setdefault('__path__',[]);(p not in mp) and mp.append(p)
import sys, types, os;has_mfs = sys.version_info > (3, 5);p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('google', 'cloud'));importlib = has_mfs and __import__('importlib.util');has_mfs and __import__('importlib.machinery');m = has_mfs and sys.modules.setdefault('google.cloud', importlib.util.module_from_spec(importlib.machinery.PathFinder.find_spec('google.cloud', [os.path.dirname(p)])));m = m or sys.modules.setdefault('google.cloud', types.ModuleType('google.cloud'));mp = (m or []) and m.__dict__.setdefault('__path__',[]);(p not in mp) and mp.append(p);m and setattr(sys.modules['google'], 'cloud', m)

But something else I'm noticing now, even the pkg_resources-managed namespace packages, when installed with pip, are showing up as PEP 420 namespace packages (note NamespaceLoader for google and google.cloud):

 draft $ py -q
>>> import google.cloud, google.auth
>>> google.__spec__
ModuleSpec(name='google', loader=<_frozen_importlib_external.NamespaceLoader object at 0x1026f8890>, submodule_search_locations=_NamespacePath(['/Users/jaraco/draft/.venv/lib/python3.12/site-packages/google']))
>>> google.auth.__spec__
ModuleSpec(name='google.auth', loader=<_frozen_importlib_external.SourceFileLoader object at 0x10287f7a0>, origin='/Users/jaraco/draft/.venv/lib/python3.12/site-packages/google/auth/__init__.py', submodule_search_locations=['/Users/jaraco/draft/.venv/lib/python3.12/site-packages/google/auth'])
>>> google.cloud.__spec__
ModuleSpec(name='google.cloud', loader=<_frozen_importlib_external.NamespaceLoader object at 0x1026f8ad0>, submodule_search_locations=_NamespacePath(['/Users/jaraco/draft/.venv/lib/python3.12/site-packages/google/cloud']))

That indicates to me that the compatibility story has improved from years ago when the analysis was done on cross-compatibility.

I do note, however, that other installation methods (older versions of pip or other installers) may produce different results.

Feel free to use these explorations as inspiration for other ways to test the downstream effects of this change.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This was referenced Nov 8, 2023
deprecation warning from setuptools 67.3 #1229
Closed
feat: Introduce compatibility with native namespace packages googleapis/gapic-generator-python#1852
Merged
feat: Introduce compatibility with native namespace packages googleapis/python-bigquery#1720
Closed
feat: Introduce compatibility with native namespace packages googleapis/python-spanner#1036
Merged
feat: Introduce compatibility with native namespace packages googleapis/python-documentai-toolbox#201
Merged
feat: Introduce compatibility with native namespace packages googleapis/python-spanner-sqlalchemy#375
Merged
feat: Introduce compatibility with native namespace packages googleapis/python-datastore#497
Merged
feat: Introduce compatibility with native namespace packages googleapis/python-firestore#792
Merged
feat: Introduce compatibility with native namespace packages googleapis/python-access-context-manager#187
Merged
feat: Introduce compatibility with native namespace packages googleapis/python-org-policy#241
Merged
feat: Introduce compatibility with native namespace packages googleapis/python-dns#232
Merged
This was referenced Nov 15, 2023
feat: Introduce compatibility with native namespace packages googleapis/python-runtimeconfig#231
Merged
feat: Introduce compatibility with native namespace packages googleapis/python-grpc-google-iam-v1#59
Merged
feat: use native namespaces instead of pkg_resources googleapis/python-logging#812
Merged
@jackwotherspoon jackwotherspoon mentioned this pull request Nov 17, 2023
feat: introduce compatibility with native namespace packages GoogleCloudPlatform/cloud-sql-python-connector#906
Merged
This was referenced Nov 22, 2023
feat: Introduce compatibility with native namespace packages googleapis/python-pubsub#1024
Merged
feat: Introduce compatibility with native namespace packages googleapis/python-pubsublite#454
Merged
feat: Introduce compatibility with native namespace packages googleapis/python-ndb#933
Merged
fix: use setuptools.find_namespace_packages googleapis/google-auth-library-python-oauthlib#321
Merged
fix: use setuptools.find_namespace_packages googleapis/proto-plus-python#412
Merged
This was referenced Nov 30, 2023
feat: Introduce compatibility with native namespace packages googleapis/python-cloud-core#260
Merged
feat: Introduce compatibility with native namespace packages googleapis/python-bigtable#893
Merged
fix: use setuptools.find_namespace_packages googleapis/python-bigquery-pandas#706
Closed
parthea added a commit to google/bigframes that referenced this pull request Nov 30, 2023
@parthea
fix: use setuptools.find_namespace_packages
45deb7e
Similar to googleapis/google-auth-library-python#1205
https://packaging.python.org/en/latest/guides/packaging-namespace-packages/#native-namespace-packages
This was referenced Nov 30, 2023
fix: use setuptools.find_namespace_packages google/bigframes#246
Merged
feat: Introduce compatibility with native namespace packages googleapis/python-api-core#561
Merged
@parthea parthea mentioned this pull request Dec 13, 2023
feat: Introduce compatibility with native namespace packages googleapis/python-audit-log#117
Merged
gcf-merge-on-green Bot pushed a commit to google/bigframes that referenced this pull request Dec 19, 2023
@parthea
fix: use setuptools.find_namespace_packages (#246)
9ec352a
Similar to googleapis/google-auth-library-python#1205 https://packaging.python.org/en/latest/guides/packaging-namespace-packages/#native-namespace-packages
@psvmcc psvmcc mentioned this pull request Jan 16, 2024
Playbook using kubernetes.core fails when using mitogen_linear strategy mitogen-hq/mitogen#1018
Open
@coderabbitai coderabbitai Bot mentioned this pull request Mar 22, 2026
Dev MarcuxOng/gemini-playground#8
Closed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

@arithmetic1728 arithmetic1728 Awaiting requested review from arithmetic1728
@sai-sunder-s sai-sunder-s Awaiting requested review from sai-sunder-s
@parthea parthea Awaiting requested review from parthea
1 more reviewer
@clundin25 clundin25 clundin25 approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@parthea parthea

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@jaraco @clundin25 @parthea @yoshi-kokoro
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.