Skip to content

Commit

Permalink
handle modules contained within packages in fake venv
Browse files Browse the repository at this point in the history
Change-Id: Ia512780c98c55e61cfcf97e60806fd673cd16bd0
  • Loading branch information
oliverlee committed Oct 3, 2024
1 parent 367a408 commit 77ae341
Showing 1 changed file with 36 additions and 11 deletions.
47 changes: 36 additions & 11 deletions private/local_python_fake_venv.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,51 @@ echo "$packages"

result = rctx.execute(
["./requirements.bash"],
timeout = 3,
timeout = 1,
)
if result.return_code != 0:
fail(result.stderr)

pyenv = rctx.attr.pip_requirements.workspace_name
external = str(rctx.path(rctx.attr.pip_requirements)).rsplit("/", 2)[0]
for pkg in result.stdout.splitlines():
rctx.symlink(
"{external}/{pyenv}_{pkg}/site-packages/{pkg}".format(
external = external,
pyenv = pyenv,
pkg = pkg,
),
"{pyenv}/site-packages/{pkg}".format(
pyenv = pyenv,
pkg = pkg,
),
site_packages = "{external}/{pyenv}_{pkg}/site-packages".format(
external = external,
pyenv = pyenv,
pkg = pkg,
)

result = rctx.execute(
[
"find",
site_packages,
"!",
"-name",
"*-*",
"-maxdepth",
"1",
"-type",
"d",
],
timeout = 1,
)
modules = [
p.rpartition("/")[-1]
for p in result.stdout.strip().splitlines()
]

for mod in modules:
rctx.symlink(
"{source}/{mod}".format(
source = site_packages,
mod = mod,
),
"{pyenv}/site-packages/{mod}".format(
pyenv = pyenv,
mod = mod,
),
)

local_python_fake_venv = repository_rule(
implementation = _impl,
local = True,
Expand Down

0 comments on commit 77ae341

Please sign in to comment.