Skip to content

Commit

Permalink
Ruff lint
Browse files Browse the repository at this point in the history
- Apply new rules: PLR5501, SIM, ARG, PLW1510. See ruff.toml or visit the manual for details.
  • Loading branch information
R1kaB3rN committed Mar 22, 2024
1 parent 14891f3 commit 78d37fe
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 40 deletions.
2 changes: 1 addition & 1 deletion umu/umu_dl_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 17 additions & 15 deletions umu/umu_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand All @@ -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
Expand Down Expand Up @@ -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",
Expand All @@ -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()
19 changes: 8 additions & 11 deletions umu/umu_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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": "",
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 7 additions & 9 deletions umu/umu_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions umu/umu_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 (
Expand All @@ -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
Expand Down

0 comments on commit 78d37fe

Please sign in to comment.