New submission from kunaltyagi <kunal.tyagi.3.1...@gmail.com>:

TLDR: `activate` script should be able to:
* inform user if it has been run and not sourced
* act as a placeholder to detect the shell being used and source the necessary 
`activate.{SHELL}` instead of throwing an error

---
It's mildly infuriating that `activate` on different setups needs to be called 
differently. The lack of messages when it's not sourced is also beginner 
unfriendly.

Both the issues are relatively easy to fix. First, making it shell agnostic. We 
can move the contents of `activate` to `activate.sh` and change `activate` to 
contain code like:
```sh
[ $FISH_VERSION ] && . activate.fish
[ $BASH_VERSION ] && . activate.sh
...
```

This of course will fail hard when you try to `. <venv_location>/bin/activate`. 
Finding the path of the file is not trivial, but doable. If we assume `dirname` 
is not present on the system, we can use `<full_path>/activate.<SHELL>`.

Making the "sourced or ran" logic shell agnostic is slightly easier to 
accomplish due to `$_`, `$0`, `$BASH_SOURCE`.

It'll possibly take a non-trivial amount of code to accomplish something this 
trivial, but it'll save people with custom shells 3 keystrokes and make the 
workflow smoother.

----------
components: Library (Lib)
messages: 373386
nosy: kunaltyagi
priority: normal
severity: normal
status: open
title: activate script created by venv is not smart enough
versions: Python 3.10, Python 3.5, Python 3.6, Python 3.7, Python 3.8, Python 
3.9

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue41256>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to