Skip to content

Commit

Permalink
More hacks.
Browse files Browse the repository at this point in the history
  • Loading branch information
jsirois committed Nov 17, 2024
1 parent 47443d9 commit d075c89
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions pex/pex_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
import json
import os
import zipfile
from multiprocessing import Array

from pex import layout, pex_warnings, variables
from pex.cache import root as cache_root
from pex.common import can_write_dir, open_zip, safe_mkdtemp, safe_rmtree
from pex.common import can_write_dir, open_zip, safe_mkdtemp
from pex.compatibility import PY2, WINDOWS
from pex.compatibility import string as compatibility_string
from pex.inherit_path import InheritPath
Expand Down Expand Up @@ -61,6 +62,7 @@ class PexInfo(object):
"""

PATH = layout.PEX_INFO_PATH
_BACKUP_PEX_ROOT = Array("u", safe_mkdtemp())

@classmethod
def make_build_properties(cls):
Expand Down Expand Up @@ -151,9 +153,6 @@ def __init__(self, info=None):

self._excluded = OrderedSet(self._pex_info.get("excluded", ())) # type: OrderedSet[str]
self._overridden = OrderedSet(self._pex_info.get("overridden", ())) # type: OrderedSet[str]
os.environ["_PEX_BACKUP_ROOT"] = self._backup_pex_root = (
os.environ.get("_PEX_BACKUP_ROOT") or safe_mkdtemp()
)

def _get_safe(self, key):
if key not in self._pex_info:
Expand Down Expand Up @@ -512,11 +511,8 @@ def raw_pex_root(self):
def pex_root(self):
# type: () -> str
pex_root = os.path.realpath(os.path.expanduser(self.raw_pex_root))
if can_write_dir(pex_root):
os.environ.pop("_PEX_BACKUP_ROOT", None)
safe_rmtree(self._backup_pex_root)
else:
tmp_root = os.path.realpath(self._backup_pex_root)
if not can_write_dir(pex_root):
tmp_root = os.path.realpath(self._BACKUP_PEX_ROOT.tounicode())
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

0 comments on commit d075c89

Please sign in to comment.