From 14ed4c94da2040abee99100d483eecd5032cbe7a Mon Sep 17 00:00:00 2001 From: Jose Enriquez Date: Wed, 14 Feb 2024 14:44:59 -0500 Subject: [PATCH 1/2] Add support for virtualenv in installer Signed-off-by: Jose Enriquez --- install.py | 44 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/install.py b/install.py index 78bff3550..43b7c81cc 100644 --- a/install.py +++ b/install.py @@ -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__)) @@ -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): From b0bc067083ef68a7f91bad16ecdb9e889e0fa002 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Morin Date: Fri, 16 Feb 2024 16:28:46 -0500 Subject: [PATCH 2/2] Run workflows when install script is modified Signed-off-by: Jean-Christophe Morin --- .github/workflows/installation.yaml | 8 ++++++++ .github/workflows/tests.yaml | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/.github/workflows/installation.yaml b/.github/workflows/installation.yaml index 6d635d9fb..0a2425fcf 100644 --- a/.github/workflows/installation.yaml +++ b/.github/workflows/installation.yaml @@ -3,12 +3,20 @@ on: pull_request: paths: - 'src/**' + - 'install.py' + - 'setup.py' + - 'MANIFEST.in' + - 'pyproject.toml' - '.github/workflows/installation.yaml' - '!src/rez/utils/_version.py' - '!**.md' push: paths: - 'src/**' + - 'install.py' + - 'setup.py' + - 'MANIFEST.in' + - 'pyproject.toml' - '.github/workflows/installation.yaml' - '!src/rez/utils/_version.py' - '!**.md' diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index dc4fc0f0b..097c56be1 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -3,12 +3,20 @@ on: pull_request: paths: - 'src/**' + - 'install.py' + - 'setup.py' + - 'MANIFEST.in' + - 'pyproject.toml' - '.github/workflows/tests.yaml' - '!src/rez/utils/_version.py' - '!**.md' push: paths: - 'src/**' + - 'install.py' + - 'setup.py' + - 'MANIFEST.in' + - 'pyproject.toml' - '.github/workflows/tests.yaml' - '!src/rez/utils/_version.py' - '!**.md'