Skip to content

Commit b604807

Browse files
Make sure -E is used and fix scripts on unix
Signed-off-by: Jean-Christophe Morin <[email protected]>
1 parent 09bcf25 commit b604807

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed

.github/workflows/wheel.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
cp distlib/PC/launcher.c launcher/
3030
3131
cd launcher
32-
patch -Np1 -i remote-appended.patch --binary
32+
patch -Np1 -i rez.patch --binary
3333
3434
mkdir build
3535
cd build

launcher/remote-appended.patch renamed to launcher/rez.patch

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
diff --git a/launcher.c b/launcher.c
2-
index 727f7916..431e0339 100644
2+
index 727f7916..99234d3a 100644
33
--- a/launcher.c
44
+++ b/launcher.c
55
@@ -35,8 +35,6 @@
@@ -25,3 +25,13 @@ index 727f7916..431e0339 100644
2525
ok = CreateProcessW(NULL, cmdline, NULL, NULL, TRUE, 0, NULL, NULL, &si, &child_process_info);
2626
if (!ok) {
2727
// Failed to create process. See if we can find out why.
28+
@@ -1031,7 +1036,8 @@ process(int argc, char * argv[])
29+
len = wcslen(wcp) + wcslen(wp) + 8 + wcslen(psp) + wcslen(cmdline);
30+
cmdp = (wchar_t *) calloc(len, sizeof(wchar_t));
31+
assert(cmdp != NULL, "Expected to be able to allocate command line memory");
32+
- _snwprintf_s(cmdp, len, len, L"\"%ls\" %ls \"%ls\" %ls", wcp, wp, psp, cmdline);
33+
+ // Note that we inject -E to make sure PYTHON* variables are not picked up.
34+
+ _snwprintf_s(cmdp, len, len, L"\"%ls\" -E %ls \"%ls\" %ls", wcp, wp, psp, cmdline);
35+
run_child(cmdp); /* never actually returns */
36+
free(cmdp);
37+
return 0;

setup.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,22 @@ def find_files(pattern, path=None, root="rez"):
5555
long_description = f.read()
5656

5757

58-
SCRIPT_TEMPLATE = """#!/usr/bin/python -E
58+
SCRIPT_TEMPLATE = """#!/usr/bin/python
5959
# -*- coding: utf-8 -*-
60+
import os
6061
import re
6162
import sys
63+
import platform
64+
# If -E is not passed, then inject it and re-execute outself.
65+
# Note that this is not done on Windows because the Windows launcher
66+
# already does this.
67+
if not sys.flags.ignore_environment and platform.system() != 'Windows':
68+
args = sys.orig_argv[:]
69+
args[0] = sys.executable
70+
args.insert(1, '-E')
71+
if os.getenv('REZ_LAUNCHER_DEBUG'):
72+
print('Launching:', ' '.join(args))
73+
os.execvp(sys.executable, args)
6274
from rez.cli._entry_points import {0}
6375
if __name__ == '__main__':
6476
sys.argv[0] = re.sub(r'(-script\\.pyw|\\.exe)?$', '', sys.argv[0])
@@ -76,12 +88,12 @@ def run(self):
7688
scripts = []
7789
tmpdir = tempfile.mkdtemp("rez-scripts")
7890

79-
os.makedirs(self.build_dir)
91+
os.makedirs(self.build_dir, exist_ok=True)
8092

8193
for command in self.scripts:
8294
spec = get_specifications()[command]
8395

84-
filename = "{0}.py".format(command)
96+
filename = command
8597
if platform.system() == "Windows":
8698
filename = "{0}-script.py".format(command)
8799

src/rez/cli/_entry_points.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ def check_production_install():
6565
@register("jctest")
6666
def run_jctest():
6767
print("argv:", sys.argv)
68+
print("orig_argv", sys.orig_argv)
6869
print("executable:", sys.executable)
70+
print("sys.flags:", sys.flags)
6971
return 0
7072

7173

0 commit comments

Comments
 (0)