Skip to content

Commit

Permalink
Add support for virtualenv in installer
Browse files Browse the repository at this point in the history
Signed-off-by: Jose Enriquez <[email protected]>
  • Loading branch information
Pixel-Minions committed Feb 14, 2024
1 parent ca90803 commit 14ed4c9
Showing 1 changed file with 36 additions and 8 deletions.
44 changes: 36 additions & 8 deletions install.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,17 @@
"""
import argparse
import os
import platform
import sys
import shutil
import subprocess
import venv

USE_VIRTUALENV = False
try:
import venv
except ImportError:
USE_VIRTUALENV = True
import virtualenv


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


def create_virtual_environment(dest_dir):
builder = venv.EnvBuilder(with_pip=True)
builder.create(dest_dir)
def create_virtual_environment(dest_dir: str) -> None:
"""Create a virtual environment in the given directory.
Args:
dest_dir (str): Full path to the virtual environment directory.
"""
if USE_VIRTUALENV:
try:
subprocess.run(
[sys.executable, "-m", "virtualenv", dest_dir],
check=True
)
except subprocess.CalledProcessError as err:
print(f"Failed to create virtual environment: {err}")
sys.exit(1)
else:
builder = venv.EnvBuilder(with_pip=True)
builder.create(dest_dir)


def get_virtualenv_bin_dir(dest_dir: str) -> str:
"""Get the bin directory of the virtual environment.
Args:
dest_dir (str): The directory of the virtual environment.
def get_virtualenv_bin_dir(dest_dir):
builder = venv.EnvBuilder()
context = builder.ensure_directories(dest_dir)
return context.bin_path
"""
bin_dir = "Scripts" if platform.system() == "Windows" else "bin"
return os.path.join(dest_dir, bin_dir)


def get_virtualenv_py_executable(dest_dir):
Expand Down

0 comments on commit 14ed4c9

Please sign in to comment.