Skip to content

Commit

Permalink
More fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jvolkman committed Feb 7, 2024
1 parent 8faed8b commit 8ffe7ac
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
11 changes: 9 additions & 2 deletions delocate/delocating.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
_allow_all,
filter_system_libs,
get_rp_stripper,
is_resolved_subpath,
stripped_lib_dict,
tree_libs,
tree_libs_from_directory,
Expand Down Expand Up @@ -58,8 +59,14 @@ class DelocationError(Exception):
pass


def posix_relpath(path: str, start: str = None) -> str:
def posix_relpath(
path: Union[str, os.PathLike],
start: Union[str, os.PathLike],
) -> str:
"""Return path relative to start using posix separators (/)."""
# We use os.path.relpath here since Path.relative_to doesn't support
# relative sibling paths. E.g., relpath("foo", "bar") == "../foo",
# but Path("foo").relative_to(Path("bar")) raises an error.
rel = relpath(path, start)
return Path(rel).as_posix()

Expand Down Expand Up @@ -165,7 +172,7 @@ def _analyze_tree_libs(
# @rpath, etc, at this point should never happen.
raise DelocationError("%s was expected to be resolved." % required)
r_ed_base = basename(required)
if Path(rp_root_path) not in Path(required).parents:
if not is_resolved_subpath(required, rp_root_path):
# Not local, plan to copy
if r_ed_base in copied_basenames:
raise DelocationError(
Expand Down
19 changes: 13 additions & 6 deletions delocate/libsana.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
Set,
Text,
Tuple,
Union,
)

import delocate.delocating
Expand All @@ -41,12 +42,18 @@ class DependencyNotFound(Exception):
"""


def filter_system_libs(libname: Text) -> bool:
def is_resolved_subpath(
path: Union[str, os.PathLike],
base: Union[str, os.PathLike],
) -> bool:
return Path(base).resolve() in Path(path).resolve().parents


def filter_system_libs(libname: Union[str, os.PathLike]) -> bool:
"""Return True if libname starts with /System or /usr/lib."""
# If libname has a drive letter, we need to strip it off first.
_, libname = os.path.splitdrive(libname)
libname = Path(libname).as_posix()
return not (libname.startswith("/usr/lib") or libname.startswith("/System"))
return not any(
is_resolved_subpath(libname, base) for base in ["/usr/lib", "/System"]
)


def get_dependencies(
Expand Down Expand Up @@ -772,4 +779,4 @@ def _paths_from_var(varname: str, lib_basename: str) -> List[str]:
var = os.environ.get(varname)
if var is None:
return []
return [pjoin(path, lib_basename) for path in var.split(":")]
return [pjoin(path, lib_basename) for path in var.split(os.pathsep)]
2 changes: 1 addition & 1 deletion delocate/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ def get_environment_variable_paths():
for pathname in extra_paths:
path_contents = os.environ.get(pathname)
if path_contents is not None:
for path in path_contents.split(":"):
for path in path_contents.split(os.pathsep):
env_var_paths.append(path)
return tuple(env_var_paths)

Expand Down

0 comments on commit 8ffe7ac

Please sign in to comment.