Skip to content

Commit 7886405

Browse files
YuanTingHsiehpcnuddegreptile-apps[bot]
authored
Cherry-pick [2.7] Enhancements on CI install_requirements (#4249) (#4283)
Make integration tests' install_requirements more robust <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [x] Non-breaking change (fix or new feature that would not break existing functionality). - [ ] Breaking change (fix or new feature that would cause existing functionality to change). - [ ] New tests added to cover the changes. - [ ] Quick tests passed locally by running `./runtest.sh`. - [ ] In-line docstrings updated. - [ ] Documentation updated. --------- Fixes # . ### Description A few sentences describing the changes proposed in this pull request. ### Types of changes <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [x] Non-breaking change (fix or new feature that would not break existing functionality). - [ ] Breaking change (fix or new feature that would cause existing functionality to change). - [ ] New tests added to cover the changes. - [ ] Quick tests passed locally by running `./runtest.sh`. - [ ] In-line docstrings updated. - [ ] Documentation updated. --------- Co-authored-by: Peter Cnudde <pcnudde@nvidia.com> Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
1 parent aaf5b13 commit 7886405

File tree

3 files changed

+41
-15
lines changed

3 files changed

+41
-15
lines changed

tests/integration_test/install_requirements.py

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@
2222
"""
2323

2424
import argparse
25+
import os
26+
import re
2527
import subprocess
2628
import sys
29+
import tempfile
2730

2831

2932
def main():
@@ -42,25 +45,43 @@ def main():
4245
with open(args.requirements_file) as f:
4346
lines = f.readlines()
4447

45-
packages = []
48+
filtered = []
4649
for line in lines:
4750
stripped = line.strip()
4851
if not stripped or stripped.startswith("#"):
4952
continue
50-
pkg_lower = stripped.lower()
51-
if any(pkg_lower.startswith(ex) for ex in excluded):
52-
continue
53-
packages.append(stripped)
53+
if excluded:
54+
# Extract the package specifier before any inline comment for exclude matching
55+
spec = re.split(r"\s+#", stripped)[0].strip()
56+
if any(spec.lower().startswith(ex) for ex in excluded):
57+
continue
58+
filtered.append(line)
5459

55-
if not packages:
60+
if not filtered:
5661
print("No packages to install.")
5762
return
5863

59-
cmd = [sys.executable, "-m", "pip", "install"] + packages
60-
if args.quiet:
61-
cmd.append("--quiet")
64+
req_dir = os.path.dirname(os.path.abspath(args.requirements_file))
65+
fd, tmp_path = tempfile.mkstemp(suffix=".txt", dir=req_dir)
66+
result = 1
67+
try:
68+
try:
69+
with os.fdopen(fd, "w") as tmp:
70+
tmp.writelines(filtered)
71+
except Exception:
72+
os.close(fd)
73+
raise
74+
cmd = [sys.executable, "-m", "pip", "install", "-r", tmp_path]
75+
if args.quiet:
76+
cmd.append("--quiet")
77+
result = subprocess.call(cmd)
78+
finally:
79+
try:
80+
os.unlink(tmp_path)
81+
except FileNotFoundError:
82+
pass
6283

63-
sys.exit(subprocess.call(cmd))
84+
sys.exit(result)
6485

6586

6687
if __name__ == "__main__":

tests/integration_test/src/provision_site_launcher.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
import os
16+
import shlex
1617
import shutil
1718
import tempfile
1819
import time
@@ -34,14 +35,16 @@
3435

3536

3637
def _start_site(site_properties: SiteProperties):
37-
process = run_command_in_subprocess(f"bash {os.path.join(site_properties.root_dir, 'startup', 'start.sh')}")
38+
process = run_command_in_subprocess(
39+
f"bash {shlex.quote(os.path.join(site_properties.root_dir, 'startup', 'start.sh'))}"
40+
)
3841
print(f"Starting {site_properties.name} ...")
3942
site_properties.process = process
4043

4144

4245
def _stop_site(site_properties: SiteProperties):
4346
run_command_in_subprocess(
44-
f"bash {os.path.join(site_properties.root_dir, 'startup', 'stop_fl.sh')}", stdin_data=b"y\n"
47+
f"bash {shlex.quote(os.path.join(site_properties.root_dir, 'startup', 'stop_fl.sh'))}", stdin_data=b"y\n"
4548
)
4649
print(f"Stopping {site_properties.name} ...")
4750

tests/integration_test/src/utils.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,17 @@ def run_command_in_subprocess(command, stdin_data=None):
6666
new_env = os.environ.copy()
6767
python_path = ":".join(sys.path)[1:] # strip leading colon
6868
new_env["PYTHONPATH"] = python_path
69+
tokens = [os.path.expandvars(os.path.expanduser(t)) for t in shlex.split(command)]
6970
process = subprocess.Popen(
70-
shlex.split(command),
71+
tokens,
7172
stdin=subprocess.PIPE if stdin_data else None,
7273
preexec_fn=os.setsid,
7374
env=new_env,
7475
)
7576
if stdin_data:
76-
process.stdin.write(stdin_data)
77-
process.stdin.close()
77+
# communicate() writes stdin and waits for the process to exit.
78+
# stdout/stderr are inherited from the parent process (not captured).
79+
process.communicate(input=stdin_data)
7880
return process
7981

8082

0 commit comments

Comments
 (0)