Skip to content

Commit 2d70f38

Browse files
authored
fix: skip prefix creation when running native Linux executables (#302)
* umu_run: skip prefix setup when not using proton * umu_run: update environment check logic when not using proton * umu_test: add tests when configured to not using proton
1 parent 562e390 commit 2d70f38

File tree

2 files changed

+89
-3
lines changed

2 files changed

+89
-3
lines changed

umu/umu_run.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ def setup_pfx(path: str) -> None:
7272
user: str = getpwuid(os.getuid()).pw_name
7373
wineuser: Path = Path(path).expanduser().joinpath("drive_c", "users", user)
7474

75+
if os.environ.get("UMU_NO_PROTON") == "1":
76+
return
77+
7578
if pfx.is_symlink():
7679
pfx.unlink()
7780

@@ -112,17 +115,23 @@ def check_env(
112115
err: str = "Environment variable is empty: WINEPREFIX"
113116
raise ValueError(err)
114117

115-
if "WINEPREFIX" not in os.environ:
118+
if (
119+
os.environ.get("UMU_NO_PROTON") != "1"
120+
and "WINEPREFIX" not in os.environ
121+
):
116122
pfx: Path = Path.home().joinpath("Games", "umu", env["GAMEID"])
117123
pfx.mkdir(parents=True, exist_ok=True)
118124
os.environ["WINEPREFIX"] = str(pfx)
119125

120-
if not Path(os.environ["WINEPREFIX"]).expanduser().is_dir():
126+
if (
127+
os.environ.get("UMU_NO_PROTON") != "1"
128+
and not Path(os.environ["WINEPREFIX"]).expanduser().is_dir()
129+
):
121130
pfx: Path = Path(os.environ["WINEPREFIX"])
122131
pfx.mkdir(parents=True, exist_ok=True)
123132
os.environ["WINEPREFIX"] = str(pfx)
124133

125-
env["WINEPREFIX"] = os.environ["WINEPREFIX"]
134+
env["WINEPREFIX"] = os.environ.get("WINEPREFIX", "")
126135

127136
# Skip Proton if running a native Linux executable
128137
if os.environ.get("UMU_NO_PROTON") == "1":

umu/umu_test.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def setUp(self):
6969
"STEAM_COMPAT_MEDIA_PATH": "",
7070
"STEAM_FOSSILIZE_DUMP_PATH": "",
7171
"DXVK_STATE_CACHE_PATH": "",
72+
"UMU_NO_PROTON": "",
7273
}
7374
self.user = getpwuid(os.getuid()).pw_name
7475
self.test_opts = "-foo -bar"
@@ -2914,6 +2915,26 @@ def test_setup_pfx_paths(self):
29142915
"Expected tracked_files to be a file",
29152916
)
29162917

2918+
def test_setup_pfx_noproton(self):
2919+
"""Test setup_pfx when configured to not use Proton."""
2920+
result = None
2921+
os.environ["UMU_NO_PROTON"] = "1"
2922+
2923+
result = umu_run.setup_pfx(self.test_file)
2924+
self.assertTrue(result is None, f"Expected None, received {result}")
2925+
self.assertFalse(
2926+
Path(self.test_file, "pfx").exists(),
2927+
f"Expected {self.test_file}/pfx to not exist",
2928+
)
2929+
self.assertFalse(
2930+
Path(self.test_file, "tracked_files").exists(),
2931+
f"Expected {self.test_file}/tracked_files to not exist",
2932+
)
2933+
self.assertFalse(
2934+
Path(self.test_file, "drive_c").exists(),
2935+
f"Expected {self.test_file}/drive_c to not exist",
2936+
)
2937+
29172938
def test_setup_pfx(self):
29182939
"""Test setup_pfx."""
29192940
result = None
@@ -3034,6 +3055,62 @@ def test_parse_args_config(self):
30343055
result, Namespace, "Expected a Namespace from parse_arg"
30353056
)
30363057

3058+
def test_env_nowine_noproton(self):
3059+
"""Test check_env when configured to not use Proton.
3060+
3061+
Expects the directory $HOME/Games/umu/$GAMEID to not be created
3062+
when UMU_NO_PROTON=1 and GAMEID is set in the host environment.
3063+
"""
3064+
result = None
3065+
# Mock $HOME
3066+
mock_home = Path(self.test_file)
3067+
3068+
with (
3069+
ThreadPoolExecutor() as thread_pool,
3070+
# Mock the internal call to Path.home(). Otherwise, some of our
3071+
# assertions may fail when running this test suite locally if
3072+
# the user already has that dir
3073+
patch.object(Path, "home", return_value=mock_home),
3074+
):
3075+
os.environ["UMU_NO_PROTON"] = "1"
3076+
os.environ["GAMEID"] = "foo"
3077+
result = umu_run.check_env(self.env, thread_pool)
3078+
self.assertTrue(result is self.env)
3079+
path = mock_home.joinpath("Games", "umu", os.environ["GAMEID"])
3080+
# Ensure we did not create the target nor its parents up to $HOME
3081+
self.assertFalse(path.exists(), f"Expected {path} to not exist")
3082+
self.assertFalse(
3083+
path.parent.exists(), f"Expected {path.parent} to not exist"
3084+
)
3085+
self.assertFalse(
3086+
path.parent.parent.exists(),
3087+
f"Expected {path.parent.parent} to not exist",
3088+
)
3089+
self.assertTrue(
3090+
mock_home.exists(), f"Expected {mock_home} to exist"
3091+
)
3092+
3093+
def test_env_wine_noproton(self):
3094+
"""Test check_env when configured to not use Proton.
3095+
3096+
Expects the WINE prefix directory to not be created when
3097+
UMU_NO_PROTON=1 and WINEPREFIX is set in the host environment.
3098+
"""
3099+
result = None
3100+
3101+
with (
3102+
ThreadPoolExecutor() as thread_pool,
3103+
):
3104+
os.environ["WINEPREFIX"] = "123"
3105+
os.environ["UMU_NO_PROTON"] = "1"
3106+
os.environ["GAMEID"] = "foo"
3107+
result = umu_run.check_env(self.env, thread_pool)
3108+
self.assertTrue(result is self.env)
3109+
self.assertFalse(
3110+
Path(os.environ["WINEPREFIX"]).exists(),
3111+
f"Expected directory {os.environ['WINEPREFIX']} to not exist",
3112+
)
3113+
30373114
def test_env_proton_nodir(self):
30383115
"""Test check_env when $PROTONPATH in the case we failed to set it.
30393116

0 commit comments

Comments
 (0)