Skip to content

Commit 78d37fe

Browse files
committed
Ruff lint
- Apply new rules: PLR5501, SIM, ARG, PLW1510. See ruff.toml or visit the manual for details.
1 parent 14891f3 commit 78d37fe

File tree

5 files changed

+37
-40
lines changed

5 files changed

+37
-40
lines changed

umu/umu_dl_util.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ def _get_latest(
295295
log.console(f"Using {version} ({proton})")
296296
env["PROTONPATH"] = environ["PROTONPATH"]
297297
except ValueError:
298-
log.exception("Exception")
298+
log.exception("ValueError")
299299
tarball: str = files[1][0]
300300

301301
# Digest mismatched

umu/umu_plugins.py

+17-15
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def set_env_toml(
3838
with Path(path_config).open(mode="rb") as file:
3939
toml = tomllib.load(file)
4040

41-
_check_env_toml(env, toml)
41+
_check_env_toml(toml)
4242

4343
for key, val in toml["umu"].items():
4444
if key == "prefix":
@@ -59,7 +59,7 @@ def set_env_toml(
5959
return env, opts
6060

6161

62-
def _check_env_toml(env: Dict[str, str], toml: Dict[str, Any]) -> Dict[str, Any]:
62+
def _check_env_toml(toml: Dict[str, Any]) -> Dict[str, Any]:
6363
"""Check for required or empty key/value pairs when reading a TOML config.
6464
6565
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:
170170
err: str = f"{command} was not found in system"
171171
raise FileNotFoundError(err)
172172

173-
with Popen([cmd, *opts], stdout=PIPE, stderr=STDOUT) as proc:
174-
with Popen(
173+
with (
174+
Popen([cmd, *opts], stdout=PIPE, stderr=STDOUT) as proc,
175+
Popen(
175176
[
176177
f"{bin}",
177178
"--progress",
@@ -181,14 +182,15 @@ def enable_zenity(command: str, opts: List[str], msg: str) -> int:
181182
"--pulsate",
182183
],
183184
stdin=PIPE,
184-
) as zenity_proc:
185-
try:
186-
proc.wait(timeout=300)
187-
except TimeoutExpired:
188-
zenity_proc.terminate()
189-
log.warning("%s timed out after 5 min.", cmd)
190-
raise TimeoutError
191-
192-
zenity_proc.stdin.close()
193-
194-
return zenity_proc.wait()
185+
) as zenity_proc,
186+
):
187+
try:
188+
proc.wait(timeout=300)
189+
except TimeoutExpired:
190+
zenity_proc.terminate()
191+
log.warning("%s timed out after 5 min.", cmd)
192+
raise TimeoutError
193+
194+
zenity_proc.stdin.close()
195+
196+
return zenity_proc.wait()

umu/umu_run.py

+8-11
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from typing import Dict, Any, List, Set, Union, Tuple
88
from umu_plugins import enable_steam_game_drive, set_env_toml, enable_reaper
99
from re import match
10-
from subprocess import run
10+
from subprocess import run, CalledProcessError
1111
from umu_dl_util import get_umu_proton
1212
from umu_consts import PROTON_VERBS, DEBUG_FORMAT, STEAM_COMPAT, UMU_LOCAL
1313
from umu_util import setup_umu
@@ -107,9 +107,7 @@ def setup_pfx(path: str) -> None:
107107
log.debug("User home directory exists: %s", wineuser)
108108

109109

110-
def check_env(
111-
env: Dict[str, str], toml: Dict[str, Any] = None
112-
) -> Union[Dict[str, str], Dict[str, Any]]:
110+
def check_env(env: Dict[str, str]) -> Union[Dict[str, str], Dict[str, Any]]:
113111
"""Before executing a game, check for environment variables and set them.
114112
115113
GAMEID is strictly required
@@ -145,7 +143,7 @@ def check_env(
145143
).as_posix()
146144

147145
# GE-Proton
148-
if os.environ.get("PROTONPATH") and os.environ.get("PROTONPATH") == "GE-Proton":
146+
if os.environ.get("PROTONPATH") == "GE-Proton":
149147
log.debug("GE-Proton selected")
150148
get_umu_proton(env)
151149

@@ -257,7 +255,7 @@ def build_command(
257255
return command
258256

259257

260-
def main() -> int: # noqa: D103
258+
def main() -> None: # noqa: D103
261259
env: Dict[str, str] = {
262260
"WINEPREFIX": "",
263261
"GAMEID": "",
@@ -352,18 +350,17 @@ def main() -> int: # noqa: D103
352350
build_command(env, UMU_LOCAL, command, opts)
353351
log.debug("%s", command)
354352

355-
return run(command).returncode
353+
return run(command, check=True)
356354

357355

358356
if __name__ == "__main__":
359357
try:
360-
sys.exit(main())
358+
main()
361359
except KeyboardInterrupt:
362360
log.warning("Keyboard Interrupt")
363361
sys.exit(1)
364-
except SystemExit as e:
365-
if e.code != 0:
366-
raise Exception(e)
362+
except CalledProcessError:
363+
log.exception("CalledProcessError")
367364
except Exception:
368365
log.exception("Exception")
369366
sys.exit(1)

umu/umu_test.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -1931,15 +1931,13 @@ def test_env_proton_nodir(self):
19311931
An FileNotFoundError should be raised when we fail to set PROTONPATH
19321932
"""
19331933
# Mock getting the Proton
1934-
with self.assertRaises(FileNotFoundError):
1935-
with patch.object(
1936-
umu_run,
1937-
"get_umu_proton",
1938-
return_value=self.env,
1939-
):
1940-
os.environ["WINEPREFIX"] = self.test_file
1941-
os.environ["GAMEID"] = self.test_file
1942-
umu_run.check_env(self.env)
1934+
with (
1935+
self.assertRaises(FileNotFoundError),
1936+
patch.object(umu_run, "get_umu_proton", return_value=self.env),
1937+
):
1938+
os.environ["WINEPREFIX"] = self.test_file
1939+
os.environ["GAMEID"] = self.test_file
1940+
umu_run.check_env(self.env)
19431941

19441942
def test_env_wine_dir(self):
19451943
"""Test check_env when $WINEPREFIX is not a directory.

umu/umu_util.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def is_user(self, uid: int) -> bool:
5757
return uid == self.puid
5858

5959

60-
def setup_runtime(root: Path, json: Dict[str, Any]) -> None: # noqa: D103
60+
def setup_runtime(json: Dict[str, Any]) -> None: # noqa: D103
6161
archive: str = "steam-container-runtime-complete.tar.gz"
6262
tmp: Path = Path(mkdtemp())
6363
# Access the 'runtime_platform' value
@@ -233,7 +233,7 @@ def _install_umu(
233233
copy(root.joinpath("reaper"), local.joinpath("reaper"))
234234

235235
# Runtime platform
236-
thread = Thread(target=setup_runtime, args=(root, json))
236+
thread = Thread(target=setup_runtime, args=[json])
237237
thread.start()
238238

239239
# Launcher files
@@ -327,7 +327,7 @@ def _update_umu(
327327
if local.joinpath(runtime).is_dir():
328328
rmtree(local.joinpath(runtime).as_posix())
329329

330-
thread = Thread(target=setup_runtime, args=(root, json_root))
330+
thread = Thread(target=setup_runtime, args=[json_root])
331331
thread.start()
332332
log.console(f"Restoring Runtime Platform to {val} ...")
333333
elif (
@@ -339,7 +339,7 @@ def _update_umu(
339339
log.console(f"Updating {key} to {val}")
340340
rmtree(local.joinpath("pressure-vessel").as_posix())
341341
rmtree(local.joinpath(runtime).as_posix())
342-
thread = Thread(target=setup_runtime, args=(root, json_root))
342+
thread = Thread(target=setup_runtime, args=[json_root])
343343
thread.start()
344344

345345
json_local["umu"]["versions"]["runtime_platform"] = val

0 commit comments

Comments
 (0)