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 df3783d
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 9 deletions.
54 changes: 54 additions & 0 deletions .github/scripts/create_python_package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
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(["conda", "create", "--prefix", dest, f"python={args.version}", "pip", "--yes"])


with rez.package_maker.make_package("python", 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)
38 changes: 37 additions & 1 deletion .github/workflows/wheel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,44 @@ 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
# We technically only need it for non windows platforms,
# by activating it everywhere adds noise, which could catch bugs.
conda activate base
set -x
interpreter_path=""
if [[ "${CURRENT_PLATFORM}" == "windows-latest" ]]; then
export REZ_PACKAGES_PATH="~/rez_packages"
interpreter_path='.venv/Scripts/python.exe'
export PATH=$(pwd)/.venv/Scripts/rez:$PATH
else
export REZ_PACKAGES_PATH=/opt/rez_packages
rm -rf $REZ_PACKAGES_PATH
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
conda deactivate
# 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 df3783d

Please sign in to comment.