| 1 |
import os |
| 2 |
import runpy |
| 3 |
import sys |
| 4 |
from pathlib import Path |
| 5 |
|
| 6 |
deps_dir = Path(__file__).parent / "deps" |
| 7 |
if not deps_dir.exists(): |
| 8 |
deps_dir.mkdir() |
| 9 |
|
| 10 |
if not (deps_dir / "venvstarter.py").exists(): |
| 11 |
if "PIP_REQUIRE_VIRTUALENV" in os.environ: |
| 12 |
del os.environ["PIP_REQUIRE_VIRTUALENV"] |
| 13 |
os.system(f"{sys.executable} -m pip install venvstarter -t {deps_dir}") |
| 14 |
|
| 15 |
sys.path.append(str(deps_dir)) |
| 16 |
venvstarter_module = runpy.run_path(str(deps_dir / "venvstarter.py")) |
| 17 |
sys.path.pop() |
| 18 |
|
| 19 |
wanted_version = "0.12.2" |
| 20 |
|
| 21 |
upgrade = False |
| 22 |
VERSION = venvstarter_module.get("VERSION") |
| 23 |
if VERSION is None: |
| 24 |
upgrade = True |
| 25 |
else: |
| 26 |
Version = venvstarter_module["Version"] |
| 27 |
if Version(VERSION) != Version(wanted_version): |
| 28 |
upgrade = True |
| 29 |
|
| 30 |
if upgrade: |
| 31 |
os.system(f"{sys.executable} -m pip install -U 'venvstarter=={wanted_version}' -t {deps_dir}") |
| 32 |
|
| 33 |
manager = runpy.run_path(str(deps_dir / "venvstarter.py"))["manager"] |