Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for virtualenv in installer #1645

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/installation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
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