Skip to content

Commit 62b8d0e

Browse files
committed
allow default language_version of system when homedir is /
1 parent 711248f commit 62b8d0e

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

pre_commit/languages/helpers.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,14 @@ def exe_exists(exe: str) -> bool:
3737
common = None
3838

3939
return (
40-
not SHIMS_RE.search(found) and # it is not in a /shims/ directory
41-
common != homedir # it is not in the home directory
40+
# it is not in a /shims/ directory
41+
not SHIMS_RE.search(found) and
42+
(
43+
# the homedir is / (docker, service user, etc.)
44+
os.path.dirname(homedir) == homedir or
45+
# the exe is not contained in the home directory
46+
common != homedir
47+
)
4248
)
4349

4450

tests/languages/helpers_test.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ def test_exe_exists_commonpath_raises_ValueError(find_exe_mck, homedir_mck):
5555
assert helpers.exe_exists('ruby') is True
5656

5757

58+
def test_exe_exists_true_when_homedir_is_slash(find_exe_mck):
59+
find_exe_mck.return_value = os.path.normpath('/usr/bin/ruby')
60+
with mock.patch.object(os.path, 'expanduser', return_value=os.sep):
61+
assert helpers.exe_exists('ruby') is True
62+
63+
5864
def test_basic_get_default_version():
5965
assert helpers.basic_get_default_version() == C.DEFAULT
6066

0 commit comments

Comments
 (0)