Skip to content

Make SSL optional in compatibility/fetcher - #3281

Open
DonnaIsDoughnut wants to merge 1 commit into
pex-tool:mainfrom
DonnaIsDoughnut:fix/ssl-optional-support
Open

DonnaIsDoughnut wants to merge 1 commit into
pex-tool:mainfrom
DonnaIsDoughnut:fix/ssl-optional-support

Conversation

@DonnaIsDoughnut

@DonnaIsDoughnut DonnaIsDoughnut commented Sep 16, 2026

Copy link
Copy Markdown

Fixes #3282

Interpreters built without SSL support (e.g. embedded / AOSP Python builds) don't define urllib.request.HTTPSHandler / urllib2.HTTPSHandler at all. Previously, importing pex.compatibility or pex.fetcher on such an interpreter would fail immediately.

This wraps the SSL-specific imports in try/except and adds a HAS_SSL flag. URLFetcher only registers an HTTPSHandler when SSL is available, and eagerly initializing the default SSL context is skipped in that case. Attempting to actually establish an HTTPS connection without SSL support now raises a clear IOError instead of failing at import time.

Interpreters built without SSL support (e.g. embedded / AOSP Python
builds) don't define `urllib.request.HTTPSHandler` /
`urllib2.HTTPSHandler` at all. Previously, importing pex.compatibility
or pex.fetcher on such an interpreter would fail immediately.

Now the SSL-specific imports are wrapped in try/except and a HAS_SSL
flag tracks availability. URLFetcher only registers an HTTPSHandler
when SSL is available, and eagerly initializing the default SSL
context is skipped entirely in that case. Attempting to actually
establish an HTTPS connection without SSL support now raises a clear
IOError instead of failing at import time.
@jsirois

jsirois commented Sep 16, 2026

Copy link
Copy Markdown
Member

@DonnaIsDoughnut Pex does not use fetcher at runtime (i.e.: PEX files do not use fetcher). The Pex runtime does use compatibility though. As such, it seems to me compatibility ought to just be broken up and fetcher can own its imports. Since the Pex buildtime always needs a fetcher with https support and the Pex runtime never needs a fetcher, this should be a cleaner split.

This is relevant: #88. Towards that end, what chip architectures do you target for embedded? I want to make sure pex.rc supports those if possible. Current target coverage can be seen here: https://github.com/pex-tool/pex.rc/blob/main/rust-toolchain

I'll take a look at splitting things up as I suggest later today.

@jsirois

jsirois commented Sep 16, 2026

Copy link
Copy Markdown
Member

Ok @DonnaIsDoughnut, I lied. The URLFetcher can be used at PEX runtime in 1 case:

:; PEX_TOOLS=1 ./my.pex venv --pip /install/pex/in/this/venv

If the Python interpreter used does not have the ensurepip module (which some Debian setups, for example, can be missing).
So this PR both re-organizes fetcher to own its imports and uses lazy imports of URLFetcher where needed: #3283

@jsirois

jsirois commented Sep 17, 2026

Copy link
Copy Markdown
Member

@DonnaIsDoughnut please try out https://github.com/pex-tool/pex/releases/tag/v2.103.1 and close this PR if that fix works for your case.

@jsirois

jsirois commented Sep 19, 2026

Copy link
Copy Markdown
Member

@DonnaIsDoughnut I'm going to close this next Friday, September 25th if I haven't head back from you about your experience with https://github.com/pex-tool/pex/releases/tag/v2.103.1.

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.

pex.compatibility / pex.fetcher fail to import on interpreters without SSL support

2 participants