Open 2cf8c726-2f5e-4cfd-8f4b-e3206ac4cbce opened 7 years ago
Remove hard coded path in activate family of virtualenv scripts.
Currently, VIRTUAL_ENV is set hard coded. Event after --relocatable
Instead, change to have is defined dynamically:
E.g. bash:
called=$_ [[ $called != $0 ]] && fullpath="${BASH_SOURCE[@]}" || fullpath=$0 fullpath=$(readlink -f $fullpath) VIRTUAL_ENV=$(dirname $(dirname $fullpath))
E.g. tcsh:
set sourced=($_)
if ("$sourced" != "") then
set fullpath="$sourced[2]"
endif
if ("$0" != "tcsh") then
set fullpath="$0"
endif
set fullpath=readlink -f $fullpath
set binpath=dirname $fullpath
setenv VIRTUAL_ENV dirname $binpath
Additional information:
This suggestion will make pyenv much better.
To emphasize the need, there are many places that due to security you cannot build virtualenv. Rather you have to push a virtualenv with your python code. Often enough, you also don't have control on where the code will be stationed on the installation server. Hence the mobility of virtualenv is important for Python code to be migratable. Many times I find myself and other edit activate shell scripts correcting their path to a relative one.
In fact, virtualenv has --relocatable flag but it doesn't do anything to the batch and shell activate files. Python programs in Scripts, however, are already built with a relative path. There is no reason not to do that to the shell and batch programs.
The only thing is that there will need to be more particular shell activate scripts (tcsh, ksh, csh, etc) as they may have different characteristics for relativity.
Progress is not defined by how things are, but how they can be.
This seems reasonable, but scripts written to venvs by e.g. pip hard-code the path to the venv, and this is a stumbling block to relocatability. There is no reason to use the activate scripts except under interactive use - a script installed in a venv should be directly runnable from its bin directory, but that currently won't work if the venv is moved to a new location.
Outside of Python I maintain the distlib library which pip uses under the covers to write installed scripts, and I will try to consider a solution which solves the wider problem.
Thank you so much for considering this.
Both windows and linux based systems provides mechanisms to be dynamic and relative to the path.
I wish there would be a way to add such behavior to Python development manifesto and to check in pypi that packages are aligned
*Arnon Sela* 214-205-2151 \<%2B1-214-205-2151> arnon@acrisel.com www.acrisel.com
Notice: from Acrisel: If received in error, please destroy and notify sender, and make no further use, disclosure, or distribution. This email (including attachments) may contain information subject to confidentiality obligations, and sender does not waive confidentiality or privilege.
On Fri, Jul 14, 2017 at 6:14 PM, Vinay Sajip \report@bugs.python.org\ wrote:
Vinay Sajip added the comment:
This seems reasonable, but scripts written to venvs by e.g. pip hard-code the path to the venv, and this is a stumbling block to relocatability. There is no reason to use the activate scripts except under interactive use
- a script installed in a venv should be directly runnable from its bin directory, but that currently won't work if the venv is moved to a new location.
Outside of Python I maintain the distlib library which pip uses under the covers to write installed scripts, and I will try to consider a solution which solves the wider problem.
----------
Python tracker \report@bugs.python.org\ \http://bugs.python.org/issue30842\
This needs further thought as to how to implement. For example, readlink -f isn't supported on OS X. If a patch were available which works across platforms, that would potentially speed up resolution of this issue.
readlink -f can be replaced by the following sequence:
pushd $fullpath
fullpath=$(pwd -P)
popd
Please note that:
[[ $called != $0 ]] && fullpath="${BASH_SOURCE[@]}" || fullpath=$0
Should be replaced with:
[[ $called != $0 ]] && fullpath="${BASH_SOURCE[0]}" || fullpath=$0
0 instead of @ - that was a misspelling.
Note that the activate script currently also works with /bin/sh (using . venv-dir/bin/activate) but pushd and popd are not supported there, and introducing them would presumably break this script on /bin/sh.
The procedure:
pushd $fullpath
fullpath=$(pwd -P)
popd
Can be made sh (and other shells) friendly by:
here=$PWD # or $(pwd)
cd $fullpath
fullpath=$(pwd -P)
cd $here
More to write, but should work, right?
If no PR is forthcoming for this, I'd like to close this issue as out of date. Any objections?
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields: ```python assignee = None closed_at = None created_at =
labels = ['type-feature', '3.7']
title = 'pyenv activate for bash and tcsh'
updated_at =
user = 'https://bugs.python.org/PyAcrisel'
```
bugs.python.org fields:
```python
activity =
actor = 'vinay.sajip'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = []
creation =
creator = 'PyAcrisel'
dependencies = []
files = []
hgrepos = []
issue_num = 30842
keywords = []
message_count = 9.0
messages = ['297611', '298351', '298377', '298382', '299463', '299466', '299513', '299527', '376854']
nosy_count = 2.0
nosy_names = ['vinay.sajip', 'PyAcrisel']
pr_nums = []
priority = 'normal'
resolution = None
stage = 'needs patch'
status = 'open'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue30842'
versions = ['Python 3.7']
```