-
-
Notifications
You must be signed in to change notification settings - Fork 310
Delay import of ssl in pex.fetcher.
#2417
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
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5626f7a
Add a failing test.
jsirois 77839af
Lazily import ssl in `pex/fetcher.py`.
jsirois 011eab2
Prepare the 2.3.2 release.
jsirois b2eaec1
`tox -efmt,lint`
jsirois bdc8a70
Fixup `tox` Pex install to only use editable mode for Pythons `>=3.6`.
jsirois ea27670
Use a modern Pip that supports Python 3.8 and editable installs of py…
jsirois 363a7e1
Eliminate flakes by using a temp local project that is not Pex itself…
jsirois 6acb877
Unrelated test bitrot fix.
jsirois File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| # Copyright 2015 Pex project contributors. | ||
| # Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
|
||
| __version__ = "2.3.1" | ||
| __version__ = "2.3.2" |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| # Copyright 2024 Pex project contributors. | ||
| # Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
|
||
| import atexit | ||
| import os.path | ||
| import re | ||
| import subprocess | ||
| import threading | ||
| from textwrap import dedent | ||
| from threading import Event | ||
| from typing import Optional | ||
|
|
||
| import pytest | ||
|
|
||
| from pex.common import safe_open | ||
| from pex.fetcher import URLFetcher | ||
| from pex.typing import TYPE_CHECKING | ||
| from testing import IS_PYPY, PY_VER, data, run_pex_command | ||
|
|
||
| if TYPE_CHECKING: | ||
| from typing import Any | ||
|
|
||
| import attr # vendor:skip | ||
| else: | ||
| from pex.third_party import attr | ||
|
|
||
|
|
||
| @pytest.mark.skipif( | ||
| IS_PYPY or PY_VER < (3, 8) or PY_VER >= (3, 13), | ||
| reason=( | ||
| "The lock file for this test only supports CPythons >=3.8,<3.13 which were the officially " | ||
| "supported CPythons at the time issue 2415 was reported." | ||
| ), | ||
| ) | ||
| def test_gevent_monkeypatch(tmpdir): | ||
| # type: (Any) -> None | ||
|
|
||
| with safe_open(os.path.join(str(tmpdir), "app.py"), "w") as app_fp: | ||
| app_fp.write( | ||
| dedent( | ||
| """\ | ||
| from gevent import monkey | ||
| monkey.patch_all() | ||
|
|
||
| from flask import Flask | ||
|
|
||
|
|
||
| app = Flask(__name__) | ||
|
|
||
|
|
||
| @app.route("/") | ||
| def hello_world(): | ||
| return "Hello, World!" | ||
| """ | ||
| ) | ||
| ) | ||
|
|
||
| pex_root = os.path.join(str(tmpdir), "pex_root") | ||
| pex = os.path.join(str(tmpdir), "pex") | ||
|
|
||
| # N.B.: Created with the following, where gevent 1.3.4 was picked as a lower bound since it | ||
| # 1st introduced the `from gevent import monkey; monkey.patch_all()` ssl check warning that is | ||
| # the subject of issue 2415: | ||
| # | ||
| # pex3 lock create \ | ||
| # --resolver-version pip-2020-resolver \ | ||
| # --pip-version latest \ | ||
| # --style universal \ | ||
| # --interpreter-constraint ">=3.8,<3.13" \ | ||
| # --indent 2 \ | ||
| # flask \ | ||
| # "gevent>=1.3.4" \ | ||
| # gunicorn | ||
| lock = data.path("locks", "issue-2415.lock.json") | ||
|
|
||
| run_pex_command( | ||
| args=[ | ||
| "--pex-root", | ||
| pex_root, | ||
| "--runtime-pex-root", | ||
| pex_root, | ||
| "--lock", | ||
| lock, | ||
| "-M", | ||
| "app", | ||
| "-c", | ||
| "gunicorn", | ||
| "--inject-args", | ||
| "app:app", | ||
| "-o", | ||
| pex, | ||
| ], | ||
| cwd=str(tmpdir), | ||
| ).assert_success() | ||
|
|
||
| log = os.path.join(str(tmpdir), "log") | ||
| os.mkfifo(log) | ||
|
|
||
| @attr.s | ||
| class LogScanner(object): | ||
| port_seen = attr.ib(factory=Event, init=False) # type: Event | ||
| _port = attr.ib(default=None) # type: Optional[int] | ||
|
|
||
| def scan_log(self): | ||
| # type: () -> None | ||
|
|
||
| with open(log) as log_fp: | ||
| for line in log_fp: | ||
| if self._port is None: | ||
| match = re.search(r"Listening at: http://127.0.0.1:(?P<port>\d{1,5})", line) | ||
| if match: | ||
| self._port = int(match.group("port")) | ||
| self.port_seen.set() | ||
|
|
||
| @property | ||
| def port(self): | ||
| # type: () -> int | ||
| self.port_seen.wait() | ||
| assert self._port is not None | ||
| return self._port | ||
|
|
||
| log_scanner = LogScanner() | ||
| log_scan_thread = threading.Thread(target=log_scanner.scan_log) | ||
| log_scan_thread.daemon = True | ||
| log_scan_thread.start() | ||
|
|
||
| with open(os.path.join(str(tmpdir), "stderr"), "wb+") as stderr_fp: | ||
| gunicorn = subprocess.Popen( | ||
| args=[pex, "--bind", "127.0.0.1:0", "--log-file", log], stderr=stderr_fp | ||
| ) | ||
| atexit.register(gunicorn.kill) | ||
|
|
||
| with URLFetcher().get_body_stream( | ||
| "http://127.0.0.1:{port}".format(port=log_scanner.port) | ||
| ) as http_fp: | ||
| assert b"Hello, World!" == http_fp.read().strip() | ||
|
|
||
| gunicorn.kill() | ||
| log_scan_thread.join() | ||
| stderr_fp.flush() | ||
| stderr_fp.seek(0) | ||
| stderr = stderr_fp.read() | ||
| assert b"MonkeyPatchWarning: Monkey-patching ssl after ssl " not in stderr, stderr.decode( | ||
| "utf-8" | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,10 +18,19 @@ download = true | |
| # N.B.: We configure tox to disable its build sdist, then install sdist in venv scheme for all envs | ||
| # with `skip_install = false` (the default). As such, we use a custom `install_command` for all | ||
| # envs that need Pex installed. The install command is tox's default, with the one addition of | ||
| # `{toxinidir}`, which adds `.` to the requirement list handed to Pip to install. | ||
| # `{toxinidir}`, which adds `-e .` to the requirement list handed to Pip to install. | ||
| install_command = | ||
| docs,check,typecheck,py{py27,py35,py36,py37,py38,py39,py310,27,35,36,37,38,39,310,311,312,313}: \ | ||
| python -m pip install {opts} {toxinidir} {packages} | ||
| # N.B.: The latest Pip supported by Python 2.7 and 3.5 can't install pyproject.toml projects in | ||
| # editable mode. | ||
| # TODO(John Sirois): Consider moving back to the setuptools.build_meta backend and using a | ||
| # minimal setup.py since hatchling is buying us less and less and getting in the way more and | ||
| # more. | ||
| py{py27,py35,27,35}: python -m pip install {opts} {toxinidir} {packages} | ||
|
|
||
| docs,check,typecheck,py{py36,py37,py38,py39,py310,36,37,38,39,310,311,312,313}: \ | ||
| python -m pip install {opts} -e {toxinidir} {packages} | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was needed to ensure non-stale Pex on the test |
||
|
|
||
|
|
||
| commands = | ||
| !integration: python testing/bin/run_tests.py {posargs:-vvs} | ||
| integration: python testing/bin/run_tests.py --it {posargs:-vvs} | ||
|
|
@@ -162,7 +171,7 @@ basepython = python3.8 | |
| skip_install = true | ||
| deps = | ||
| ansicolors==1.1.8 | ||
| pip==20.2.4 | ||
| pip==24.0 | ||
| redbaron==0.9.2 | ||
| setuptools==50.3.2 | ||
| wheel==0.35.1 | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The failure at this commit looks like: