diff --git a/umu/umu_dl_util.py b/umu/umu_dl_util.py index 97cd2565..531ea96e 100644 --- a/umu/umu_dl_util.py +++ b/umu/umu_dl_util.py @@ -295,7 +295,7 @@ def _get_latest( log.console(f"Using {version} ({proton})") env["PROTONPATH"] = environ["PROTONPATH"] except ValueError: - log.exception("Exception") + log.exception("ValueError") tarball: str = files[1][0] # Digest mismatched diff --git a/umu/umu_plugins.py b/umu/umu_plugins.py index 2400feef..d49da16d 100644 --- a/umu/umu_plugins.py +++ b/umu/umu_plugins.py @@ -38,7 +38,7 @@ def set_env_toml( with Path(path_config).open(mode="rb") as file: toml = tomllib.load(file) - _check_env_toml(env, toml) + _check_env_toml(toml) for key, val in toml["umu"].items(): if key == "prefix": @@ -59,7 +59,7 @@ def set_env_toml( return env, opts -def _check_env_toml(env: Dict[str, str], toml: Dict[str, Any]) -> Dict[str, Any]: +def _check_env_toml(toml: Dict[str, Any]) -> Dict[str, Any]: """Check for required or empty key/value pairs when reading a TOML config. NOTE: Casing matters in the config and we do not check if the game id is set @@ -170,8 +170,9 @@ def enable_zenity(command: str, opts: List[str], msg: str) -> int: err: str = f"{command} was not found in system" raise FileNotFoundError(err) - with Popen([cmd, *opts], stdout=PIPE, stderr=STDOUT) as proc: - with Popen( + with ( + Popen([cmd, *opts], stdout=PIPE, stderr=STDOUT) as proc, + Popen( [ f"{bin}", "--progress", @@ -181,14 +182,15 @@ def enable_zenity(command: str, opts: List[str], msg: str) -> int: "--pulsate", ], stdin=PIPE, - ) as zenity_proc: - try: - proc.wait(timeout=300) - except TimeoutExpired: - zenity_proc.terminate() - log.warning("%s timed out after 5 min.", cmd) - raise TimeoutError - - zenity_proc.stdin.close() - - return zenity_proc.wait() + ) as zenity_proc, + ): + try: + proc.wait(timeout=300) + except TimeoutExpired: + zenity_proc.terminate() + log.warning("%s timed out after 5 min.", cmd) + raise TimeoutError + + zenity_proc.stdin.close() + + return zenity_proc.wait() diff --git a/umu/umu_run.py b/umu/umu_run.py index baf6d292..ee5093de 100755 --- a/umu/umu_run.py +++ b/umu/umu_run.py @@ -7,7 +7,7 @@ from typing import Dict, Any, List, Set, Union, Tuple from umu_plugins import enable_steam_game_drive, set_env_toml, enable_reaper from re import match -from subprocess import run +from subprocess import run, CalledProcessError from umu_dl_util import get_umu_proton from umu_consts import PROTON_VERBS, DEBUG_FORMAT, STEAM_COMPAT, UMU_LOCAL from umu_util import setup_umu @@ -107,9 +107,7 @@ def setup_pfx(path: str) -> None: log.debug("User home directory exists: %s", wineuser) -def check_env( - env: Dict[str, str], toml: Dict[str, Any] = None -) -> Union[Dict[str, str], Dict[str, Any]]: +def check_env(env: Dict[str, str]) -> Union[Dict[str, str], Dict[str, Any]]: """Before executing a game, check for environment variables and set them. GAMEID is strictly required @@ -145,7 +143,7 @@ def check_env( ).as_posix() # GE-Proton - if os.environ.get("PROTONPATH") and os.environ.get("PROTONPATH") == "GE-Proton": + if os.environ.get("PROTONPATH") == "GE-Proton": log.debug("GE-Proton selected") get_umu_proton(env) @@ -257,7 +255,7 @@ def build_command( return command -def main() -> int: # noqa: D103 +def main() -> None: # noqa: D103 env: Dict[str, str] = { "WINEPREFIX": "", "GAMEID": "", @@ -352,18 +350,17 @@ def main() -> int: # noqa: D103 build_command(env, UMU_LOCAL, command, opts) log.debug("%s", command) - return run(command).returncode + return run(command, check=True) if __name__ == "__main__": try: - sys.exit(main()) + main() except KeyboardInterrupt: log.warning("Keyboard Interrupt") sys.exit(1) - except SystemExit as e: - if e.code != 0: - raise Exception(e) + except CalledProcessError: + log.exception("CalledProcessError") except Exception: log.exception("Exception") sys.exit(1) diff --git a/umu/umu_test.py b/umu/umu_test.py index 25c8aa9c..2267502a 100644 --- a/umu/umu_test.py +++ b/umu/umu_test.py @@ -1931,15 +1931,13 @@ def test_env_proton_nodir(self): An FileNotFoundError should be raised when we fail to set PROTONPATH """ # Mock getting the Proton - with self.assertRaises(FileNotFoundError): - with patch.object( - umu_run, - "get_umu_proton", - return_value=self.env, - ): - os.environ["WINEPREFIX"] = self.test_file - os.environ["GAMEID"] = self.test_file - umu_run.check_env(self.env) + with ( + self.assertRaises(FileNotFoundError), + patch.object(umu_run, "get_umu_proton", return_value=self.env), + ): + os.environ["WINEPREFIX"] = self.test_file + os.environ["GAMEID"] = self.test_file + umu_run.check_env(self.env) def test_env_wine_dir(self): """Test check_env when $WINEPREFIX is not a directory. diff --git a/umu/umu_util.py b/umu/umu_util.py index 0c98c5f7..0f755752 100644 --- a/umu/umu_util.py +++ b/umu/umu_util.py @@ -57,7 +57,7 @@ def is_user(self, uid: int) -> bool: return uid == self.puid -def setup_runtime(root: Path, json: Dict[str, Any]) -> None: # noqa: D103 +def setup_runtime(json: Dict[str, Any]) -> None: # noqa: D103 archive: str = "steam-container-runtime-complete.tar.gz" tmp: Path = Path(mkdtemp()) # Access the 'runtime_platform' value @@ -233,7 +233,7 @@ def _install_umu( copy(root.joinpath("reaper"), local.joinpath("reaper")) # Runtime platform - thread = Thread(target=setup_runtime, args=(root, json)) + thread = Thread(target=setup_runtime, args=[json]) thread.start() # Launcher files @@ -327,7 +327,7 @@ def _update_umu( if local.joinpath(runtime).is_dir(): rmtree(local.joinpath(runtime).as_posix()) - thread = Thread(target=setup_runtime, args=(root, json_root)) + thread = Thread(target=setup_runtime, args=[json_root]) thread.start() log.console(f"Restoring Runtime Platform to {val} ...") elif ( @@ -339,7 +339,7 @@ def _update_umu( log.console(f"Updating {key} to {val}") rmtree(local.joinpath("pressure-vessel").as_posix()) rmtree(local.joinpath(runtime).as_posix()) - thread = Thread(target=setup_runtime, args=(root, json_root)) + thread = Thread(target=setup_runtime, args=[json_root]) thread.start() json_local["umu"]["versions"]["runtime_platform"] = val