Skip to content

Commit 89c81f8

Browse files
committed
Review comments:
+ test cases + docstring + formatting + types
1 parent cb95505 commit 89c81f8

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

tests/tools/wheelmaker_test.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,22 @@
44

55

66
class ArcNameFromTest(unittest.TestCase):
7-
87
def test_arcname_from(self) -> None:
9-
108
# (name, distribution_prefix, strip_path_prefixes, want) tuples
119
checks = [
12-
("foo/bar/baz/file.py", "", [], "foo/bar/baz/file.py"),
13-
("foo/bar/baz/file.py", "", ["foo"], "/bar/baz/file.py"),
14-
("foo/bar/baz/file.py", "", ["foo/"], "bar/baz/file.py"),
15-
("foo/bar/baz/file.py", "", ["foo/bar"], "/baz/file.py"),
16-
("foo/bar/baz/file.py", "", ["foo/bar", "baz"], "/baz/file.py"),
17-
("foo/bar/baz/file.py", "", ["foo", "bar"], "/bar/baz/file.py"),
18-
("foo/bar/baz/file.py", "", ["baz", "foo/bar"], "/baz/file.py"),
10+
("a/b/c/file.py", "", [], "a/b/c/file.py"),
11+
("a/b/c/file.py", "", ["a"], "/b/c/file.py"),
12+
("a/b/c/file.py", "", ["a/b/"], "c/file.py"),
13+
# only first found is used and it's not cumulative.
14+
("a/b/c/file.py", "", ["a/", "b/"], "b/c/file.py"),
15+
# Examples from docs
16+
("foo/bar/baz/file.py", "", ["foo", "foo/bar/baz"], "/bar/baz/file.py"),
17+
("foo/bar/baz/file.py", "", ["foo/bar/baz", "foo"], "/file.py"),
18+
("foo/file2.py", "", ["foo/bar/baz", "foo"], "/file2.py"),
19+
# Files under the distribution prefix (eg mylib-1.0.0-dist-info)
20+
# are unmodified
21+
("mylib-0.0.1-dist-info/WHEEL", "mylib", [], "mylib-0.0.1-dist-info/WHEEL"),
22+
("mylib/a/b/c/WHEEL", "mylib", ["mylib"], "mylib/a/b/c/WHEEL"),
1923
]
2024
for name, prefix, strip, want in checks:
2125
with self.subTest(

tools/wheelmaker.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import stat
2525
import sys
2626
import zipfile
27+
from collections.abc import Iterable
2728
from pathlib import Path
2829

2930
_ZIP_EPOCH = (1980, 1, 1, 0, 0, 0)
@@ -99,8 +100,17 @@ def normalize_pep440(version):
99100

100101

101102
def arcname_from(
102-
name: str, distribution_prefix: str, strip_path_prefixes: list[str] | None = None
103-
):
103+
name: str, distribution_prefix: str, strip_path_prefixes: Sequence[str] = ()
104+
) -> str:
105+
"""Return the within-archive name for a given file path name.
106+
107+
Prefixes to strip are checked in order and only the first match will be used.
108+
109+
Args:
110+
name: The file path eg 'mylib/a/b/c/file.py'
111+
distribution_prefix: The
112+
strip_path_prefixes: Remove these prefixes from names.
113+
"""
104114
# Always use unix path separators.
105115
normalized_arcname = name.replace(os.path.sep, "/")
106116
# Don't manipulate names filenames in the .distinfo or .data directories.

0 commit comments

Comments
 (0)