Skip to content

fix: add missing packaging dependency for feature requiring urllib3 #1732

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 7, 2025

Conversation

harkamaljot
Copy link
Contributor

Resolves an ImportError: No module named 'packaging' encountered when using functionality in the urllib3.py file.

The code paths relying on urllib3 transport also have a runtime dependency on the packaging library. This dependency was introduced in PR #1390.

However, packaging was not explicitly listed as a requirement for the urllib3 in setup.py. This was masked during development because nox often installs packaging transitively. Users installing the library without having nox or its dependencies installed separately would face an ImportError when the urllib3 dependent code executes.

This PR fixes the issue by explicitly adding packaging alongside urllib3 in the extras group definition. This ensures that installing the optional feature via the extra correctly pulls in all its necessary runtime dependencies.

@harkamaljot harkamaljot requested review from a team as code owners April 6, 2025 22:46
@harkamaljot harkamaljot requested a review from sai-sunder-s April 6, 2025 23:01
@@ -34,6 +34,7 @@
"reauth": "pyu2f>=0.1.5",
"enterprise_cert": ["cryptography", "pyopenssl"],
"pyjwt": ["pyjwt>=2.0", "cryptography>=38.0.3"],
"urllib3": ["urllib3", "packaging"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how does user know to install this extra?

Maybe update the error msg in the try catch and tell users about this extra.

Also move packaging into the try?

from packaging import version # type: ignore

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

installing dependency like pip install google-auth[urllib3] should install all the dependencies defined for urlllib3. I was thinking about updating error message, however I saw similar error in other modules, but this is definitely confusing. let me update the message to include google-auth[urllib3] command to avoid user installing directly from pip.

@harkamaljot harkamaljot requested a review from sai-sunder-s April 7, 2025 18:04
except ImportError as caught_exc: # pragma: NO COVER
raise ImportError(
"The urllib3 library is not installed from please install the "
"urllib3 package to use the urllib3 transport."
"Error: Missing 'urllib3' dependency for 'google-auth'."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same error msg for packaging as well.

Does the caught_exc have the name of the missing library?

@harkamaljot harkamaljot requested a review from sai-sunder-s April 7, 2025 20:15
@harkamaljot harkamaljot merged commit 221f4a8 into main Apr 7, 2025
15 checks passed
@harkamaljot harkamaljot deleted the add-dependency branch April 7, 2025 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants