Last active
October 4, 2023 23:14
-
-
Save Jawabiscuit/325ccb60db155690f7be4aaa2a3cc2f4 to your computer and use it in GitHub Desktop.
Install or update rez on windows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
Install/Update Rez | |
Requirements: | |
Python2 | |
Example: | |
# Install rez | |
Install-Rez | |
# Bind packages locally | |
rez bind package | |
rez bind os | |
rez bind rez | |
# Release packages | |
rez bind -r package | |
rez bind -r os | |
rez bind -r rez | |
#> | |
Write-Host "Installing and configuring rez..." -ForegroundColor Green | |
git clone --depth 1 --branch "master" "https://github.com/nerdvegas/rez.git" "$env:TEMP\rez" | |
Set-Item "env:\PATH" "C:\Python27;C:\Python27\Scripts;$env:PATH" | |
if ([Environment]::GetEnvironmentVariable("PYTHONIOENCODING", "Machine").Count -eq "0") { | |
[Environment]::SetEnvironmentVariable("PYTHONIOENCODING", "UTF-8", "Machine") | |
} | |
python "$env:TEMP\rez\install.py" -v "C:\rez" | |
Set-Item "env:\PATH" "C:\rez\Scripts\rez;$env:PATH" | |
if ([Environment]::GetEnvironmentVariable("PYTHONPATH", "User").Count -eq "0") { | |
[Environment]::SetEnvironmentVariable("PYTHONPATH", "C:\rez\lib\site-packages", "User") | |
} else { | |
[Environment]::SetEnvironmentVariable("PYTHONPATH", "C:\rez\lib\site-packages;$env:PYTHONPATH", "User") | |
} | |
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue "$env:TEMP\rez" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
Production install for Rez development | |
Requirements: | |
- Machine configuration | |
- Setup for development with developer priviledges | |
- Install dotfiles | |
- rezconfig | |
- symlink creation in login shells | |
#> | |
Write-Host "Installing and configuring rez..." -ForegroundColor Green | |
# Python | |
Set-Item "env:\PATH" "C:\Python27;C:\Python27\Scripts;$env:PATH" | |
# Clone Rez | |
git clone --depth 1 --branch master "https://github.com/AcademySoftwareFoundation/rez.git" "$env:USERPROFILE\src\rez" | |
# Create editable install | |
python "$env:USERPROFILE\src\rez\install.py" -v -e "$env:SYSTEMDRIVE\rez" | |
<# | |
Environment | |
Commentary: | |
- Sets machine environment variables if they don't exist | |
- Prepends to *PATH if it already has a value | |
Actions: | |
1. Enforces python to use utf-8 encoding (for python 2) | |
2. Prevent python from writing out pyc files | |
3. Sets the default shell to gitbash | |
4. Puts rez executables on PATH | |
5. Puts rez python on PYTHONPATH | |
#> | |
if ([Environment]::GetEnvironmentVariable("PYTHONIOENCODING", "Machine").Count -eq "0") { | |
[Environment]::SetEnvironmentVariable("PYTHONIOENCODING", "UTF-8", "Machine") | |
} | |
if ([Environment]::GetEnvironmentVariable("PYTHONDONTWRITEBYTECODE", "Machine").Count -eq "0") { | |
[Environment]::SetEnvironmentVariable("PYTHONDONTWRITEBYTECODE", "1", "Machine") | |
} | |
if ([Environment]::GetEnvironmentVariable("SHELL", "Machine").Count -eq "0") { | |
[Environment]::SetEnvironmentVariable("SHELL", "$env:PROGRAMFILES\Git\bin\bash.exe", "Machine") | |
} | |
if ([Environment]::GetEnvironmentVariable("PATH", "User").Count -eq "0") { | |
[Environment]::SetEnvironmentVariable("PATH", "C:\rez\Scripts\rez", "User") | |
} else { | |
$user_path = [Environment]::GetEnvironmentVariable("PATH", "User") | |
[Environment]::SetEnvironmentVariable("PATH", "C:\rez\Scripts\rez;$user_path", "User") | |
} | |
if ([Environment]::GetEnvironmentVariable("PYTHONPATH", "User").Count -eq "0") { | |
[Environment]::SetEnvironmentVariable("PYTHONPATH", "C:\rez\lib\site-packages", "User") | |
} else { | |
[Environment]::SetEnvironmentVariable("PYTHONPATH", "C:\rez\lib\site-packages;$env:PYTHONPATH", "User") | |
} | |
<# | |
Manual Steps | |
1. completion script can be symlinked to the home dir from C:\Users\jsparrow\src\rez_venv\src\rez\src\rez\completion | |
bash -c -l "ln -s /c/Users/jsparrow/src/rez_venv/src/rez/src/rez/completion/completion /c/rez/completion" | |
2. rezconfig.py needs to be edited here: c:\users\jsparrow\src\rez_venv\src\rez\src\rez\rezconfig.py | |
- change platform_map value to | |
platform_map = { | |
"os": { | |
r"windows-(\d+)(\..*)": r"Windows-\1" | |
}, | |
"arch": { | |
"AMD64": "x86_64", | |
}, | |
} | |
3. rez bind os to automatically bind arch, os, and platform | |
- rez bind os | |
- rez bind -r os | |
Next Steps | |
1. Update to the latest rez from git | |
2. Rez Changes | |
- See if the following changes are still relevant | |
- rez/resolved_context.py | |
executor_path = executor.env.PATH.value() | |
executor_path = re.sub(r'([a-zA-Z]):\\', r'/\g<1>/', executor_path) | |
executor_path = executor_path.replace('\\', '/') | |
executor_path = executor_path.replace(';', ':') | |
executor.env.PATH = executor_path | |
- rezplugins/shell/bash.sh | |
def register_plugin(): | |
return Bash | |
#> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# install_rez_dev.sh - Create an editable install of rez | |
# | |
# Help: | |
# | |
# Pip Documentation | |
# https://pip.pypa.io/en/stable/cli/pip_install/?highlight=editable#editable-installs | |
# | |
# Slack Discussion | |
# https://academysoftwarefdn.slack.com/archives/C0321B828FM/p1649259168023869 | |
# | |
# | |
# Virtualenv | |
# | |
[[ ! -f ~/.mybashrc ]] && touch ~/.mybashrc | |
# TODO: Detect virtualenv installation | |
# python -m pip install --no-input --disable-pip-version-check --no-warn-script-location --user virtualenv | |
# TODO: Detect system python, find or error | |
# virtualenv path | |
echo -e "export PATH=$(cygpath -u "${APPDATA}")/Python/Python310/Scripts:${PATH}\n" >> "${HOME}/.mybashrc" | |
. "${HOME}/.mybashrc" | |
# | |
# Rez editable production install | |
# | |
[[ ! -d ~/src ]] && echo "src directory does not exist" | |
cd ~/src || exit | |
# Create virtualenv | |
virtualenv rez_venv | |
# Activate | |
. rez_venv/Scripts/activate | |
# Editable install (Method 1) | |
# TODO: This should work once rez has a command line flag for creating an editable install | |
# | |
# python -m pip install --no-input --disable-pip-version-check -e "git+https://github.com/Jawabiscuit/rez.git@production-editable-install#egg=rez" | |
# python -m pip install --no-input --disable-pip-version-check -e ~/src/rez-2.111.2/install.py | |
# | |
# Editable install (Method 2) | |
# Download or clone from official rez repo | |
# git clone --depth 1 --branch master "https://github.com/AcademySoftwareFoundation/rez.git" "$env:USERPROFILE/src/rez" | |
# | |
# TODO: Automate the patching process before proceeding to finish automating the installation process | |
# | |
# Follow this guide or manual steps below: https://gist.github.com/Jawabiscuit/523b0d860a86304be0392f7cf9361975 | |
# | |
# Install | |
# | |
# Manual Steps | |
# 1. Edit install.py | |
# - Insert "-e," into `run_command([py_executable, "m", "pip", "install", "-e", "."])` | |
# 2. python rez/install.py -v /c/rez | |
# 3. completion script can be symlinked to the home dir from C:/Users/%USERNAME%/src/rez_venv/src/rez/src/rez/completion | |
# - `bash -c -l "ln -s /c/Users/%USERNAME%/src/rez_venv/src/rez/src/rez/completion/completion /c/rez/completion"` | |
# 4. If not using Method bootstrap, rezconfig.py needs to be edited here: c:/users/%USERNAME%/src/rez_venv/src/rez/src/rez/rezconfig.py | |
# - change platform_map value to | |
# | |
# platform_map = { | |
# "os": { | |
# r"windows-(/d+)(/..*)": r"Windows-/1" | |
# }, | |
# "arch": { | |
# "AMD64": "x86_64", | |
# }, | |
# } | |
# | |
# 5. rez bind os to automatically bind arch, os, and platform | |
# - rez bind os | |
# - rez bind -r os | |
# | |
# Rez env rc (TODO: Check for an external .env file) | |
# | |
echo "" >> ~/.mybashrc | |
echo "# Rez environment" >> ~/.mybashrc | |
# Rez production install path | |
echo "export PATH=/c/rez/Scripts/rez:${PATH}" >> ~/.mybashrc | |
# Rez production install python paths | |
echo "export PYTHONPATH=/c/rez/Lib/site-packages:/c/rez/Scripts" >> ~/.mybashrc | |
# Shell completion | |
echo "`cygpath -p "${USERPROFILE}"`/src/rez/src/rez/completion/complete.sh" >> ~/.mybashrc | |
# Keep temporary rxt files around for debugging purposes (change to 1 after running) | |
echo "export REZ_KEEP_TMPDIRS=0" >> ~/.mybashrc | |
# Source bash rc | |
. ~/.mybashrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
Set-RezAndPy2-EnvVariables.ps1 | |
Important: Run in an elevated shell | |
Commentary: | |
- Sets machine environment variables if they don't exist | |
- Prepends to *PATH if it already has a value | |
and the path does not exist in the value list | |
Actions: | |
1. Prevents python from writing out pyc files | |
2. Sets python IO encoding to utf-8 (only needed for python 2) | |
3. Sets the default shell to gitbash | |
4. Puts rez executables on PATH | |
5. Puts rez python on PYTHONPATH | |
Todo: Add python install paths to User/System PATH and PYTHONPATH env vars | |
PATH | |
1. C:\Python27 | |
2. C:\Python27\Scripts | |
3. C:\Python39 | |
4. C:\Python39\Scripts | |
5. C:\Python39\Lib Maybe? | |
PYTHONPATH | |
1. C:\Python39\Lib\site-packages | |
#> | |
[Environment]::SetEnvironmentVariable("PYTHONDONTWRITEBYTECODE", "1", "Machine") | |
[Environment]::SetEnvironmentVariable("PYTHONIOENCODING", "UTF-8", "Machine") | |
[Environment]::SetEnvironmentVariable("SHELL", "$env:PROGRAMFILES\Git\bin\bash.exe", "Machine") | |
# TODO: Create function to reduce code duplication | |
if ([Environment]::GetEnvironmentVariable("PATH", "User").Count -ne "0") { | |
if ([Environment]::GetEnvironmentVariable("PATH", "User") -eq "") { | |
[Environment]::SetEnvironmentVariable("PATH", "C:\rez\Scripts\rez", "User") | |
} elseif ([Environment]::GetEnvironmentVariable("PATH", "User").Split(";").Count -eq "1") { | |
$user_path = [Environment]::GetEnvironmentVariable("PATH", "User") | |
if (-not ("C:\rez\Scripts\rez" -in ($user_path.Split(";")))) { | |
[Environment]::SetEnvironmentVariable("PATH", "C:\rez\Scripts\rez;$user_path", "User") | |
} | |
} | |
} else { | |
[Environment]::SetEnvironmentVariable("PATH", "C:\rez\Scripts\rez", "User") | |
} | |
if ([Environment]::GetEnvironmentVariable("PYTHONPATH", "User").Count -ne "0") { | |
if ([Environment]::GetEnvironmentVariable("PYTHONPATH", "User") -eq "") { | |
[Environment]::SetEnvironmentVariable("PYTHONPATH", "C:\rez\lib\site-packages", "User") | |
} elseif ([Environment]::GetEnvironmentVariable("PYTHONPATH", "User").Split(";").Count -eq "1") { | |
$user_path = [Environment]::GetEnvironmentVariable("PYTHONPATH", "User") | |
if (-not ("C:\rez\lib\site-packages" -in ($user_path.Split(";")))) { | |
[Environment]::SetEnvironmentVariable("PATH", "C:\rez\lib\site-packages;$user_path", "User") | |
} | |
} | |
} else { | |
[Environment]::SetEnvironmentVariable("PATH", "C:\rez\lib\site-packages", "User") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
Set-RezAndPy3-EnvVariables.ps1 | |
Important: Run in an elevated shell | |
Commentary: | |
- Sets machine environment variables if they don't exist | |
- Prepends to *PATH if it already has a value | |
and the path does not exist in the value list | |
Actions: | |
1. Prevents python from writing out pyc files | |
2. Sets the default shell to gitbash | |
3. Puts rez executables on PATH | |
4. Puts rez python on PYTHONPATH | |
Todo: Add python install paths to User/System PATH and PYTHONPATH env vars | |
PATH | |
1. C:\Python27 | |
2. C:\Python27\Scripts | |
3. C:\Python39 | |
4. C:\Python39\Scripts | |
5. C:\Python39\Lib Maybe? | |
PYTHONPATH | |
1. C:\Python39\Lib\site-packages | |
#> | |
[Environment]::SetEnvironmentVariable("PYTHONDONTWRITEBYTECODE", "1", "Machine") | |
[Environment]::SetEnvironmentVariable("SHELL", "$env:PROGRAMFILES\Git\bin\bash.exe", "Machine") | |
# TODO: Create function to reduce code duplication | |
if ([Environment]::GetEnvironmentVariable("PATH", "User").Count -ne "0") { | |
if ([Environment]::GetEnvironmentVariable("PATH", "User") -eq "") { | |
[Environment]::SetEnvironmentVariable("PATH", "C:\rez\Scripts\rez", "User") | |
} elseif ([Environment]::GetEnvironmentVariable("PATH", "User").Split(";").Count -eq "1") { | |
$user_path = [Environment]::GetEnvironmentVariable("PATH", "User") | |
if (-not ("C:\rez\Scripts\rez" -in ($user_path.Split(";")))) { | |
[Environment]::SetEnvironmentVariable("PATH", "C:\rez\Scripts\rez;$user_path", "User") | |
} | |
} | |
} else { | |
[Environment]::SetEnvironmentVariable("PATH", "C:\rez\Scripts\rez", "User") | |
} | |
if ([Environment]::GetEnvironmentVariable("PYTHONPATH", "User").Count -ne "0") { | |
if ([Environment]::GetEnvironmentVariable("PYTHONPATH", "User") -eq "") { | |
[Environment]::SetEnvironmentVariable("PYTHONPATH", "C:\rez\lib\site-packages", "User") | |
} elseif ([Environment]::GetEnvironmentVariable("PYTHONPATH", "User").Split(";").Count -eq "1") { | |
$user_path = [Environment]::GetEnvironmentVariable("PYTHONPATH", "User") | |
if (-not ("C:\rez\lib\site-packages" -in ($user_path.Split(";")))) { | |
[Environment]::SetEnvironmentVariable("PATH", "C:\rez\lib\site-packages;$user_path", "User") | |
} | |
} | |
} else { | |
[Environment]::SetEnvironmentVariable("PATH", "C:\rez\lib\site-packages", "User") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment