Spaces:
No application file
No application file
Download setup_tools/venv.py from mrtroydev/audio-webui: direct link, hf CLI and curl.
- Browser
- Download file 1.14 kB
-
https://huggingface.co/spaces/mrtroydev/audio-webui/resolve/main/setup_tools/venv.py
- Command line
-
hf download hf://spaces/mrtroydev/audio-webui/setup_tools/venv.py
-
curl -L -o venv.py https://huggingface.co/spaces/mrtroydev/audio-webui/resolve/main/setup_tools/venv.py
1.14 kB
| import sys | |
| from .commands import run_command, get_python | |
| from .os import is_windows | |
| import os | |
| venv_name = 'venv' | |
| venv_activate_path = f'{venv_name}/' + ('Scripts/activate.bat' if is_windows() else 'bin/activate') | |
| def get_base_prefix_compat(): | |
| """Get base/real prefix, or sys.prefix if there is none.""" | |
| return getattr(sys, "base_prefix", None) or getattr(sys, "real_prefix", None) or sys.prefix | |
| def in_venv(): | |
| in_conda = os.environ.get('CONDA_PREFIX') is not None | |
| return (get_base_prefix_compat() != sys.prefix) or in_conda | |
| def activate_venv(): | |
| if in_venv(): | |
| return | |
| if not os.path.isdir(venv_name): | |
| print('no venv found, creating venv') | |
| run_command(f'"{get_python()}"', '-m venv venv') | |
| run_command([('call' if is_windows() else 'source', venv_activate_path), ('python', ' '.join([f'"{arg}"' for arg in sys.argv]))]) # Launch the main.py with the venv | |
| exit() # Exit after the venv'ed version exits (maximum depth will be 2 because the venv is already activated in that case) | |
| def ensure_venv(): | |
| if not in_venv(): | |
| print('activating venv') | |
| activate_venv() | |