Skip to content

Commit c62758c

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. Also refactor the Proton app discovery in CLI entrypoint, as it was already duplicated and needed to be updated to print the new error message.
1 parent 426c188 commit c62758c

File tree

2 files changed

+56
-22
lines changed

2 files changed

+56
-22
lines changed

src/protontricks/cli/main.py

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

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

299332
# 6. Find Proton version of selected app
300-
proton_app = find_proton_app(
333+
proton_app = _find_proton_app_or_exit(
301334
steam_path=steam_path, steam_apps=steam_apps, appid=steam_app.appid
302335
)
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-
313336

314337
run_command(
315338
winetricks_path=winetricks_path,
@@ -361,19 +384,9 @@ def exit_(error):
361384
return
362385

363386
# 6. Find globally active Proton version now
364-
proton_app = find_proton_app(
387+
proton_app = _find_proton_app_or_exit(
365388
steam_path=steam_path, steam_apps=steam_apps, appid=args.appid)
366389

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-
377390
# If neither search or GUI are set, do a normal Winetricks command
378391
# Find game by appid
379392
steam_appid = int(args.appid)

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)