Skip to content

Commit

Permalink
refactor: py_venv macro improved defaults for usability
Browse files Browse the repository at this point in the history
After testing real developer workflows in vscode, this way works correctly and is much more practical.

Fixes #395
  • Loading branch information
alexeagle committed Oct 1, 2024
1 parent 7a9e4b2 commit e6c1c3d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 5 additions & 2 deletions py/private/py_venv.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,12 @@ A collision can occour when multiple packages providing the same file are instal
)

def py_venv(name, **kwargs):
# By default, support VSCode (and other tools) by creating virtualenv's in the root of the workspace.
# Editors expect to locate them here, and provide a nice name to see "which one is open".
# See https://github.com/aspect-build/rules_py/issues/395
default_venv_name = ".{}".format(paths.join(native.package_name(), name).replace("/", "+"))
_py_venv(
name = name,
location = kwargs.pop("location", native.package_name()),
venv_name = kwargs.pop("venv_name", ".{}".format(name)),
venv_name = kwargs.pop("venv_name", default_venv_name),
**kwargs
)
4 changes: 3 additions & 1 deletion py/private/venv.tmpl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function alocation {
}

VENV_TOOL="$(rlocation {{VENV_TOOL}})"
VENV_ROOT="${BUILD_WORKSPACE_DIRECTORY}"
VENV_ROOT="${BUILD_WORKING_DIRECTORY}"
VIRTUAL_ENV="$(alocation "${VENV_ROOT}/{{ARG_VENV_LOCATION}}")"

"${VENV_TOOL}" \
Expand All @@ -31,3 +31,5 @@ VIRTUAL_ENV="$(alocation "${VENV_ROOT}/{{ARG_VENV_LOCATION}}")"
--pth-file "$(rlocation {{ARG_PTH_FILE}})" \
--pth-entry-prefix "${RUNFILES_DIR}" \
--collision-strategy "{{ARG_COLLISION_STRATEGY}}"

echo "Created virtualenv in ${VIRTUAL_ENV}"

0 comments on commit e6c1c3d

Please sign in to comment.