Skip to content

Commit 8959315

Browse files
First attempt at writing an integration test
Signed-off-by: Jean-Christophe Morin <[email protected]>
1 parent 24aa5f0 commit 8959315

File tree

3 files changed

+117
-9
lines changed

3 files changed

+117
-9
lines changed
+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import os
2+
import zipfile
3+
import argparse
4+
import platform
5+
import tempfile
6+
import subprocess
7+
import urllib.request
8+
9+
import rez.packages
10+
import rez.package_maker
11+
12+
13+
parser = argparse.ArgumentParser()
14+
parser.add_argument("version", help="Python version")
15+
parser.add_argument("repository", help="Repository path")
16+
17+
args = parser.parse_args()
18+
19+
20+
def make_root(variant: rez.packages.Variant, path: str):
21+
dest = os.path.join(path, "python")
22+
23+
if platform.system() == "Windows":
24+
with tempfile.TemporaryDirectory() as tmpdir:
25+
archive_path = os.path.join(tmpdir, "python.nupkg")
26+
27+
url = f"https://globalcdn.nuget.org/packages/python.{variant.version}.nupkg"
28+
29+
print(f"Downloading {url!r}")
30+
with urllib.request.urlopen(url) as archive:
31+
with open(archive_path, "wb") as targetFile:
32+
targetFile.write(archive.read())
33+
34+
with zipfile.ZipFile(archive_path) as archive:
35+
print(f"Extracting {archive_path!r} to {dest!r}")
36+
archive.extractall(path=dest)
37+
else:
38+
cmd = [
39+
"conda",
40+
"create",
41+
"--prefix",
42+
dest,
43+
f"python={args.version}",
44+
"pip",
45+
"--yes",
46+
]
47+
print(f"Running {' '.join(cmd)!r}")
48+
subprocess.check_call(cmd)
49+
50+
51+
with rez.package_maker.make_package(
52+
"python", os.path.expanduser(args.repository), make_root=make_root
53+
) as package:
54+
package.version = args.version
55+
commands = [
56+
"env.PATH.prepend('{root}/python/bin')",
57+
]
58+
if platform.system() == "Windows":
59+
commands = [
60+
"env.PATH.prepend('{root}/python/tools')",
61+
"env.PATH.prepend('{root}/python/tools/DLLs')",
62+
]
63+
64+
package.commands = "\n".join(commands)

.github/workflows/wheel.yaml

+36-1
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ jobs:
119119
CURRENT_PLATFORM: ${{ matrix.os }}
120120

121121
steps:
122+
- uses: actions/checkout@v4
123+
122124
- uses: actions/setup-python@v4
123125
with:
124126
python-version: 3.11
@@ -156,8 +158,41 @@ jobs:
156158
echo 'Running jctest with REZ_LAUNCHER_DEBUG=1'
157159
export REZ_LAUNCHER_DEBUG=1
158160
159-
jctest
161+
_rez-install-test
160162
161163
rez --help
162164
rez --version
163165
rez-env --help
166+
167+
- name: Integration test
168+
shell: bash
169+
run: |
170+
set -e
171+
172+
if [[ "${CURRENT_PLATFORM}" != "windows-latest" ]]; then
173+
eval "$(conda shell.bash hook)"
174+
conda activate base
175+
fi
176+
177+
set -x
178+
179+
interpreter_path=""
180+
export REZ_PACKAGES_PATH="~/rez_packages"
181+
if [[ "${CURRENT_PLATFORM}" == "windows-latest" ]]; then
182+
interpreter_path='.venv/Scripts/python.exe'
183+
export PATH=$(pwd)/.venv/Scripts/rez:$PATH
184+
else
185+
interpreter_path=.'venv/bin/python'
186+
export PATH=$(pwd)/.venv/bin/rez:$PATH
187+
fi
188+
"${interpreter_path}" .github/scripts/create_python_package.py 3.7.9 $REZ_PACKAGES_PATH
189+
190+
# First, test that the "python" package is found and is the right version.
191+
test "$(rez-env python -- python --version)" = 'Python 3.7.9'
192+
193+
# Now test that the -E flag is used. This manifest with sys.flags.ignore_environment=1
194+
test $(rez-env python -- _rez-install-test | jq '.sysflags.ignore_environment' -r) -eq 1
195+
196+
# Now test that the executable used for runnin the rez command is the one from the rez
197+
# install, not the rez package.
198+
test $(rez-env python -- _rez-install-test | jq '.executable' -r) = "$(pwd)/${interpreter_path}"

src/rez/cli/_entry_points.py

+17-8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import os
99
import os.path
1010
import sys
11+
import json
1112

1213

1314
### Utility functions
@@ -62,14 +63,6 @@ def check_production_install():
6263

6364
### Entry points
6465

65-
@register("jctest")
66-
def run_jctest():
67-
print("argv:", sys.argv)
68-
print("executable:", sys.executable)
69-
print("sys.flags:", sys.flags)
70-
return 0
71-
72-
7366
@register("rez")
7467
def run_rez():
7568
check_production_install()
@@ -322,3 +315,19 @@ def run_rez_rm():
322315
check_production_install()
323316
from rez.cli._main import run
324317
return run("rm")
318+
319+
320+
@register("_rez-install-test")
321+
def run_rez_install_test():
322+
data = {
323+
"argv": sys.argv,
324+
"executable": sys.executable,
325+
"sysflags": {
326+
attr: getattr(sys.flags, attr)
327+
for attr in dir(sys.flags)
328+
if not attr.startswith("_") and not callable(getattr(sys.flags, attr))
329+
}
330+
}
331+
332+
print(json.dumps(data, indent=4))
333+
return 0

0 commit comments

Comments
 (0)