Skip to content

Commit 22c308d

Browse files
authored
fix(venv_link): Restore original venv name mangling (#589)
Reported by @jimmyt857 in testing of v1.6.0-rc0 Previously running the `examples/py_binary:py_binary.venv` target would create a link `$BUILD_WORKING_DIRECTORY/.examples+py_binary+py_binary.venv`. This behavior regressed in 1.5.0 and the link became simply `$BUILD_WORKING_DIRECTORY/.py_binary.venv`. Restore the original behavior. --- ### Changes are visible to end-users: no - Searched for relevant documentation and updated as needed: no - Breaking change (forces users to change their own code or config): no - Suggested release notes appear below: no ### Test plan - [x] Manual testing ```shellsession ❯ bazel run //examples/py_binary:py_binary.venv INFO: Analyzed target //examples/py_binary:py_binary.venv (0 packages loaded, 0 targets configured). INFO: Found 1 target... Target //examples/py_binary:py_binary.venv up-to-date: bazel-bin/examples/py_binary/py_binary.venv INFO: Elapsed time: 0.815s, Critical Path: 0.05s INFO: 2 processes: 1 internal, 1 darwin-sandbox. INFO: Build completed successfully, 2 total actions INFO: Running command line: bazel-bin/examples/py_binary/py_binary.venv usage: link [options] Helper to create a symlink to a virtualenv in the source tree. optional arguments: -h, --help show this help message and exit --dest DEST Dir to link the virtualenv into. Default is $BUILD_WORKING_DIRECTORY. (default: /Users/arrdem/Documents/work/aspect/rules_py) --name NAME Name to link the virtualenv as. (default: .examples+py_binary+py_binary.venv) Linking: /private/var/tmp/_bazel_arrdem/93bfea6cdc1153cc29a75400cd38823a/execroot/aspect_rules_py/bazel-out/darwin_arm64-fastbuild/bin/examples/py_binary/.py_binary.venv -> /Users/arrdem/Documents/work/aspect/rules_py/.examples+py_binary+py_binary.venv Link is up to date! To configure the virtualenv in your IDE, configure an interpreter with the homedir /Users/arrdem/Documents/work/aspect/rules_py/.examples+py_binary+py_binary.venv To activate the virtualenv in your shell run source /Users/arrdem/Documents/work/aspect/rules_py/.examples+py_binary+py_binary.venv/bin/activate ```
1 parent 5ea06cb commit 22c308d

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

py/private/py_venv/link.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@
1515
virtualenv_name = os.path.basename(virtualenv_home)
1616
runfiles_dir = os.path.realpath(os.environ["RUNFILES_DIR"])
1717
builddir = os.path.realpath(os.environ["BUILD_WORKING_DIRECTORY"])
18-
19-
# Chop off the runfiles tree prefix
20-
virtualenv_path = virtualenv_home.lstrip(runfiles_dir).lstrip("/")
21-
# Chop off the repo name to get a repo-relative path
22-
virtualenv_path = virtualenv_path[virtualenv_path.find("/"):]
18+
target_package, target_name = os.environ["BAZEL_TARGET"].split("//", 1)[1].split(":")
2319

2420
PARSER = argparse.ArgumentParser(
2521
prog="link",
@@ -36,7 +32,7 @@
3632
PARSER.add_argument(
3733
"--dest",
3834
dest="dest",
39-
default=os.path.join(builddir, os.path.dirname(virtualenv_path)),
35+
default=os.path.join(builddir, target_package),
4036
help="Dir to link the virtualenv into",
4137
)
4238

0 commit comments

Comments
 (0)