File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed
src/setuptools_scm/_integration Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -174,6 +174,7 @@ def read_pyproject(
174
174
tool_name : str = DEFAULT_TOOL_NAME ,
175
175
canonical_build_package_name : str = "setuptools-scm" ,
176
176
_given_result : _t .GivenPyProjectResult = None ,
177
+ _given_definition : TOML_RESULT | None = None ,
177
178
) -> PyProjectData :
178
179
"""Read and parse pyproject configuration.
179
180
@@ -195,7 +196,10 @@ def read_pyproject(
195
196
if isinstance (_given_result , (InvalidTomlError , FileNotFoundError )):
196
197
raise _given_result
197
198
198
- defn = read_toml_content (path )
199
+ if _given_definition is not None :
200
+ defn = _given_definition
201
+ else :
202
+ defn = read_toml_content (path )
199
203
200
204
requires : list [str ] = defn .get ("build-system" , {}).get ("requires" , [])
201
205
is_required = has_build_package (requires , canonical_build_package_name )
Original file line number Diff line number Diff line change 1
1
from __future__ import annotations
2
2
3
3
from pathlib import Path
4
+ from unittest .mock import Mock
4
5
5
6
import pytest
6
7
@@ -108,3 +109,20 @@ def test_invalid_requirement_string(self) -> None:
108
109
assert (
109
110
has_build_package_with_extra (requires , "setuptools-scm" , "simple" ) is False
110
111
)
112
+
113
+
114
+ def test_read_pyproject_with_given_definition (monkeypatch : pytest .MonkeyPatch ) -> None :
115
+ """Test that read_pyproject reads existing files correctly."""
116
+ monkeypatch .setattr (
117
+ "setuptools_scm._integration.pyproject_reading.read_toml_content" ,
118
+ Mock (side_effect = FileNotFoundError ("this test should not read" )),
119
+ )
120
+
121
+ res = read_pyproject (
122
+ _given_definition = {
123
+ "build-system" : {"requires" : ["setuptools-scm[simple]" ]},
124
+ "project" : {"name" : "test-package" , "dynamic" : ["version" ]},
125
+ }
126
+ )
127
+
128
+ assert res .should_infer ()
You can’t perform that action at this time.
0 commit comments