@@ -15,13 +15,15 @@ load(
1515 "VenvSymlinkKind" ,
1616)
1717
18- def create_venv_app_files (ctx , venv_dir_map ):
18+ def create_venv_app_files (ctx , deps , venv_dir_map ):
1919 """Creates the tree of app-specific files for a venv for a binary.
2020
2121 App specific files are the files that come from dependencies.
2222
2323 Args:
2424 ctx: {type}`ctx` current ctx.
25+ deps: {type}`list[Target]` the targets whose venv information
26+ to put into the returned venv files.
2527 venv_dir_map: mapping of VenvSymlinkKind constants to the
2628 venv path. This tells the directory name of
2729 platform/configuration-dependent directories. The values are
@@ -35,7 +37,7 @@ def create_venv_app_files(ctx, venv_dir_map):
3537 entries = depset (
3638 transitive = [
3739 dep [PyInfo ].venv_symlinks
38- for dep in ctx . attr . deps
40+ for dep in deps
3941 if PyInfo in dep
4042 ],
4143 ).to_list ()
@@ -191,24 +193,28 @@ def _merge_venv_path_group(ctx, group, keep_map):
191193 if venv_path not in keep_map :
192194 keep_map [venv_path ] = file
193195
194- def get_venv_symlinks (ctx , package , version_str , imports ):
195- if len ( imports ) == 0 :
196- fail ( "When venvs_site_packages is enabled, exactly one `imports` " +
197- "value must be specified, got 0" )
198- elif len ( imports ) > 1 :
199- fail ( "When venvs_site_packages is enabled, exactly one `imports` " +
200- "value must be specified, got {}" . format ( imports ))
201- else :
202- site_packages_root = imports [ 0 ]
196+ def get_venv_symlinks (ctx , files , package , version_str , site_packages_root ):
197+ """Compute the VenvSymlinkEntry objects for a library.
198+
199+ Args:
200+ ctx: {type}`ctx` the current ctx.
201+ package: {type}`str` the Python distribution name.
202+ version_str: {type}`str` the distribution's version.
203+ site_packages_root: {type}`str` prefix under which files are
204+ considered to be part of the installed files.
203205
206+ Returns:
207+ {type}`list[VenvSymlinkEntry]` the entries that describe how
208+ to map the files into a venv.
209+ """
204210 if site_packages_root .endswith ("/" ):
205- fail ("The site packages root value from `imports` cannot end in " +
211+ fail ("The `site_packages_root` value cannot end in " +
206212 "slash, got {}" .format (site_packages_root ))
207213 if site_packages_root .startswith ("/" ):
208- fail ("The site packages root value from `imports ` cannot start with " +
214+ fail ("The `site_packages_root ` cannot start with " +
209215 "slash, got {}" .format (site_packages_root ))
210216
211- # Append slash to prevent incorrectly prefix-string matches
217+ # Append slash to prevent incorrect prefix-string matches
212218 site_packages_root += "/"
213219
214220 # We have to build a list of (runfiles path, site-packages path) pairs of the files to
@@ -228,10 +234,9 @@ def get_venv_symlinks(ctx, package, version_str, imports):
228234
229235 dir_symlinks = {} # dirname -> runfile path
230236 venv_symlinks = []
231- all_files = sorted (
232- ctx .files .srcs + ctx .files .data + ctx .files .pyi_srcs ,
233- key = lambda f : f .short_path ,
234- )
237+
238+ # Sort so order is top-down
239+ all_files = sorted (files , key = lambda f : f .short_path )
235240
236241 for src in all_files :
237242 path = _repo_relative_short_path (src .short_path )
@@ -307,4 +312,4 @@ def _repo_relative_short_path(short_path):
307312 if short_path .startswith ("../" ):
308313 return short_path [3 :].partition ("/" )[2 ]
309314 else :
310- return short_path
315+ return short_path
0 commit comments