classification
Title: pyenv activate for bash and tcsh
Type: enhancement Stage:
Components: Versions: Python 3.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: PyAcrisel, vinay.sajip
Priority: normal Keywords:

Created on 2017-07-03 19:36 by PyAcrisel, last changed 2017-07-15 04:28 by PyAcrisel.

Messages (4)
msg297611 - (view) Author: Arnon Sela (PyAcrisel) Date: 2017-07-03 19:36
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`
msg298351 - (view) Author: Arnon Sela (PyAcrisel) Date: 2017-07-14 12:33
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.
msg298377 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2017-07-14 23:14
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.
msg298382 - (view) Author: Arnon Sela (PyAcrisel) Date: 2017-07-15 04:28
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

IT Solutions and Ab Initio Experts
--
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>
> _______________________________________
>
History
Date User Action Args
2017-07-15 04:28:48PyAcriselsetmessages: + msg298382
2017-07-14 23:14:10vinay.sajipsetmessages: + msg298377
2017-07-14 12:33:52PyAcriselsetmessages: + msg298351
versions: + Python 3.7, - Python 3.5
2017-07-03 22:07:36ned.deilysetnosy: + vinay.sajip
2017-07-03 19:36:47PyAcriselcreate