Skip to content

Commit

Permalink
First attempt at writing an integration test
Browse files Browse the repository at this point in the history
Signed-off-by: Jean-Christophe Morin <[email protected]>
  • Loading branch information
JeanChristopheMorinPerso committed Sep 23, 2023
1 parent 24aa5f0 commit 2030a61
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 9 deletions.
64 changes: 64 additions & 0 deletions .github/scripts/create_python_package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import os
import zipfile
import argparse
import platform
import tempfile
import subprocess
import urllib.request

import rez.packages
import rez.package_maker


parser = argparse.ArgumentParser()
parser.add_argument("version", help="Python version")
parser.add_argument("repository", help="Repository path")

args = parser.parse_args()


def make_root(variant: rez.packages.Variant, path: str):
dest = os.path.join(path, "python")

if platform.system() == "Windows":
with tempfile.TemporaryDirectory() as tmpdir:
archive_path = os.path.join(tmpdir, "python.nupkg")

url = f"https://globalcdn.nuget.org/packages/python.{variant.version}.nupkg"

print(f"Downloading {url!r}")
with urllib.request.urlopen(url) as archive:
with open(archive_path, "wb") as targetFile:
targetFile.write(archive.read())

with zipfile.ZipFile(archive_path) as archive:
print(f"Extracting {archive_path!r} to {dest!r}")
archive.extractall(path=dest)
else:
cmd = [
"conda",
"create",
"--prefix",
dest,
f"python={args.version}",
"pip",
"--yes",
]
print(f"Running {' '.join(cmd)!r}")
subprocess.check_call(cmd)


with rez.package_maker.make_package(
"python", os.path.expanduser(args.repository), make_root=make_root
) as package:
package.version = args.version
commands = [
"env.PATH.prepend('{root}/python/bin')",
]
if platform.system() == "Windows":
commands = [
"env.PATH.prepend('{root}/python/tools')",
"env.PATH.prepend('{root}/python/tools/DLLs')",
]

package.commands = "\n".join(commands)
37 changes: 36 additions & 1 deletion .github/workflows/wheel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ jobs:
CURRENT_PLATFORM: ${{ matrix.os }}

steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v4
with:
python-version: 3.11
Expand Down Expand Up @@ -156,8 +158,41 @@ jobs:
echo 'Running jctest with REZ_LAUNCHER_DEBUG=1'
export REZ_LAUNCHER_DEBUG=1
jctest
_rez-install-test
rez --help
rez --version
rez-env --help
- name: Integration test
shell: bash
run: |
set -e
if [[ "${CURRENT_PLATFORM}" != "windows-latest" ]]; then
eval "$(conda shell.bash hook)"
conda activate base
fi
set -x
interpreter_path=""
export REZ_PACKAGES_PATH="~/rez_packages"
if [[ "${CURRENT_PLATFORM}" == "windows-latest" ]]; then
interpreter_path='.venv/Scripts/python.exe'
export PATH=$(pwd)/.venv/Scripts/rez:$PATH
else
interpreter_path=.'venv/bin/python'
export PATH=$(pwd)/.venv/bin/rez:$PATH
fi
"${interpreter_path}" .github/scripts/create_python_package.py 3.7.10 $REZ_PACKAGES_PATH
# First, test that the "python" package is found and is the right version.
test "$(rez-env python -- python --version)" = 'Python 3.7.10'
# Now test that the -E flag is used. This manifest with sys.flags.ignore_environment=1
test $(rez-env python -- _rez-install-test | jq '.sysflags.ignore_environment' -r) -eq 1
# Now test that the executable used for runnin the rez command is the one from the rez
# install, not the rez package.
test $(rez-env python -- _rez-install-test | jq '.executable' -r) = "$(pwd)/${interpreter_path}"
25 changes: 17 additions & 8 deletions src/rez/cli/_entry_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import os
import os.path
import sys
import json


### Utility functions
Expand Down Expand Up @@ -62,14 +63,6 @@ def check_production_install():

### Entry points

@register("jctest")
def run_jctest():
print("argv:", sys.argv)
print("executable:", sys.executable)
print("sys.flags:", sys.flags)
return 0


@register("rez")
def run_rez():
check_production_install()
Expand Down Expand Up @@ -322,3 +315,19 @@ def run_rez_rm():
check_production_install()
from rez.cli._main import run
return run("rm")


@register("_rez-install-test")
def run_rez_install_test():
data = {
"argv": sys.argv,
"executable": sys.executable,
"sysflags": {
attr: getattr(sys.flags, attr)
for attr in dir(sys.flags)
if not attr.startswith("_") and not callable(getattr(sys.flags, attr))
}
}

print(json.dumps(data, indent=4))
return 0

0 comments on commit 2030a61

Please sign in to comment.