Skip to content

Commit 5897f01

Browse files
fix(constants): use cwd for project cache path in PyInstaller/frozen mode (#720)
1 parent 0604791 commit 5897f01

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

tests/test_constants.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33

44
from webdriver_manager.core.constants import ROOT_FOLDER_NAME, get_default_user_home_cache_path
5+
from webdriver_manager.core.constants import get_default_project_root_cache_path
56

67

78
def test_default_user_home_cache_path_falls_back_to_temp_if_home_is_root(monkeypatch):
@@ -18,3 +19,13 @@ def test_default_user_home_cache_path_falls_back_to_temp_if_home_is_unresolved(m
1819
cache_path = get_default_user_home_cache_path()
1920

2021
assert cache_path == os.path.join(tempfile.gettempdir(), ROOT_FOLDER_NAME)
22+
23+
24+
def test_default_project_root_cache_path_uses_cwd_for_frozen_app(monkeypatch):
25+
monkeypatch.setattr("sys.path", ["C:/app/base_library.zip"])
26+
monkeypatch.setattr("sys.frozen", True, raising=False)
27+
monkeypatch.setattr("os.getcwd", lambda: "C:/app/runtime")
28+
29+
cache_path = get_default_project_root_cache_path()
30+
31+
assert cache_path == os.path.join("C:/app/runtime", ROOT_FOLDER_NAME)

webdriver_manager/core/constants.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,16 @@
33
import tempfile
44

55
ROOT_FOLDER_NAME = ".wdm"
6-
DEFAULT_PROJECT_ROOT_CACHE_PATH = os.path.join(sys.path[0], ROOT_FOLDER_NAME)
6+
7+
8+
def get_default_project_root_cache_path():
9+
base_path = sys.path[0]
10+
if getattr(sys, "frozen", False) or base_path.endswith(".zip"):
11+
base_path = os.getcwd()
12+
return os.path.join(base_path, ROOT_FOLDER_NAME)
13+
14+
15+
DEFAULT_PROJECT_ROOT_CACHE_PATH = get_default_project_root_cache_path()
716

817

918
def get_default_user_home_cache_path():

0 commit comments

Comments
 (0)