Skip to content

Commit 14ed4c9

Browse files
committed
Add support for virtualenv in installer
Signed-off-by: Jose Enriquez <[email protected]>
1 parent ca90803 commit 14ed4c9

File tree

1 file changed

+36
-8
lines changed

1 file changed

+36
-8
lines changed

install.py

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,17 @@
88
"""
99
import argparse
1010
import os
11+
import platform
1112
import sys
1213
import shutil
1314
import subprocess
14-
import venv
15+
16+
USE_VIRTUALENV = False
17+
try:
18+
import venv
19+
except ImportError:
20+
USE_VIRTUALENV = True
21+
import virtualenv
1522

1623

1724
source_path = os.path.dirname(os.path.realpath(__file__))
@@ -27,15 +34,36 @@
2734
from rez.vendor.distlib.scripts import ScriptMaker # noqa: E402
2835

2936

30-
def create_virtual_environment(dest_dir):
31-
builder = venv.EnvBuilder(with_pip=True)
32-
builder.create(dest_dir)
37+
def create_virtual_environment(dest_dir: str) -> None:
38+
"""Create a virtual environment in the given directory.
39+
40+
Args:
41+
dest_dir (str): Full path to the virtual environment directory.
42+
43+
"""
44+
if USE_VIRTUALENV:
45+
try:
46+
subprocess.run(
47+
[sys.executable, "-m", "virtualenv", dest_dir],
48+
check=True
49+
)
50+
except subprocess.CalledProcessError as err:
51+
print(f"Failed to create virtual environment: {err}")
52+
sys.exit(1)
53+
else:
54+
builder = venv.EnvBuilder(with_pip=True)
55+
builder.create(dest_dir)
56+
57+
58+
def get_virtualenv_bin_dir(dest_dir: str) -> str:
59+
"""Get the bin directory of the virtual environment.
3360
61+
Args:
62+
dest_dir (str): The directory of the virtual environment.
3463
35-
def get_virtualenv_bin_dir(dest_dir):
36-
builder = venv.EnvBuilder()
37-
context = builder.ensure_directories(dest_dir)
38-
return context.bin_path
64+
"""
65+
bin_dir = "Scripts" if platform.system() == "Windows" else "bin"
66+
return os.path.join(dest_dir, bin_dir)
3967

4068

4169
def get_virtualenv_py_executable(dest_dir):

0 commit comments

Comments
 (0)