11"""Utility functions to manipulate Bazel files"""
22import os
33import textwrap
4- from typing import Iterable , List
4+ from typing import Iterable , List , Dict , Set
55
66from extract_wheels .lib import namespace_pkgs , wheel , purelib
77
@@ -113,7 +113,7 @@ def setup_namespace_pkg_compatibility(wheel_dir: str) -> None:
113113 namespace_pkgs .add_pkgutil_style_namespace_pkg_init (ns_pkg_dir )
114114
115115
116- def extract_wheel (wheel_file : str , extras : List [str ]) -> str :
116+ def extract_wheel (wheel_file : str , extras : Dict [str , Set [ str ] ]) -> str :
117117 """Extracts wheel into given directory and creates a py_library target.
118118
119119 Args:
@@ -134,16 +134,17 @@ def extract_wheel(wheel_file: str, extras: List[str]) -> str:
134134 purelib .spread_purelib_into_root (directory )
135135 setup_namespace_pkg_compatibility (directory )
136136
137+ extras_requested = extras [whl .name ] if whl .name in extras else set ()
138+
139+ sanitised_dependencies = [
140+ '"//%s"' % sanitise_name (d ) for d in sorted (whl .dependencies (extras_requested ))
141+ ]
142+
137143 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- )
144+ contents = generate_build_file_contents (
145+ sanitise_name (whl .name ), sanitised_dependencies ,
146146 )
147+ build_file .write (contents )
147148
148149 os .remove (whl .path )
149150
0 commit comments