diff --git a/.gitignore b/.gitignore index 264a1230..c4d53b86 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ Qt/ .eggs qtaccount.ini .pytest_cache +.run/ diff --git a/aqt/commercial.py b/aqt/commercial.py index 2f2049b0..280cec93 100644 --- a/aqt/commercial.py +++ b/aqt/commercial.py @@ -68,7 +68,7 @@ def __init__( # Set OS-specific properties self.os_name = self._get_os_name() - self.installer_filename = self.ALLOWED_INSTALLERS[self.os_name] + self._installer_filename = self.ALLOWED_INSTALLERS[self.os_name] self.qt_account = self._get_qt_account_path() def _get_os_name(self) -> str: @@ -92,7 +92,7 @@ def _get_qt_account_path(self) -> Path: return Path.home() / ".local" / "share" / "Qt" / "qtaccount.ini" def _download_installer(self, target_path: Path) -> None: - url = f"{self.base_url}/official_releases/online_installers/{self.installer_filename}" + url = f"{self.base_url}/official_releases/online_installers/{self._installer_filename}" try: response = requests.get(url, stream=True, timeout=self.timeout) response.raise_for_status() @@ -100,9 +100,6 @@ def _download_installer(self, target_path: Path) -> None: with open(target_path, "wb") as f: for chunk in response.iter_content(chunk_size=8192): f.write(chunk) - - if self.os_name != "windows": - os.chmod(target_path, 0o700) except Exception as e: raise RuntimeError(f"Failed to download installer: {e}") @@ -175,9 +172,8 @@ def install(self) -> None: with tempfile.TemporaryDirectory(prefix="qt_install_") as temp_dir: temp_path = Path(temp_dir) - os.chmod(temp_dir, 0o700) - installer_path = temp_path / self.installer_filename + installer_path = temp_path / self._installer_filename self.logger.info(f"Downloading Qt installer to {installer_path}") self._download_installer(installer_path) @@ -194,7 +190,7 @@ def install(self) -> None: safe_cmd[email_index + 1] = "********" self.logger.info(f"Running: {' '.join(safe_cmd)}") - subprocess.run(cmd, shell=False, check=True, cwd=temp_dir) + subprocess.run([self._installer_filename] + cmd, shell=False, check=True, cwd=temp_dir) except subprocess.CalledProcessError as e: self.logger.error(f"Installation failed with exit code {e.returncode}") diff --git a/tests/test_cli.py b/tests/test_cli.py index 863777c5..fc45d667 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -14,41 +14,33 @@ def expected_help(actual, prefix=None): - if sys.version_info >= (3, 13): - expected = ( - "usage: aqt [-h] [-c CONFIG]\n" - " {install-qt,install-tool,install-qt-commercial,install-doc,install-example," - "install-src,list-qt,list-tool,list-doc,list-example,list-src,help,version}\n" - " ...\n" - "\n" - "Another unofficial Qt Installer.\n" - "aqt helps you install Qt SDK, tools, examples and others\n" - "\n" - "options:\n" - " -h, --help show this help message and exit\n" - " -c, --config CONFIG Configuration ini file.\n" - ) - if prefix is not None: - return actual.startswith(prefix + expected) - return actual.startswith(expected) - else: - expected = ( - "usage: aqt [-h] [-c CONFIG]\n" - " {install-qt,install-tool,install-qt-commercial,install-doc,install-example," - "install-src,list-qt,list-tool,list-doc,list-example,list-src,help,version}\n" - " ...\n" - "\n" - "Another unofficial Qt Installer.\n" - "aqt helps you install Qt SDK, tools, examples and others\n" - "\n" - "option", - " -h, --help show this help message and exit\n" - " -c CONFIG, --config CONFIG\n" - " Configuration ini file.\n", - ) - if prefix is not None: - return actual.startswith(prefix + expected[0]) and actual.endswith(expected[1]) - return actual.startswith(expected[0]) and actual.endswith(expected[1]) + expected = ( + "usage: aqt [-h] [-c CONFIG]\n" + " {install-qt,install-tool,install-doc,install-example,install-src," + "list-qt,list-tool,list-doc,list-example,list-src,help,version}\n" + " ...\n" + "\n" + "Another unofficial Qt Installer.\n" + "aqt helps you install Qt SDK, tools, examples and others\n" + "\n" + "option", + " -h, --help show this help message and exit\n" + " -c CONFIG, --config CONFIG\n" + " Configuration ini file.\n" + "\n" + "subcommands:\n" + " aqt accepts several subcommands:\n" + " install-* subcommands are commands that install components\n" + " list-* subcommands are commands that show available components\n" + "\n" + " {install-qt,install-tool,install-doc,install-example,install-src,list-qt," + "list-tool,list-doc,list-example,list-src,help,version}\n" + " Please refer to each help message by using '--help' " + "with each subcommand\n", + ) + if prefix is not None: + return actual.startswith(prefix + expected[0]) and actual.endswith(expected[1]) + return actual.startswith(expected[0]) and actual.endswith(expected[1]) def test_cli_help(capsys): diff --git a/tests/test_install.py b/tests/test_install.py index 25a29aff..a200bc10 100644 --- a/tests/test_install.py +++ b/tests/test_install.py @@ -2061,9 +2061,9 @@ def mock_get_url(url: str, *args, **kwargs) -> str: "cmd, arch_dict, details, expected_command", [ ( - "install-qt-commercial desktop {} 6.8.0 " "--outputdir /tmp/install-qt-commercial " "--user {} --password {}", + "install-qt-commercial desktop {} 6.8.0 " "--outputdir ./install-qt-commercial " "--user {} --password {}", {"windows": "win64_msvc2022_64", "linux": "linux_gcc_64", "mac": "clang_64"}, - ["/tmp/install-qt-commercial", "qt6", "680"], + ["./install-qt-commercial", "qt6", "680"], "qt-unified-{}-x64-online.run --email ******** --pw ******** --root {} " "--accept-licenses --accept-obligations " "--confirm-command " @@ -2077,11 +2077,17 @@ def test_install_qt_commercial( capsys, monkeypatch, cmd: str, arch_dict: dict[str, str], details: list[str], expected_command: str ) -> None: """Test commercial Qt installation command""" + + # Use monkeypatch to replace subprocess.run + monkeypatch.setattr(subprocess, "run", lambda *args, **kwargs: None) + current_platform = sys.platform.lower() arch = arch_dict[current_platform] + abs_out = Path(details[0]).absolute() + formatted_cmd = cmd.format(arch, "vofab76634@gholar.com", "WxK43TdWCTmxsrrpnsWbjPfPXVq3mtLK") - formatted_expected = expected_command.format(current_platform, *details, arch) + formatted_expected = expected_command.format(current_platform, abs_out, *details[1:], arch) cli = Cli() cli._setup_settings()