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(
174174 tool_name : str = DEFAULT_TOOL_NAME ,
175175 canonical_build_package_name : str = "setuptools-scm" ,
176176 _given_result : _t .GivenPyProjectResult = None ,
177+ _given_definition : TOML_RESULT | None = None ,
177178) -> PyProjectData :
178179 """Read and parse pyproject configuration.
179180
@@ -195,7 +196,10 @@ def read_pyproject(
195196 if isinstance (_given_result , (InvalidTomlError , FileNotFoundError )):
196197 raise _given_result
197198
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 )
199203
200204 requires : list [str ] = defn .get ("build-system" , {}).get ("requires" , [])
201205 is_required = has_build_package (requires , canonical_build_package_name )
Original file line number Diff line number Diff line change 11from __future__ import annotations
22
33from pathlib import Path
4+ from unittest .mock import Mock
45
56import pytest
67
@@ -108,3 +109,20 @@ def test_invalid_requirement_string(self) -> None:
108109 assert (
109110 has_build_package_with_extra (requires , "setuptools-scm" , "simple" ) is False
110111 )
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