Skip to content

Commit

Permalink
Fix test_pex_builder_add_source_relpath_issues_1192 issue under Pyt…
Browse files Browse the repository at this point in the history
…hon 2.7.
  • Loading branch information
jsirois committed Jul 26, 2023
1 parent f93421e commit 4ca216c
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions pex/pex_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@
from typing import Dict, Optional


# N.B.: __file__ will be relative when this module is loaded from a "" `sys.path` entry under
# Python 2.7. This can occur in test scenarios; so we ensure the __file__ is resolved to an absolute
# path here at import time before any cd'ing occurs in test code that might interfere with our
# attempts to locate Pex files later below.
_ABS_PEX_PACKAGE_DIR = os.path.dirname(os.path.abspath(__file__))


class CopyMode(Enum["CopyMode.Value"]):
class Value(Enum.Value):
pass
Expand Down Expand Up @@ -579,9 +586,8 @@ def _prepare_bootstrap(self):
bootstrap_packages = ["third_party", "venv"]
if self._pex_info.includes_tools:
bootstrap_packages.extend(["commands", "tools"])
package_root = os.path.dirname(__file__)
for root, dirs, files in os.walk(package_root):
if root == package_root:
for root, dirs, files in os.walk(_ABS_PEX_PACKAGE_DIR):
if root == _ABS_PEX_PACKAGE_DIR:
dirs[:] = bootstrap_packages

for f in filter_pyc_files(files):
Expand All @@ -593,7 +599,9 @@ def _prepare_bootstrap(self):
self._chroot.write(
data,
dst=os.path.join(
self._pex_info.bootstrap, "pex", os.path.relpath(abs_src, package_root)
self._pex_info.bootstrap,
"pex",
os.path.relpath(abs_src, _ABS_PEX_PACKAGE_DIR),
),
label="bootstrap",
)
Expand Down

0 comments on commit 4ca216c

Please sign in to comment.