Skip to content

Commit

Permalink
Another try as macOS realpath issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
jsirois committed Oct 24, 2024
1 parent 5b80d3d commit 2c9bb58
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
2 changes: 1 addition & 1 deletion pex/pex_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ def pex_root(self):
# type: () -> str
pex_root = os.path.realpath(os.path.expanduser(self.raw_pex_root))
if not can_write_dir(pex_root):
tmp_root = safe_mkdtemp()
tmp_root = os.path.realpath(safe_mkdtemp())
pex_warnings.warn(
"PEX_ROOT is configured as {pex_root} but that path is un-writeable, "
"falling back to a temporary PEX_ROOT of {tmp_root} which will hurt "
Expand Down
35 changes: 18 additions & 17 deletions tests/test_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from pex.util import named_temporary_file
from pex.variables import NoValueError, Variables
from testing import environment_as
from testing.pytest.tmp import Tempdir

if TYPE_CHECKING:
from typing import Any
Expand Down Expand Up @@ -196,27 +197,27 @@ def test_pex_vars_defaults_stripped():
assert Variables.PEX_VERBOSE.strip_default(v) is None


def test_pex_root_unwriteable():
# type: () -> None
with temporary_dir() as td:
pex_root = os.path.realpath(os.path.join(td, "pex_root"))
os.mkdir(pex_root, 0o444)
def test_pex_root_unwriteable(tmpdir):
# type: (Tempdir) -> None

pex_root = tmpdir.join("pex_root")
os.mkdir(pex_root, 0o444)

env = Variables(environ=dict(PEX_ROOT=pex_root))
env = Variables(environ=dict(PEX_ROOT=pex_root))

with warnings.catch_warnings(record=True) as log:
assert pex_root != env.PEX_ROOT
with warnings.catch_warnings(record=True) as log:
assert pex_root != env.PEX_ROOT

assert 1 == len(log)
message = log[0].message
assert isinstance(message, PEXWarning)
assert pex_root in str(message)
assert env.PEX_ROOT is not None
assert env.PEX_ROOT in str(message)
assert 1 == len(log)
message = log[0].message
assert isinstance(message, PEXWarning)
assert pex_root in str(message)
assert env.PEX_ROOT is not None
assert env.PEX_ROOT in str(message)

assert (
env.PEX_ROOT == env.PEX_ROOT
), "When an ephemeral PEX_ROOT is materialized it should be stable."
assert (
env.PEX_ROOT == env.PEX_ROOT
), "When an ephemeral PEX_ROOT is materialized it should be stable."


def test_pex_vars_value_or(tmpdir):
Expand Down

0 comments on commit 2c9bb58

Please sign in to comment.