Skip to content

Commit a6f2bd7

Browse files
authored
fix: resolve path of InTemporaryDirectory name (#569)
1 parent a67aa87 commit a6f2bd7

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

src/auditwheel/tmpdirs.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,17 @@ class InTemporaryDirectory:
2727

2828
def __init__(self) -> None:
2929
self._tmpdir = TemporaryDirectory()
30+
self._name = Path(self._tmpdir.name).resolve(strict=True)
3031

3132
@property
3233
def name(self) -> Path:
33-
return Path(self._tmpdir.name)
34+
return self._name
3435

3536
def __enter__(self) -> Path:
3637
self._pwd = Path.cwd()
37-
os.chdir(self._tmpdir.name)
38-
return Path(self._tmpdir.__enter__())
38+
os.chdir(self._name)
39+
self._tmpdir.__enter__()
40+
return self._name
3941

4042
def __exit__(
4143
self,
@@ -44,7 +46,7 @@ def __exit__(
4446
tb: TracebackType | None,
4547
) -> None:
4648
os.chdir(self._pwd)
47-
return self._tmpdir.__exit__(exc, value, tb)
49+
self._tmpdir.__exit__(exc, value, tb)
4850

4951

5052
class InGivenDirectory:

tests/unit/test_wheeltools.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
from __future__ import annotations
22

33
import re
4+
import tempfile
5+
from pathlib import Path
46

57
import pytest
68

79
from auditwheel.architecture import Architecture
810
from auditwheel.error import NonPlatformWheel
911
from auditwheel.libc import Libc
1012
from auditwheel.wheeltools import (
13+
InWheelCtx,
1114
WheelToolsError,
1215
get_wheel_architecture,
1316
get_wheel_libc,
1417
)
1518

19+
HERE = Path(__file__).parent.resolve()
20+
1621

1722
@pytest.mark.parametrize(
1823
("filename", "expected"),
@@ -76,3 +81,19 @@ def test_get_wheel_libc_multiple(filename: str) -> None:
7681
match = re.escape("multiple libc are not supported")
7782
with pytest.raises(WheelToolsError, match=match):
7883
get_wheel_libc(filename)
84+
85+
86+
def test_inwheel_tmpdir(tmp_path, monkeypatch):
87+
wheel_path = (
88+
HERE
89+
/ "../integration/arch-wheels/glibc/testsimple-0.0.1-cp313-cp313-linux_x86_64.whl"
90+
)
91+
tmp_path = tmp_path.resolve(strict=True)
92+
tmpdir = tmp_path / "tmpdir"
93+
tmpdir.mkdir()
94+
tmpdir_symlink = tmp_path / "symlink"
95+
tmpdir_symlink.symlink_to(str(tmpdir), target_is_directory=True)
96+
monkeypatch.setattr(tempfile, "gettempdir", lambda: str(tmpdir_symlink))
97+
with InWheelCtx(wheel_path, tmp_path / wheel_path.name) as context:
98+
Path(context._tmpdir.name).relative_to(tmpdir_symlink)
99+
context.name.relative_to(tmpdir)

0 commit comments

Comments
 (0)