finish ex0
This commit is contained in:
+37
-10
@@ -1,24 +1,51 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
import site
|
||||
import os
|
||||
|
||||
|
||||
def is_virtual_environment():
|
||||
return sys.prefix != sys.base_prefix
|
||||
|
||||
|
||||
def main():
|
||||
if not is_virtual_environment():
|
||||
|
||||
print("""NOT running in virtual environment.
|
||||
Create a virtual environment with:
|
||||
current_python = sys.executable
|
||||
|
||||
if is_virtual_environment():
|
||||
environment_path = sys.prefix
|
||||
venv_name = os.path.basename(environment_path)
|
||||
site_packages = site.getsitepackages()[0]
|
||||
print(rf"""
|
||||
LABORATORY STATUS: The laboratory is sealed
|
||||
|
||||
Current Python: {current_python}
|
||||
Virtual Environment: {venv_name}
|
||||
Environment Path: {environment_path}
|
||||
|
||||
SUCCESS: You are working in an isolated environment!
|
||||
Safe to install reagents without affecting
|
||||
the global system.
|
||||
|
||||
Reagent installation path:
|
||||
{site_packages}""")
|
||||
else:
|
||||
print(rf"""
|
||||
LABORATORY STATUS: You are working in the open
|
||||
|
||||
Current Python: {current_python}
|
||||
Virtual Environment: None detected
|
||||
|
||||
WARNING: You are in the global environment!
|
||||
Every reagent you install here leaks into the whole system.
|
||||
|
||||
To seal the laboratory, run:
|
||||
python3 -m venv lab_env
|
||||
source lab_env/bin/activate
|
||||
""")
|
||||
source lab_env/bin/activate # On Unix
|
||||
lab_env\Scripts\activate # On Windows
|
||||
Then run this program again.""")
|
||||
|
||||
return
|
||||
|
||||
print("""
|
||||
In virtual env :)
|
||||
""")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user