@@ -216,16 +216,20 @@ def _get_imports_and_site_packages_symlinks(ctx, semantics):
216216def  _get_site_packages_symlinks (ctx ):
217217    imports  =  ctx .attr .imports 
218218    if  len (imports ) ==  0 :
219-         fail ("Must specify imports attr" )
219+         fail ("When venvs_site_packages is enabled, exactly one `imports` "  + 
220+              "value must be specified, got 0" )
220221    elif  len (imports ) >  1 :
221-         fail ("Too many imports paths" )
222+         fail ("When venvs_site_packages is enabled, exactly one `imports` "  + 
223+              "value must be specified, got {}" .format (imports ))
222224    else :
223225        site_packages_root  =  imports [0 ]
224226
225227    if  site_packages_root .endswith ("/" ):
226-         fail ("should not end in slash" )
228+         fail ("The site packages root value from `imports` cannot end in "  + 
229+              "slash, got {}" .format (site_packages_root ))
227230    if  site_packages_root .startswith ("/" ):
228-         fail ("cannot start with slash" )
231+         fail ("The site packages root value from `imports` cannot start with "  + 
232+              "slash, got {}" .format (site_packages_root ))
229233
230234    # Append slash to prevent incorrectly prefix-string matches 
231235    site_packages_root  +=  "/" 
@@ -245,7 +249,6 @@ def _get_site_packages_symlinks(ctx):
245249    # directories that _do_ have an `__init__.py` file and treat those as 
246250    # the path to symlink to. 
247251
248-     ##site_packages_root = paths.join(ctx.label.package, site_packages_root) 
249252    repo_runfiles_dirname  =  None 
250253    dirs_with_init  =  {}  # dirname -> runfile path 
251254    for  src  in  ctx .files .srcs :
@@ -257,8 +260,10 @@ def _get_site_packages_symlinks(ctx):
257260        path  =  path .removeprefix (site_packages_root )
258261        dir_name , _ , filename  =  path .rpartition ("/" )
259262        if  not  dir_name :
260-             # This would be e.g. `site-packages/__init__.py`, which isn't valid. 
261-             # Apparently, the pypi integration adds such a file? 
263+             # This would be e.g. `site-packages/__init__.py`, which isn't valid 
264+             # because it's not within a directory for an importable Python package. 
265+             # However, the pypi integration over-eagerly adds a pkgutil-style 
266+             # __init__.py file during the repo phase. Just ignore them for now. 
262267            continue 
263268
264269        if  filename .startswith ("__init__." ):
@@ -285,12 +290,12 @@ def _get_site_packages_symlinks(ctx):
285290            paths .join (repo_runfiles_dirname , site_packages_root , dirname ),
286291            dirname ,
287292        ))
288-     if  not  site_packages_symlinks :
289-         fail ("empty?" , ctx .label , site_packages_root , ctx .files .srcs [0 ])
290293    return  site_packages_symlinks 
291294
292295def  _repo_relative_short_path (short_path ):
296+     # Convert `../+pypi+foo/some/file.py` to `some/file.py` 
293297    if  short_path .startswith ("../" ):
298+         fail (short_path )
294299        return  short_path [3 :].partition ("/" )[2 ]
295300    else :
296301        return  short_path 
0 commit comments