Repository: zulip/zulip

Issue:
Don't activate zulip_py3_venv at the launch of shell on direct system dev setups.
As a part of `./tools/provision` we add `"source " + os.path.join(VENV_PATH, "bin", "activate")` to the bash profile of the user which is responsible for automatic activation of the zulip's virtualenv when a new shell is launched.

While this is handy for Vagrant/Docker/Droplet setups, which are dedicated machines for running Zulip, this is not a desired behaviour in other setups like [Direct Installation on systems](https://zulip.readthedocs.io/en/latest/development/setup-advanced.html#installing-directly-on-ubuntu-debian-centos-or-fedora).

Solution would be to extract the script which writes the venv activation to bash profile and call it via Vagrantfile/Dockerfile/Droplet setup script.


Discussion:
Hello @zulip/server-development members, this issue was labeled with the "area: provision" label, so you may want to check it out!

<!-- areaLabelAddition -->
@zulipbot claim
Welcome to Zulip, @HausCloud! We just sent you an invite to collaborate on this repository at https://github.com/zulip/zulip/invitations. Please accept this invite in order to claim this issue and begin a fun, rewarding experience contributing to Zulip!

Here's some tips to get you off to a good start:
* Join me on the [Zulip developers' server](https://chat.zulip.org), to get help, chat about this issue, and meet the other developers.
* [Unwatch this repository](https://help.github.com/articles/unwatching-repositories/), so that you don't get 100 emails a day.

As you work on this issue, you'll also want to refer to the [Zulip code contribution guide](https://zulip.readthedocs.io/en/latest/contributing/index.html), as well as the rest of the developer documentation on that site.

See you on the other side (that is, the pull request side)!
@zulipbot claim
Hello @Krishna-Sivakumar, you have been unassigned from this issue because you have not updated this issue or any referenced pull requests for over 14 days.

You can reclaim this issue or claim any other issue by commenting `@zulipbot claim` on that issue.

Thanks for your contributions, and hope to see you again soon!
@zulipbot abandon

@zulipbot claim
Welcome to Zulip, @Krishna-Sivakumar! We just sent you an invite to collaborate on this repository at https://github.com/zulip/zulip/invitations. Please accept this invite in order to claim this issue and begin a fun, rewarding experience contributing to Zulip!

Here's some tips to get you off to a good start:
* Join me on the [Zulip developers' server](https://chat.zulip.org), to get help, chat about this issue, and meet the other developers.
* [Unwatch this repository](https://help.github.com/articles/unwatching-repositories/), so that you don't get 100 emails a day.

As you work on this issue, you'll also want to refer to the [Zulip code contribution guide](https://zulip.readthedocs.io/en/latest/contributing/index.html), as well as the rest of the developer documentation on that site.

See you on the other side (that is, the pull request side)!
Can you take a look at this? @amanagr 
@zulipbot claim
Hello @Krishna-Sivakumar, you have been unassigned from this issue because you have not updated this issue or any referenced pull requests for over 14 days.

You can reclaim this issue or claim any other issue by commenting `@zulipbot claim` on that issue.

Thanks for your contributions, and hope to see you again soon!
@zulipbot claim
Welcome to Zulip, @Purhan! We just sent you an invite to collaborate on this repository at https://github.com/zulip/zulip/invitations. Please accept this invite in order to claim this issue and begin a fun, rewarding experience contributing to Zulip!

Here's some tips to get you off to a good start:
* Join me on the [Zulip developers' server](https://chat.zulip.org), to get help, chat about this issue, and meet the other developers.
* [Unwatch this repository](https://help.github.com/articles/unwatching-repositories/), so that you don't get 100 emails a day.

As you work on this issue, you'll also want to refer to the [Zulip code contribution guide](https://zulip.readthedocs.io/en/latest/contributing/index.html), as well as the rest of the developer documentation on that site.

See you on the other side (that is, the pull request side)!
@Krishna-Sivakumar I just noticed you have an open PR. Are you still working on this? If so, please tell me and I will drop this issue. Didn't see that before claiming it.
> @Krishna-Sivakumar I just noticed you have an open PR. Are you still working on this? If so, please tell me and I will drop this issue. Didn't see that before claiming it.

nope, I'm not working on it anymore. Please go ahead.
@berniev9 You have been unassigned from this issue because you have not made any updates for over 14 days. Please feel free to reclaim the issue if you decide to pick up again. Thanks!

@zulipbot abandon
@zulipbot claim
Welcome to Zulip, @skamranahmed! We just sent you an invite to collaborate on this repository at https://github.com/zulip/zulip/invitations. Please accept this invite in order to claim this issue and begin a fun, rewarding experience contributing to Zulip!

Here's some tips to get you off to a good start:
* Join me on the [Zulip developers' server](https://chat.zulip.org), to get help, chat about this issue, and meet the other developers.
* [Unwatch this repository](https://help.github.com/articles/unwatching-repositories/), so that you don't get 100 emails a day.

As you work on this issue, you'll also want to refer to the [Zulip code contribution guide](https://zulip.readthedocs.io/en/latest/contributing/index.html), as well as the rest of the developer documentation on that site.

See you on the other side (that is, the pull request side)!
@zulipbot claim
Hello @Abhirup-99, it looks like you've currently claimed 1 issue in this repository. We encourage new contributors to focus their efforts on at most 1 issue at a time, so please complete your work on your other claimed issues before trying to claim this issue again.

We look forward to your valuable contributions!
@zulipbot claim
@zulipbot claim

@zulipbot claim
@zulipbot claim
@zulipbot claim
Welcome to Zulip, @daniellf99! We just sent you an invite to collaborate on this repository at https://github.com/zulip/zulip/invitations. Please accept this invite in order to claim this issue and begin a fun, rewarding experience contributing to Zulip!

Here's some tips to get you off to a good start:
* Join me on the [Zulip developers' server](https://chat.zulip.org), to get help, chat about this issue, and meet the other developers.
* [Unwatch this repository](https://help.github.com/articles/unwatching-repositories/), so that you don't get 100 emails a day.

As you work on this issue, you'll also want to refer to the [Zulip code contribution guide](https://zulip.readthedocs.io/en/latest/contributing/index.html), as well as the rest of the developer documentation on that site.

See you on the other side (that is, the pull request side)!
@amanagr I was thinking if maybe we could add an option to `./tools/provision` like `--no-bash-profile` to prevent the script from writing to the bash profile.

That way the user could choose what works best for him, while the Vagrantfile/Dockerfile/Droplet setup script just continues working the way it is.
This is actually a good idea. We just need to document it properly in https://zulip.readthedocs.io/en/latest/development/setup-advanced.html alteast after adding it. 
Will do, thanks for the advice!
@zulipbot claim
Hello @gvarun1, it looks like you've currently claimed 1 issue in this repository. We encourage new contributors to focus their efforts on at most 1 issue at a time, so please complete your work on your other claimed issues before trying to claim this issue again.

We look forward to your valuable contributions!
@zulipbot claim
@zulipbot  abandon 
@amanagr is this issue still relevant? I cannot see the discussed points in /tools/provision. If you could point out what needs to be done for this issue, i might try it :)
@zulipbot claim
@amanagr  This issue of automatic activation of zulip-py3-venv also applies to WSL2 setup on a Windows 10 or 11 machine. So, as you suggested, this should be only for machines that are dedicated to running Zulip and avoid automatic activation for other setups. I was looking through this **tools/setup/setup_venvs.py** file, and I figured what if we could add a condition that checks for what kind of container this is? We would only execute this script (making the assumption that this is the script that runs automatically when we enter the shell) for vagrant, docker, and droplet machines and ignore other machines. If I'm right, that will solve the problem. I don't have the whole picture, but if you could push me a bit in the right direction, that would be a great help. I can then claim this issue. Thanks.  
@zulipbot claim
Welcome to Zulip, @s-bose7! We just sent you an invite to collaborate on this repository at https://github.com/zulip/zulip/invitations. Please accept this invite in order to claim this issue and begin a fun, rewarding experience contributing to Zulip!

Here's some tips to get you off to a good start:

- Join me on the [Zulip developers' server](https://chat.zulip.org), to get help, chat about this issue, and meet the other developers.
- [Unwatch this repository](https://help.github.com/articles/unwatching-repositories/), so that you don't get 100 emails a day.

As you work on this issue, you'll also want to refer to the [Zulip code contribution guide](https://zulip.readthedocs.io/en/latest/contributing/index.html), as well as the rest of the developer documentation on that site.

See you on the other side (that is, the pull request side)!


Resolving patch:
diff --git a/tools/lib/provision_inner.py b/tools/lib/provision_inner.py
--- a/tools/lib/provision_inner.py
+++ b/tools/lib/provision_inner.py
@@ -93,8 +93,16 @@ def write_command(command: str) -> None:
             with open(shell_profile_path, "w") as shell_profile_file:
                 shell_profile_file.writelines(command + "\n")
 
-    source_activate_command = "source " + os.path.join(VENV_PATH, "bin", "activate")
-    write_command(source_activate_command)
+    # Check if the environment is one of the dedicated containers: Vagrant, Docker, Droplet or WSL2
+    WSL = os.path.exists("/proc/sys/fs/binfmt_misc/WSLInterop")
+    vagrant = os.path.exists("/vagrant")
+    docker = os.path.exists("/var/run/docker.sock")
+    droplet = os.path.exists("/etc/digitalocean")
+    # If the environment matches one of the containers, write the activation command to the user's bash profile
+    if WSL or vagrant or docker or droplet:
+        source_activate_command = "source " + os.path.join(VENV_PATH, "bin", "activate")
+        write_command(source_activate_command)
+
     if os.path.exists("/srv/zulip"):
         write_command("cd /srv/zulip")
 


Test patch: