62 lines
1.6 kB
1import sys
2import os
3import site
4
5
6def in_venv() -> bool:
7 return sys.prefix != sys.base_prefix
8
9
10def show_py(in_venv: bool, venv_name: str) -> None:
11 print(f"Current Python: {sys.executable}")
12 print(
13 "Virtual Environment:",
14 venv_name + "\nEnvironment Path: " + sys.prefix
15 if in_venv else "None detected"
16 )
17 print()
18
19
20def show_msg(in_venv: bool) -> None:
21 if in_venv:
22 print("SUCCESS: You're in an isolated environment!")
23 print(
24 "Safe to install packages without affecting the global system.\n"
25 )
26 else:
27 print("WARNING: You're in the global environment!")
28 print("The machines can see everything you install.")
29 print("\nTo enter the construct run:")
30 print("python -m venv matrix_env")
31 print("source matrix_env/bin/activate # On Unix")
32 print("matrix_env/Scripts/activate # On Windows")
33 print("\nThen run this program again.")
34
35
36def show_pkgs(in_venv: bool, venv_name: str) -> None:
37 if in_venv:
38 sp = None
39 for p in site.getsitepackages():
40 if venv_name in p:
41 sp = p
42 break
43 print("Package installation path:\n", sp)
44
45
46def main() -> None:
47 venv_name = os.path.basename(sys.prefix)
48 is_in_venv = in_venv()
49
50 print(
51 "\nMATRIX STATUS:",
52 "Welcome to the construct" if is_in_venv
53 else "You're still plugged in"
54 )
55 print()
56 show_py(is_in_venv, venv_name)
57 show_msg(is_in_venv)
58 show_pkgs(is_in_venv, venv_name)
59
60
61if __name__ == "__main__":
62 main()