diff --git a/py/private/py_venv.bzl b/py/private/py_venv.bzl index 691757d3..5ccd7c63 100644 --- a/py/private/py_venv.bzl +++ b/py/private/py_venv.bzl @@ -140,9 +140,12 @@ A collision can occour when multiple packages providing the same file are instal ) def py_venv(name, **kwargs): + # By default, VSCode (and likely other tools) expect to find virtualenv's in the root of the project opened in the editor. + # They also provide a nice name to see "which one is open" when discovered this way. + # 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 ) diff --git a/py/private/venv.tmpl.sh b/py/private/venv.tmpl.sh index d129a215..7eea08c5 100644 --- a/py/private/venv.tmpl.sh +++ b/py/private/venv.tmpl.sh @@ -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}" \ @@ -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}"