@@ -215,17 +215,7 @@ def install_deps():
215215 )
216216
217217
218- DEFAULT_PACKAGE_PREFIX = "pypi__"
219-
220-
221- def whl_library_repo_prefix (parent_repo : str ) -> str :
222- return "{parent}_{default_package_prefix}" .format (
223- parent = parent_repo ,
224- default_package_prefix = DEFAULT_PACKAGE_PREFIX
225- )
226-
227-
228- def sanitise_name (name : str , prefix : str = DEFAULT_PACKAGE_PREFIX ) -> str :
218+ def sanitise_name (name : str , prefix : str ) -> str :
229219 """Sanitises the name to be compatible with Bazel labels.
230220
231221 There are certain requirements around Bazel labels that we need to consider. From the Bazel docs:
@@ -268,12 +258,12 @@ def setup_namespace_pkg_compatibility(wheel_dir: str) -> None:
268258 namespace_pkgs .add_pkgutil_style_namespace_pkg_init (ns_pkg_dir )
269259
270260
271- def sanitised_library_label (whl_name : str ) -> str :
272- return '"//%s"' % sanitise_name (whl_name )
261+ def sanitised_library_label (whl_name : str , prefix : str ) -> str :
262+ return '"//%s"' % sanitise_name (whl_name , prefix )
273263
274264
275- def sanitised_file_label (whl_name : str ) -> str :
276- return '"//%s:%s"' % (sanitise_name (whl_name ), WHEEL_FILE_LABEL )
265+ def sanitised_file_label (whl_name : str , prefix : str ) -> str :
266+ return '"//%s:%s"' % (sanitise_name (whl_name , prefix ), WHEEL_FILE_LABEL )
277267
278268
279269def _whl_name_to_repo_root (whl_name : str , repo_prefix : str ) -> str :
@@ -293,8 +283,8 @@ def extract_wheel(
293283 extras : Dict [str , Set [str ]],
294284 pip_data_exclude : List [str ],
295285 enable_implicit_namespace_pkgs : bool ,
286+ repo_prefix : str ,
296287 incremental : bool = False ,
297- incremental_repo_prefix : Optional [str ] = None ,
298288) -> Optional [str ]:
299289 """Extracts wheel into given directory and creates py_library and filegroup targets.
300290
@@ -305,8 +295,6 @@ def extract_wheel(
305295 enable_implicit_namespace_pkgs: if true, disables conversion of implicit namespace packages and will unzip as-is
306296 incremental: If true the extract the wheel in a format suitable for an external repository. This
307297 effects the names of libraries and their dependencies, which point to other external repositories.
308- incremental_repo_prefix: If incremental is true, use this prefix when creating labels from wheel
309- names instead of the default.
310298
311299 Returns:
312300 The Bazel label for the extracted wheel, in the form '//path/to/wheel'.
@@ -316,7 +304,7 @@ def extract_wheel(
316304 if incremental :
317305 directory = "."
318306 else :
319- directory = sanitise_name (whl .name )
307+ directory = sanitise_name (whl .name , prefix = repo_prefix )
320308
321309 os .mkdir (directory )
322310 # copy the original wheel
@@ -333,25 +321,21 @@ def extract_wheel(
333321 whl_deps = sorted (whl .dependencies (extras_requested ))
334322
335323 if incremental :
336- # check for mypy Optional validity
337- if incremental_repo_prefix is None :
338- raise TypeError (
339- "incremental_repo_prefix arguement cannot be None if incremental == True" )
340324 sanitised_dependencies = [
341- sanitised_repo_library_label (d , repo_prefix = incremental_repo_prefix ) for d in whl_deps
325+ sanitised_repo_library_label (d , repo_prefix = repo_prefix ) for d in whl_deps
342326 ]
343327 sanitised_wheel_file_dependencies = [
344- sanitised_repo_file_label (d , repo_prefix = incremental_repo_prefix ) for d in whl_deps
328+ sanitised_repo_file_label (d , repo_prefix = repo_prefix ) for d in whl_deps
345329 ]
346330 else :
347331 sanitised_dependencies = [
348- sanitised_library_label (d ) for d in whl_deps
332+ sanitised_library_label (d , prefix = repo_prefix ) for d in whl_deps
349333 ]
350334 sanitised_wheel_file_dependencies = [
351- sanitised_file_label (d ) for d in whl_deps
335+ sanitised_file_label (d , prefix = repo_prefix ) for d in whl_deps
352336 ]
353337
354- library_name = PY_LIBRARY_LABEL if incremental else sanitise_name (whl .name )
338+ library_name = PY_LIBRARY_LABEL if incremental else sanitise_name (whl .name , repo_prefix )
355339
356340 directory_path = Path (directory )
357341 entry_points = []
@@ -365,7 +349,7 @@ def extract_wheel(
365349
366350 with open (os .path .join (directory , "BUILD.bazel" ), "w" ) as build_file :
367351 contents = generate_build_file_contents (
368- library_name ,
352+ PY_LIBRARY_LABEL if incremental else sanitise_name ( whl . name , repo_prefix ) ,
369353 sanitised_dependencies ,
370354 sanitised_wheel_file_dependencies ,
371355 pip_data_exclude ,
0 commit comments