Skip to content
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

Prepare the 2.1.118 release. #2009

Merged
merged 9 commits into from
Dec 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
Release Notes
=============

2.1.118
-------

This is a very tardy hotfix release for a regression introduced in Pex
2.1.91 by #1785 that replaced sys.argv[0] with its fully resolved path.
This prevented introspecting the actual file path used to launch the PEX
which broke BusyBox-alike use cases.

There is also a new ``--non-hermetic-scripts`` option accepted by the
``venv`` tool to allow running console scripts with ``PYTHONPATH``
adjustments to the ``sys.path``.

* Remove un-needed realpathing of ``sys.argv[0]``. (#2007)
`PR #2007 <https://github.com/pantsbuild/pex/pull/2007>`_

* Add ``--non-hermetic-scripts`` option to ``venv`` tool. (#2010)
`PR #2010 <https://github.com/pantsbuild/pex/pull/2010>`_

2.1.117
-------

Expand Down
2 changes: 1 addition & 1 deletion pex/pex_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def __entry_point_from_filename__(filename):
sys.exit(2)

__installed_from__ = os.environ.pop(__INSTALLED_FROM__, None)
sys.argv[0] = os.path.realpath(__installed_from__ or sys.argv[0])
sys.argv[0] = __installed_from__ or sys.argv[0]

sys.path[0] = os.path.abspath(sys.path[0])
sys.path.insert(0, os.path.abspath(os.path.join(__entry_point__, {bootstrap_dir!r})))
Expand Down
2 changes: 1 addition & 1 deletion pex/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2015 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

__version__ = "2.1.117"
__version__ = "2.1.118"
8 changes: 7 additions & 1 deletion tests/integration/test_issue_1730.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2022 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

from __future__ import absolute_import
from __future__ import absolute_import, print_function

import os

Expand All @@ -24,11 +24,17 @@ def test_check_install_issue_1730(
# type: (...) -> None

pex_root = os.path.join(str(tmpdir), "pex_root")
constraints = os.path.join(str(tmpdir), "constraints.txt")
with open(constraints, "w") as fp:
print("packaging==21.3", file=fp)

pex_args = [
"--pex-root",
pex_root,
"--runtime-pex-root",
pex_root,
"--constraints",
constraints,
"pantsbuild.pants.testutil==2.12.0.dev3",
"--",
"-c",
Expand Down
70 changes: 70 additions & 0 deletions tests/integration/test_issue_2006.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Copyright 2022 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

import os.path
import subprocess
import sys

import pytest

from pex.compatibility import PY3
from pex.testing import PY38, ensure_python_interpreter, run_pex_command
from pex.typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import Any, List


@pytest.mark.parametrize(
["boot_args"],
[
pytest.param([], id="__main__.py boot"),
pytest.param(["--sh-boot"], id="--sh-boot"),
],
)
def test_symlink_preserved_in_argv0(
tmpdir, # type: Any
boot_args, # type: List[str]
):
# type: (...) -> None

# N.B.: We use conscript (https://pypi.org/project/conscript/) here to test a very common real
# use case for knowing the original path used to launch an executable. In general this allows
# the executable to react differently based on its name. In the conscript case, it uses that
# name to select a matching console script in the PEX if one exists and run that. If no such
# match exists and there are no args, it launches a REPL session over the PEX contents.

pex = os.path.join(str(tmpdir), "speak.pex")
run_pex_command(
args=["conscript==0.1.5", "cowsay==5.0", "fortune==1.1.0", "-c", "conscript", "-o", pex]
+ boot_args
).assert_success()

assert (
"5.0" == subprocess.check_output(args=[pex, "cowsay", "--version"]).decode("utf-8").strip()
)

cowsay = os.path.join(str(tmpdir), "cowsay")
os.symlink(pex, cowsay)
assert "5.0" == subprocess.check_output(args=[cowsay, "--version"]).decode("utf-8").strip(), (
"Expected the symlink used to launch this PEX to be preserved in sys.argv[0] such that "
"conscript could observe it and select the cowsay console script inside the PEX for"
"execution. Without symlink preservation, the real PEX name of speak.pex will match no "
"internal console scripts and the conscript entry point will drop into a REPL session over "
"the PEX causing this test to hang waiting for a REPL session exit signal / command."
)

fortune_file = os.path.join(str(tmpdir), "fortunes.txt")
with open(fortune_file, "w") as fp:
fp.write("Just the one")
fortune = os.path.join(str(tmpdir), "fortune")
os.symlink(pex, fortune)

# N.B.: This fortune implementation uses print(..., file=...) without
# `from __future__ import print_function`; so fails under Python 2.7 despite the fact its
# released as a py2.py3 wheel.
python = sys.executable if PY3 else ensure_python_interpreter(PY38)
assert (
"Just the one"
== subprocess.check_output(args=[python, fortune, fortune_file]).decode("utf-8").strip()
)