Skip to content

Commit 9cc98b4

Browse files
committed
Print available Proton versions on missing value
Print available Proton versions when $PROTON_VERSION has been set but the installation in question cannot be found, as the list of allowed values is otherwise hard to determine.
1 parent 426c188 commit 9cc98b4

File tree

3 files changed

+58
-22
lines changed

3 files changed

+58
-22
lines changed

src/protontricks/cli/main.py

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,45 @@ def cli(args=None):
3232
main(args)
3333

3434

35+
3536
@cli_error_handler
3637
def main(args=None, steam_path=None, steam_root=None):
3738
"""
3839
'protontricks' script entrypoint
3940
"""
41+
def _find_proton_app_or_exit(steam_path, steam_apps, appid):
42+
"""
43+
Attempt to find a Proton app. Fail with an appropriate CLI error
44+
message if one cannot be found.
45+
"""
46+
proton_app = find_proton_app(
47+
steam_path=steam_path, steam_apps=steam_apps, appid=appid
48+
)
49+
50+
if not proton_app:
51+
if os.environ.get("PROTON_VERSION"):
52+
# Print an error listing accepted values if PROTON_VERSION was
53+
# set, as the user is trying to use a certain Proton version
54+
proton_names = sorted(set([
55+
app.name for app in steam_apps if app.is_proton
56+
]))
57+
exit_(
58+
"Protontricks installation could not be found with given "
59+
"$PROTON_VERSION!\n\n"
60+
f"Valid values include: {", ".join(proton_names)}"
61+
)
62+
else:
63+
exit_("Proton installation could not be found!")
64+
65+
if not proton_app.is_proton_ready:
66+
exit_(
67+
"Proton installation is incomplete. Have you launched a Steam "
68+
"app using this Proton version at least once to finish the "
69+
"installation?"
70+
)
71+
72+
return proton_app
73+
4074
if args is None:
4175
args = sys.argv[1:]
4276

@@ -297,19 +331,9 @@ def exit_(error):
297331
cwd = str(steam_app.install_path) if args.cwd_app else None
298332

299333
# 6. Find Proton version of selected app
300-
proton_app = find_proton_app(
334+
proton_app = _find_proton_app_or_exit(
301335
steam_path=steam_path, steam_apps=steam_apps, appid=steam_app.appid
302336
)
303-
if not proton_app:
304-
exit_("Proton installation could not be found!")
305-
306-
if not proton_app.is_proton_ready:
307-
exit_(
308-
"Proton installation is incomplete. Have you launched a Steam "
309-
"app using this Proton version at least once to finish the "
310-
"installation?"
311-
)
312-
313337

314338
run_command(
315339
winetricks_path=winetricks_path,
@@ -361,19 +385,9 @@ def exit_(error):
361385
return
362386

363387
# 6. Find globally active Proton version now
364-
proton_app = find_proton_app(
388+
proton_app = _find_proton_app_or_exit(
365389
steam_path=steam_path, steam_apps=steam_apps, appid=args.appid)
366390

367-
if not proton_app:
368-
exit_("Proton installation could not be found!")
369-
370-
if not proton_app.is_proton_ready:
371-
exit_(
372-
"Proton installation is incomplete. Have you launched a Steam app "
373-
"using this Proton version at least once to finish the "
374-
"installation?"
375-
)
376-
377391
# If neither search or GUI are set, do a normal Winetricks command
378392
# Find game by appid
379393
steam_appid = int(args.appid)

src/protontricks/steam.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,7 @@ def find_proton_app(steam_path, steam_apps, appid=None):
925925
"$PROTON_VERSION was set but matching Proton installation "
926926
"could not be found."
927927
)
928+
928929
return None
929930

930931
tool_app = find_steam_compat_tool_app(

tests/cli/test_main.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,27 @@ def test_run_winetricks_select_proton(
6969
assert command_mock.commands[-1].env["PROTON_PATH"] \
7070
== str(custom_proton.install_path)
7171

72+
def test_run_winetricks_select_proton_accepted_values(
73+
self, cli, steam_app_factory, custom_proton_factory, command_mock):
74+
"""
75+
Perform a Protonrticks command while selecting a non-existent Proton
76+
version using PROTON_VERSION env var. Ensure list of allowed values
77+
is printed in the error message
78+
"""
79+
steam_app_factory(name="Fake game", appid=10)
80+
custom_proton_factory(name="Custom Proton C")
81+
custom_proton_factory(name="Custom Proton A")
82+
83+
result = cli(
84+
["10", "winecfg"],
85+
env={"PROTON_VERSION": "Nonexistent Proton"},
86+
expect_returncode=1
87+
)
88+
89+
assert "Protontricks installation could not be found" in result
90+
assert \
91+
"Valid values include: Custom Proton A, Custom Proton C" in result
92+
7293
def test_run_winetricks_select_steam(
7394
self, cli, steam_app_factory, default_proton, command_mock,
7495
home_dir):

0 commit comments

Comments
 (0)