classification
Title: activate script created by venv is not smart enough
Type: Stage:
Components: Library (Lib) Versions: Python 3.10, Python 3.9, Python 3.8
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: eric.smith, kunaltyagi, vinay.sajip
Priority: normal Keywords:

Created on 2020-07-09 09:57 by kunaltyagi, last changed 2020-07-10 21:14 by eric.smith.

Messages (2)
msg373386 - (view) Author: (kunaltyagi) Date: 2020-07-09 09:57
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.
msg373485 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2020-07-10 21:14
Changing versions to those that are currently receiving support.
History
Date User Action Args
2020-07-10 21:14:55eric.smithsetnosy: + eric.smith

messages: + msg373485
versions: - Python 3.5, Python 3.6, Python 3.7
2020-07-09 10:08:04xtreaksetnosy: + vinay.sajip
2020-07-09 09:57:08kunaltyagicreate