Skip to content

Commit e969b7b

Browse files
authored
Portability fixes when running on windows (#480)
Fixes: - path handling in various places ('\' vs '/') - newline when writing the new binary "script" shim
1 parent 4e929a7 commit e969b7b

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

src/auditwheel/elfutils.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

3-
import os
4-
from os.path import basename, realpath, relpath
3+
from os.path import basename
4+
from pathlib import Path
55
from typing import Iterator
66

77
from elftools.common.exceptions import ELFError
@@ -126,17 +126,14 @@ def elf_read_rpaths(fn: str) -> dict[str, list[str]]:
126126
return result
127127

128128

129-
def is_subdir(path: str, directory: str) -> bool:
129+
def is_subdir(path: str | Path | None, directory: str | Path) -> bool:
130130
if path is None:
131131
return False
132132

133-
path = realpath(path)
134-
directory = realpath(directory)
133+
path = Path(path).resolve()
134+
directory = Path(directory).resolve()
135135

136-
relative = relpath(path, directory)
137-
if relative.startswith(os.pardir):
138-
return False
139-
return True
136+
return directory in path.parents
140137

141138

142139
def get_undefined_symbols(path: str) -> set[str]:

src/auditwheel/repair.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import stat
1010
from os.path import abspath, basename, dirname, exists, isabs
1111
from os.path import join as pjoin
12+
from pathlib import Path
1213
from subprocess import check_call
1314
from typing import Iterable
1415

@@ -237,7 +238,7 @@ def _resolve_rpath_tokens(rpath: str, lib_base_dir: str) -> str:
237238

238239
def _path_is_script(path: str) -> bool:
239240
# Looks something like "uWSGI-2.0.21.data/scripts/uwsgi"
240-
components = path.split("/")
241+
components = Path(path).parts
241242
return (
242243
len(components) == 3
243244
and components[0].endswith(".data")
@@ -265,7 +266,7 @@ def _replace_elf_script_with_shim(package_name: str, orig_path: str) -> str:
265266
new_path = os.path.join(scripts_dir, os.path.basename(orig_path))
266267
os.rename(orig_path, new_path)
267268

268-
with open(orig_path, "w") as f:
269+
with open(orig_path, "w", newline="\n") as f:
269270
f.write(_script_shim(new_path))
270271
os.chmod(orig_path, os.stat(new_path).st_mode)
271272

@@ -286,5 +287,5 @@ def _script_shim(binary_path: str) -> str:
286287
sys.argv,
287288
)
288289
""".format(
289-
binary_path=binary_path,
290+
binary_path=Path(binary_path).as_posix(),
290291
)

0 commit comments

Comments
 (0)