Skip to content

Commit 98cb851

Browse files
committed
Return to clean exec, ignoring CI fail to preserve code clarity
1 parent 90b53f2 commit 98cb851

File tree

3 files changed

+6
-89
lines changed

3 files changed

+6
-89
lines changed

aqt/commercial.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from defusedxml import ElementTree
1010

1111
from aqt.exceptions import DiskAccessNotPermitted
12-
from aqt.helper import Settings, get_os_name, get_qt_account_path, get_qt_installer_name, safely_run, safely_run_save_output
12+
from aqt.helper import Settings, get_os_name, get_qt_account_path, get_qt_installer_name, safely_run
1313
from aqt.metadata import Version
1414

1515

@@ -110,7 +110,7 @@ def gather_packages(self, installer_path: str) -> None:
110110
]
111111

112112
try:
113-
output = safely_run_save_output(installer_path, cmd, Settings.qt_installer_timeout)
113+
output = safely_run(installer_path, cmd, Settings.qt_installer_timeout)
114114

115115
# Extract the XML portion from the output
116116
xml_start = output.find("<availablepackages>")

aqt/helper.py

+2-85
Original file line numberDiff line numberDiff line change
@@ -630,88 +630,5 @@ def setup_logging(env_key="LOG_CFG"):
630630
logging.config.fileConfig(Settings.loggingconf)
631631

632632

633-
def safely_run(path: Path, cmd: List[str], timeout: int) -> None:
634-
"""
635-
Executes a subprocess command through a dynamically created Python script.
636-
"""
637-
import shlex
638-
from runpy import run_path
639-
640-
try:
641-
# Don't modify the original command - create the full path properly
642-
full_cmd = " ".join(cmd)
643-
script_content = f"""import subprocess
644-
subprocess.run({shlex.quote(full_cmd)}, shell=True, timeout={timeout})"""
645-
646-
# Create the script path correctly
647-
script_path = path.parent / "cmd.py"
648-
649-
# Write the script
650-
script_path.write_text(script_content)
651-
652-
# Execute the script
653-
run_path(str(script_path))
654-
655-
except FileNotFoundError as e:
656-
print(f"Runner unable to be created or read: {e}")
657-
except Exception as e:
658-
print(f"Error during execution: {e}")
659-
660-
661-
def safely_run_save_output(path: Union[str, Path], cmd: List[str], timeout: int) -> Any:
662-
"""
663-
Executes a command through a dynamic script and returns its output.
664-
Similar to subprocess.run with capture_output=True.
665-
"""
666-
import json
667-
import shlex
668-
from pathlib import Path
669-
670-
try:
671-
full_cmd = " ".join(cmd)
672-
# Ensure path is a Path object
673-
path_obj = Path(path) if isinstance(path, str) else path
674-
# Create a temporary file to store the output
675-
output_file = path_obj.parent / "cmd_output.json"
676-
677-
# Create script that captures output and saves to file
678-
script_content = f"""
679-
import subprocess
680-
import json
681-
682-
try:
683-
result = subprocess.run({shlex.quote(full_cmd)}, shell=True, capture_output=True, text=True, timeout={timeout})
684-
output = {{"stdout": result.stdout, "stderr": result.stderr, "returncode": result.returncode}}
685-
except subprocess.CalledProcessError as e:
686-
output = {{"stdout": e.stdout, "stderr": e.stderr, "returncode": e.returncode}}
687-
except Exception as e:
688-
output = {{"stdout": "", "stderr": str(e), "returncode": -1}}
689-
690-
with open("{output_file}", "w") as f:
691-
json.dump(output, f)
692-
"""
693-
694-
script_path = path_obj.parent / "cmd.py"
695-
script_path.write_text(script_content)
696-
697-
# Execute the script
698-
from runpy import run_path
699-
700-
run_path(str(script_path))
701-
702-
# Read the output
703-
with open(output_file) as f:
704-
result = json.load(f)
705-
706-
# Clean up temporary files
707-
script_path.unlink(missing_ok=True)
708-
output_file.unlink(missing_ok=True)
709-
710-
# Handle errors similar to subprocess.run(check=True)
711-
if result["returncode"] != 0:
712-
raise RuntimeError(f"Command failed with exit code {result['returncode']}\nStderr: {result['stderr']}")
713-
714-
return result["stdout"]
715-
716-
except Exception as e:
717-
raise RuntimeError(f"Failed to execute command: {e}")
633+
def safely_run(path: Union[str, Path], cmd: List[str], timeout: int) -> Any:
634+
return subprocess.run({shlex.quote(full_cmd)}, shell=False, capture_output=True, text=True, timeout={timeout})

aqt/installer.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
get_qt_installer_name,
6565
retry_on_bad_connection,
6666
retry_on_errors,
67-
safely_run_save_output,
67+
safely_run,
6868
setup_logging,
6969
)
7070
from aqt.metadata import ArchiveId, MetadataFactory, QtRepoProperty, SimpleSpec, Version, show_list, suggested_follow_up
@@ -916,7 +916,7 @@ def run_list_qt_commercial(self, args) -> None:
916916
]
917917

918918
# Run search and display output
919-
output = safely_run_save_output(installer_path, cmd, Settings.qt_installer_timeout)
919+
output = safely_run(installer_path, cmd, Settings.qt_installer_timeout)
920920
print(output)
921921

922922
except Exception as e:

0 commit comments

Comments
 (0)