Skip to content

Commit 58aae63

Browse files
committed
fixup after moving
1 parent 7d5de87 commit 58aae63

File tree

3 files changed

+40
-21
lines changed

3 files changed

+40
-21
lines changed

python/private/py_executable.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ def _create_venv(ctx, output_prefix, imports, runtime_details):
612612
VenvSymlinkKind.BIN: bin_dir,
613613
VenvSymlinkKind.LIB: site_packages,
614614
}
615-
venv_app_files = create_venv_app_files(ctx, venv_dir_map)
615+
venv_app_files = create_venv_app_files(ctx, ctx.attr.deps, venv_dir_map)
616616

617617
files_without_interpreter = [pth, site_init] + venv_app_files
618618
if pyvenv_cfg:

python/private/py_library.bzl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,21 @@ def _get_imports_and_venv_symlinks(ctx, semantics):
233233
venv_symlinks = []
234234
if VenvsSitePackages.is_enabled(ctx):
235235
package, version_str = _get_package_and_version(ctx)
236-
venv_symlinks = get_venv_symlinks(ctx, package, version_str, ctx.attr.imports)
236+
imports = ctx.attr.imports
237+
if len(imports) == 0:
238+
fail("When venvs_site_packages is enabled, exactly one `imports` " +
239+
"value must be specified, got 0")
240+
elif len(imports) > 1:
241+
fail("When venvs_site_packages is enabled, exactly one `imports` " +
242+
"value must be specified, got {}".format(imports))
243+
244+
venv_symlinks = get_venv_symlinks(
245+
ctx,
246+
ctx.files.srcs + ctx.files.data + ctx.files.pyi_srcs,
247+
package,
248+
version_str,
249+
site_packages_root = imports[0],
250+
)
237251
else:
238252
imports = collect_imports(ctx, semantics)
239253
return imports, venv_symlinks

python/private/venv_runfiles.bzl

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)