Skip to content

Commit f3c53fe

Browse files
Remove dependency cycle (#29)
1 parent 11e2906 commit f3c53fe

File tree

4 files changed

+41
-42
lines changed

4 files changed

+41
-42
lines changed

extract_wheels/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import subprocess
1212
import sys
1313

14-
from extract_wheels.lib import wheel, bazel
14+
from extract_wheels.lib import bazel
1515

1616

1717
def configure_reproducible_wheels() -> None:
@@ -71,7 +71,7 @@ def main() -> None:
7171
)
7272

7373
targets = [
74-
'"%s%s"' % (args.repo, wheel.extract_wheel(whl, []))
74+
'"%s%s"' % (args.repo, bazel.extract_wheel(whl, []))
7575
for whl in glob.glob("*.whl")
7676
]
7777

extract_wheels/lib/__init__.py

Whitespace-only changes.

extract_wheels/lib/bazel.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
"""Utility functions to manipulate Bazel files"""
2+
import os
23
import textwrap
34
from typing import Iterable, List
45

5-
from extract_wheels.lib import namespace_pkgs
6+
from extract_wheels.lib import namespace_pkgs, wheel, purelib
67

78

89
def generate_build_file_contents(name: str, dependencies: List[str]) -> str:
@@ -110,3 +111,40 @@ def setup_namespace_pkg_compatibility(wheel_dir: str) -> None:
110111

111112
for ns_pkg_dir in namespace_pkg_dirs:
112113
namespace_pkgs.add_pkgutil_style_namespace_pkg_init(ns_pkg_dir)
114+
115+
116+
def extract_wheel(wheel_file: str, extras: List[str]) -> str:
117+
"""Extracts wheel into given directory and creates a py_library target.
118+
119+
Args:
120+
wheel_file: the filepath of the .whl
121+
extras: a list of extras to add as dependencies for the installed wheel
122+
123+
Returns:
124+
The Bazel label for the extracted wheel, in the form '//path/to/wheel'.
125+
"""
126+
127+
whl = wheel.Wheel(wheel_file)
128+
directory = sanitise_name(whl.name)
129+
130+
os.mkdir(directory)
131+
whl.unzip(directory)
132+
133+
# Note: Order of operations matters here
134+
purelib.spread_purelib_into_root(directory)
135+
setup_namespace_pkg_compatibility(directory)
136+
137+
with open(os.path.join(directory, "BUILD"), "w") as build_file:
138+
build_file.write(
139+
generate_build_file_contents(
140+
sanitise_name(whl.name),
141+
[
142+
'"//%s"' % sanitise_name(d)
143+
for d in sorted(whl.dependencies(extras_requested=extras))
144+
],
145+
)
146+
)
147+
148+
os.remove(whl.path)
149+
150+
return "//%s" % directory

extract_wheels/lib/wheel.py

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
import pkg_resources
88
import pkginfo
99

10-
from extract_wheels.lib import bazel, purelib
11-
1210

1311
class Wheel:
1412
"""Representation of the compressed .whl file"""
@@ -118,40 +116,3 @@ def parse_wheel_meta_file(wheel_dir: str) -> Dict[str, str]:
118116
"Encounted invalid line in WHEEL file: '%s'" % cleaned
119117
)
120118
return contents
121-
122-
123-
def extract_wheel(wheel_file: str, extras: List[str]) -> str:
124-
"""Extracts wheel into given directory and creates a py_library target.
125-
126-
Args:
127-
wheel_file: the filepath of the .whl
128-
extras: a list of extras to add as dependencies for the installed wheel
129-
130-
Returns:
131-
The Bazel label for the extracted wheel, in the form '//path/to/wheel'.
132-
"""
133-
134-
whl = Wheel(wheel_file)
135-
directory = bazel.sanitise_name(whl.name)
136-
137-
os.mkdir(directory)
138-
whl.unzip(directory)
139-
140-
# Note: Order of operations matters here
141-
purelib.spread_purelib_into_root(directory)
142-
bazel.setup_namespace_pkg_compatibility(directory)
143-
144-
with open(os.path.join(directory, "BUILD"), "w") as build_file:
145-
build_file.write(
146-
bazel.generate_build_file_contents(
147-
bazel.sanitise_name(whl.name),
148-
[
149-
'"//%s"' % bazel.sanitise_name(d)
150-
for d in sorted(whl.dependencies(extras_requested=extras))
151-
],
152-
)
153-
)
154-
155-
os.remove(whl.path)
156-
157-
return "//%s" % directory

0 commit comments

Comments
 (0)