Skip to content

Commit c2f7caf

Browse files
remove the missing_file_ok hack and use exception handling instead
1 parent 6c335cd commit c2f7caf

File tree

6 files changed

+12
-33
lines changed

6 files changed

+12
-33
lines changed

src/setuptools_scm/_config.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,6 @@ def from_file(
270270
cls,
271271
name: str | os.PathLike[str] = "pyproject.toml",
272272
dist_name: str | None = None,
273-
missing_file_ok: bool = False,
274273
pyproject_data: PyProjectData | None = None,
275274
**kwargs: Any,
276275
) -> Configuration:
@@ -282,15 +281,11 @@ def from_file(
282281
Parameters:
283282
- name: path to pyproject.toml
284283
- dist_name: name of the distribution
285-
- missing_file_ok: if True, do not raise an error if the file is not found
286284
- **kwargs: additional keyword arguments to pass to the Configuration constructor
287285
"""
288286

289287
if pyproject_data is None:
290-
pyproject_data = _read_pyproject(
291-
Path(name),
292-
missing_file_ok=missing_file_ok,
293-
)
288+
pyproject_data = _read_pyproject(Path(name))
294289
args = _get_args_for_pyproject(pyproject_data, dist_name, kwargs)
295290

296291
args.update(read_toml_overrides(args["dist_name"]))

src/setuptools_scm/_integration/pyproject_reading.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,11 @@ def read_pyproject(
126126
path: Path = Path("pyproject.toml"),
127127
tool_name: str = "setuptools_scm",
128128
canonical_build_package_name: str = "setuptools-scm",
129-
missing_file_ok: bool = False,
130129
) -> PyProjectData:
131130
try:
132131
defn = read_toml_content(path)
133132
except FileNotFoundError:
134-
if missing_file_ok:
135-
log.warning("File %s not found, using empty configuration", path)
136-
return PyProjectData.empty(path=path, tool_name=tool_name)
137-
else:
138-
raise
133+
raise
139134

140135
requires: list[str] = defn.get("build-system", {}).get("requires", [])
141136
is_required = has_build_package(requires, canonical_build_package_name)

src/setuptools_scm/_integration/setuptools.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import logging
44
import warnings
55

6+
from pathlib import Path
67
from typing import Any
78
from typing import Callable
89

@@ -90,7 +91,12 @@ def version_keyword(
9091
pyproject_data = _given_pyproject_data
9192
else:
9293
try:
93-
pyproject_data = read_pyproject(missing_file_ok=True)
94+
pyproject_data = read_pyproject()
95+
except FileNotFoundError:
96+
log.debug("pyproject.toml not found, proceeding with empty configuration")
97+
pyproject_data = PyProjectData.empty(
98+
Path("pyproject.toml"), "setuptools_scm"
99+
)
94100
except (LookupError, ValueError) as e:
95101
log.debug("Configuration issue in pyproject.toml: %s", e)
96102
return

src/setuptools_scm/_integration/version_inference.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ def apply(self, dist: Any) -> None:
3737
config = _config_module.Configuration.from_file(
3838
dist_name=self.dist_name,
3939
pyproject_data=self.pyproject_data,
40-
missing_file_ok=True,
4140
**(self.overrides or {}),
4241
)
4342

testing/test_integration.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,6 @@ def test_missing_section_no_longer_raises_error(
910910
config = Configuration.from_file(
911911
name=wd.cwd.joinpath("pyproject.toml"),
912912
dist_name="test-package",
913-
missing_file_ok=False,
914913
)
915914

916915
# Should have created a valid configuration with default values

testing/test_pyproject_reading.py

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,10 @@
1010
class TestPyProjectReading:
1111
"""Test the pyproject reading functionality."""
1212

13-
def test_read_pyproject_missing_file_ok(self, tmp_path: Path) -> None:
14-
"""Test that read_pyproject handles missing files when missing_file_ok=True."""
15-
# Test with missing_file_ok=True
16-
result = read_pyproject(
17-
path=tmp_path / "nonexistent.toml", missing_file_ok=True
18-
)
19-
20-
assert result.path == tmp_path / "nonexistent.toml"
21-
assert result.tool_name == "setuptools_scm"
22-
assert result.project == {}
23-
assert result.section == {}
24-
assert result.is_required is False
25-
assert result.section_present is False
26-
assert result.project_present is False
27-
28-
def test_read_pyproject_missing_file_not_ok(self, tmp_path: Path) -> None:
29-
"""Test that read_pyproject raises FileNotFoundError when missing_file_ok=False."""
13+
def test_read_pyproject_missing_file_raises(self, tmp_path: Path) -> None:
14+
"""Test that read_pyproject raises FileNotFoundError when file is missing."""
3015
with pytest.raises(FileNotFoundError):
31-
read_pyproject(path=tmp_path / "nonexistent.toml", missing_file_ok=False)
16+
read_pyproject(path=tmp_path / "nonexistent.toml")
3217

3318
def test_read_pyproject_existing_file(self, tmp_path: Path) -> None:
3419
"""Test that read_pyproject reads existing files correctly."""

0 commit comments

Comments
 (0)