-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamically generate VIRTUAL_ENV environment variable #1166
Comments
moving a virtualenv is generally not a supported operation as the shebangs ( that said, I had a usecase for almost exactly what's desired here as I'm managing virtualenvs inside I used this chunk of code to accomplish what I wanted: def _fixup_activate_file(filename: str, replacement: str) -> None:
dest = os.path.join(target, 'bin', filename)
backup = f'{dest}.old'
os.rename(dest, backup)
with open(backup) as f:
contents = f.read()
with open(dest, 'w') as f:
f.write(contents.replace(f'"{target}"', replacement))
# make relocatable activate files
_fixup_activate_file(
'activate',
# bash / zsh (sh not supported, is this ok?)
'"$(cd "$(dirname "$(dirname "${BASH_SOURCE:0}")")"; pwd)"',
)
_fixup_activate_file(
'activate.fish',
"(bash -c 'cd '(dirname (dirname (status --current-filename)))'; pwd')", # noqa: E501
) note that this doesn't work for |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Just add a comment if you want to keep it open. Thank you for your contributions. |
We no longer support the relocate-able flag, so this is now out of scope too. |
Currently, the
VIRTUAL_ENV
environment variable inactivate
script will be generated when virtual environment is created.However, if we change the name of the folder. It would not work.
Isn't it better to generate VIRTUAL_ENV variable dynamically using the path of the activate script ?
Maybe I am wrong, but based on my understanding, the activate script is a bash script and we can get the path of this script using mechanism similar to
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
.The text was updated successfully, but these errors were encountered: