Skip to content

Commit 197f037

Browse files
author
Jonathon Belotti
committed
1 parent b9ed0e3 commit 197f037

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

src/purelib.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,25 @@ def spread_purelib_into_root(extracted_whl_directory: str) -> None:
1919
return
2020

2121
dot_data_dir = wheel.get_dot_data_directory(extracted_whl_directory)
22-
2322
# 'Root-Is-Purelib: false' is no guarantee a .date directory exists with
2423
# package code in it. eg. the 'markupsafe' package.
25-
if dot_data_dir:
26-
for child in pathlib.Path(dot_data_dir).iterdir():
27-
# TODO(Jonathon): Should all other potential folders get ignored? eg. 'platlib'
28-
if str(child).endswith("purelib"):
29-
for grandchild in child.iterdir():
30-
shutil.move(
31-
src=str(grandchild),
32-
dst=extracted_whl_directory,
33-
)
24+
if not dot_data_dir:
25+
return
26+
27+
for child in pathlib.Path(dot_data_dir).iterdir():
28+
# TODO(Jonathon): Should all other potential folders get ignored? eg. 'platlib'
29+
if str(child).endswith("purelib"):
30+
_spread_purelib(child, extracted_whl_directory)
31+
32+
33+
def _spread_purelib(purelib_dir, root_dir):
34+
for grandchild in purelib_dir.iterdir():
35+
# Some purelib Wheels, like Tensorflow 2.0.0, have directories
36+
# split between the root and the purelib directory. In this case
37+
# we should leave the purelib 'sibling' alone.
38+
# See: https://github.com/dillon-giacoppo/rules_python_external/issues/8
39+
if not pathlib.Path(root_dir, grandchild.name).exists():
40+
shutil.move(
41+
src=str(grandchild),
42+
dst=root_dir,
43+
)

0 commit comments

Comments
 (0)