Skip to content

Commit e749604

Browse files
committed
fix: handle OSErrors when seraching for pyproject.toml
Fixes #6715
1 parent e443977 commit e749604

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

marimo/_config/reader.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ def read_pyproject_marimo_config(
2121
) -> Optional[PartialMarimoConfig]:
2222
"""Read the marimo tool config from a pyproject.toml file."""
2323
pyproject_config = read_toml(pyproject_path)
24-
marimo_tool_config = get_marimo_config_from_pyproject_dict(
25-
pyproject_config
26-
)
24+
marimo_tool_config = get_marimo_config_from_pyproject_dict(pyproject_config)
2725
if marimo_tool_config is None:
2826
return None
2927
LOGGER.info("Found marimo config in pyproject.toml at %s", pyproject_path)
@@ -52,10 +50,13 @@ def find_nearest_pyproject_toml(
5250
"""Find the nearest pyproject.toml file."""
5351
path = Path(start_path)
5452
root = path.anchor
55-
while not path.joinpath("pyproject.toml").exists():
56-
if str(path) == root:
57-
return None
58-
if path.parent == path:
59-
return None
60-
path = path.parent
53+
try:
54+
while not path.joinpath("pyproject.toml").exists():
55+
if str(path) == root:
56+
return None
57+
if path.parent == path:
58+
return None
59+
path = path.parent
60+
except OSError:
61+
return None
6162
return path.joinpath("pyproject.toml")

tests/_config/test_reader.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def test_read_pyproject_config_no_file(tmp_path: Path):
111111
assert nearest_pyproject_toml is None
112112

113113

114-
def testfind_nearest_pyproject_toml():
114+
def test_find_nearest_pyproject_toml():
115115
with tempfile.TemporaryDirectory() as temp_dir:
116116
parent_dir = os.path.join(temp_dir, "parent")
117117
os.makedirs(parent_dir)
@@ -125,12 +125,19 @@ def testfind_nearest_pyproject_toml():
125125
assert result == Path(pyproject_path)
126126

127127

128-
def testfind_nearest_pyproject_toml_not_found():
128+
def test_find_nearest_pyproject_toml_not_found():
129129
with tempfile.TemporaryDirectory() as temp_dir:
130130
result = find_nearest_pyproject_toml(temp_dir)
131131
assert result is None
132132

133133

134+
def test_find_nearest_pyproject_toml_permission_error():
135+
with patch("pathlib.Path.exists") as mock_exists:
136+
mock_exists.side_effect = PermissionError("Permission denied")
137+
result = find_nearest_pyproject_toml("/some/path")
138+
assert result is None
139+
140+
134141
def test_read_toml_invalid_content():
135142
invalid_toml = b"""
136143
[invalid

0 commit comments

Comments
 (0)