Skip to content

Commit 9d4e67e

Browse files
remove the missing section km parameter
1 parent 9f6796e commit 9d4e67e

File tree

5 files changed

+21
-41
lines changed

5 files changed

+21
-41
lines changed

src/setuptools_scm/_config.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -271,30 +271,24 @@ def from_file(
271271
name: str | os.PathLike[str] = "pyproject.toml",
272272
dist_name: str | None = None,
273273
missing_file_ok: bool = False,
274-
missing_section_ok: bool = False,
275274
pyproject_data: PyProjectData | None = None,
276275
**kwargs: Any,
277276
) -> Configuration:
278277
"""
279278
Read Configuration from pyproject.toml (or similar).
280279
Raises exceptions when file is not found or toml is
281-
not installed or the file has invalid format or does
282-
not contain setuptools_scm configuration (either via
283-
_ [tool.setuptools_scm] section or build-system.requires).
280+
not installed or the file has invalid format.
284281
285282
Parameters:
286283
- name: path to pyproject.toml
287284
- dist_name: name of the distribution
288285
- missing_file_ok: if True, do not raise an error if the file is not found
289-
- missing_section_ok: if True, do not raise an error if the section is not found
290-
(workaround for not walking the dependency graph when figuring out if setuptools_scm is a dependency)
291286
- **kwargs: additional keyword arguments to pass to the Configuration constructor
292287
"""
293288

294289
if pyproject_data is None:
295290
pyproject_data = _read_pyproject(
296291
Path(name),
297-
missing_section_ok=missing_section_ok,
298292
missing_file_ok=missing_file_ok,
299293
)
300294
args = _get_args_for_pyproject(pyproject_data, dist_name, kwargs)

src/setuptools_scm/_integration/pyproject_reading.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ def read_pyproject(
114114
path: Path = Path("pyproject.toml"),
115115
tool_name: str = "setuptools_scm",
116116
canonical_build_package_name: str = "setuptools-scm",
117-
missing_section_ok: bool = False,
118117
missing_file_ok: bool = False,
119118
) -> PyProjectData:
120119
try:
@@ -140,21 +139,11 @@ def read_pyproject(
140139
try:
141140
section = defn.get("tool", {})[tool_name]
142141
section_present = True
143-
except LookupError as e:
144-
if not is_required and not missing_section_ok:
145-
# Enhanced error message that mentions both configuration options
146-
error = (
147-
f"{path} does not contain a tool.{tool_name} section. "
148-
f"setuptools_scm requires configuration via either:\n"
149-
f" 1. [tool.{tool_name}] section in {path}, or\n"
150-
f" 2. {tool_name} (or setuptools-scm) in [build-system] requires"
151-
)
152-
raise LookupError(error) from e
153-
else:
154-
error = f"{path} does not contain a tool.{tool_name} section"
155-
log.warning("toml section missing %r", error, exc_info=True)
156-
section = {}
157-
section_present = False
142+
except LookupError:
143+
error = f"{path} does not contain a tool.{tool_name} section"
144+
log.warning("toml section missing %r", error, exc_info=True)
145+
section = {}
146+
section_present = False
158147

159148
project = defn.get("project", {})
160149
project_present = "project" in defn

src/setuptools_scm/_integration/setuptools.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,7 @@ def version_keyword(
9090
pyproject_data = _given_pyproject_data
9191
else:
9292
try:
93-
pyproject_data = read_pyproject(
94-
missing_section_ok=True, missing_file_ok=True
95-
)
93+
pyproject_data = read_pyproject(missing_file_ok=True)
9694
except (LookupError, ValueError) as e:
9795
log.debug("Configuration issue in pyproject.toml: %s", e)
9896
return
@@ -126,7 +124,7 @@ def infer_version(
126124
pyproject_data = _given_pyproject_data
127125
else:
128126
try:
129-
pyproject_data = read_pyproject(missing_section_ok=True)
127+
pyproject_data = read_pyproject()
130128
except FileNotFoundError:
131129
log.debug("pyproject.toml not found, skipping infer_version")
132130
return

src/setuptools_scm/_integration/version_inference.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ def apply(self, dist: Any) -> None:
3838
dist_name=self.dist_name,
3939
pyproject_data=self.pyproject_data,
4040
missing_file_ok=True,
41-
missing_section_ok=True,
4241
**(self.overrides or {}),
4342
)
4443

testing/test_integration.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -881,10 +881,10 @@ def test_build_requires_integration_with_config_reading(wd: WorkDir) -> None:
881881
assert config.dist_name == "test-package"
882882

883883

884-
def test_improved_error_message_mentions_both_config_options(
884+
def test_missing_section_no_longer_raises_error(
885885
wd: WorkDir, monkeypatch: pytest.MonkeyPatch
886886
) -> None:
887-
"""Test that the error message mentions both configuration options"""
887+
"""Test that missing [tool.setuptools_scm] section no longer raises error, creates valid config"""
888888
if sys.version_info < (3, 11):
889889
pytest.importorskip("tomli")
890890

@@ -904,18 +904,18 @@ def test_improved_error_message_mentions_both_config_options(
904904

905905
from setuptools_scm._config import Configuration
906906

907-
with pytest.raises(LookupError) as exc_info:
908-
Configuration.from_file(
909-
name=wd.cwd.joinpath("pyproject.toml"),
910-
dist_name="test-package",
911-
missing_file_ok=False,
912-
)
907+
# This should no longer raise an error - instead it should create a valid configuration
908+
# with default values and log a warning
909+
config = Configuration.from_file(
910+
name=wd.cwd.joinpath("pyproject.toml"),
911+
dist_name="test-package",
912+
missing_file_ok=False,
913+
)
913914

914-
error_msg = str(exc_info.value)
915-
# Check that the error message mentions both configuration options
916-
assert "tool.setuptools_scm" in error_msg
917-
assert "build-system" in error_msg
918-
assert "requires" in error_msg
915+
# Should have created a valid configuration with default values
916+
assert config.dist_name == "test-package"
917+
assert config.version_scheme == "guess-next-dev" # default
918+
assert config.local_scheme == "node-and-date" # default
919919

920920

921921
# Helper function for creating and managing distribution objects

0 commit comments

Comments
 (0)