@@ -1037,33 +1037,28 @@ def test_infer_version_with_build_requires_no_tool_section(
1037
1037
wd : WorkDir , monkeypatch : pytest .MonkeyPatch
1038
1038
) -> None :
1039
1039
"""Test that infer_version works when setuptools-scm is in build_requires but no [tool.setuptools_scm] section"""
1040
- if sys .version_info < (3 , 11 ):
1041
- pytest .importorskip ("tomli" )
1042
-
1043
1040
# Set up a git repository with a tag
1044
1041
wd .commit_testfile ("test" )
1045
1042
wd ("git tag 1.0.0" )
1046
1043
monkeypatch .chdir (wd .cwd )
1047
1044
1048
- # Create a pyproject.toml file with setuptools_scm in build-system.requires but NO [tool.setuptools_scm] section
1049
- pyproject_content = """
1050
- [build-system]
1051
- requires = ["setuptools>=80", "setuptools_scm>=8"]
1052
- build-backend = "setuptools.build_meta"
1053
-
1054
- [project]
1055
- name = "test-package-infer-version"
1056
- dynamic = ["version"]
1057
- """
1058
- wd .write ("pyproject.toml" , pyproject_content )
1059
-
1045
+ from setuptools_scm ._integration .pyproject_reading import PyProjectData
1060
1046
from setuptools_scm ._integration .setuptools import infer_version
1061
1047
1048
+ # Create pyproject data: setuptools_scm required, no tool section, project with dynamic=['version']
1049
+ pyproject_data = PyProjectData .for_testing (
1050
+ is_required = True ,
1051
+ section_present = False ,
1052
+ project_present = True ,
1053
+ project_name = "test-package-infer-version" ,
1054
+ has_dynamic_version = True ,
1055
+ )
1056
+
1062
1057
# Create clean distribution
1063
1058
dist = create_clean_distribution ("test-package-infer-version" )
1064
1059
1065
- # Call infer_version - this should work because setuptools_scm is in build-system.requires
1066
- infer_version (dist )
1060
+ # Call infer_version with direct data injection - no file I/O!
1061
+ infer_version (dist , _given_pyproject_data = pyproject_data )
1067
1062
1068
1063
# Verify that version was set
1069
1064
assert dist .metadata .version is not None
@@ -1077,33 +1072,28 @@ def test_infer_version_with_build_requires_dash_variant_no_tool_section(
1077
1072
wd : WorkDir , monkeypatch : pytest .MonkeyPatch
1078
1073
) -> None :
1079
1074
"""Test that infer_version works when setuptools-scm (dash variant) is in build_requires but no [tool.setuptools_scm] section"""
1080
- if sys .version_info < (3 , 11 ):
1081
- pytest .importorskip ("tomli" )
1082
-
1083
1075
# Set up a git repository with a tag
1084
1076
wd .commit_testfile ("test" )
1085
1077
wd ("git tag 1.0.0" )
1086
1078
monkeypatch .chdir (wd .cwd )
1087
1079
1088
- # Create a pyproject.toml file with setuptools-scm (dash variant) in build-system.requires but NO [tool.setuptools_scm] section
1089
- pyproject_content = """
1090
- [build-system]
1091
- requires = ["setuptools>=80", "setuptools-scm>=8"]
1092
- build-backend = "setuptools.build_meta"
1093
-
1094
- [project]
1095
- name = "test-package-infer-version-dash"
1096
- dynamic = ["version"]
1097
- """
1098
- wd .write ("pyproject.toml" , pyproject_content )
1099
-
1080
+ from setuptools_scm ._integration .pyproject_reading import PyProjectData
1100
1081
from setuptools_scm ._integration .setuptools import infer_version
1101
1082
1083
+ # Create pyproject data: setuptools-scm required, no tool section, project with dynamic=['version']
1084
+ pyproject_data = PyProjectData .for_testing (
1085
+ is_required = True ,
1086
+ section_present = False ,
1087
+ project_present = True ,
1088
+ project_name = "test-package-infer-version-dash" ,
1089
+ has_dynamic_version = True ,
1090
+ )
1091
+
1102
1092
# Create clean distribution
1103
1093
dist = create_clean_distribution ("test-package-infer-version-dash" )
1104
1094
1105
- # Call infer_version - this should work because setuptools-scm is in build-system.requires
1106
- infer_version (dist )
1095
+ # Call infer_version with direct data injection - no file I/O!
1096
+ infer_version (dist , _given_pyproject_data = pyproject_data )
1107
1097
1108
1098
# Verify that version was set
1109
1099
assert dist .metadata .version is not None
@@ -1117,32 +1107,28 @@ def test_infer_version_without_build_requires_no_tool_section_silently_returns(
1117
1107
wd : WorkDir , monkeypatch : pytest .MonkeyPatch
1118
1108
) -> None :
1119
1109
"""Test that infer_version silently returns when setuptools-scm is NOT in build_requires and no [tool.setuptools_scm] section"""
1120
- if sys .version_info < (3 , 11 ):
1121
- pytest .importorskip ("tomli" )
1122
-
1123
1110
# Set up a git repository with a tag
1124
1111
wd .commit_testfile ("test" )
1125
1112
wd ("git tag 1.0.0" )
1126
1113
monkeypatch .chdir (wd .cwd )
1127
1114
1128
- # Create a pyproject.toml file WITHOUT setuptools_scm in build-system.requires and NO [tool.setuptools_scm] section
1129
- pyproject_content = """
1130
- [build-system]
1131
- requires = ["setuptools>=80", "wheel"]
1132
- build-backend = "setuptools.build_meta"
1133
-
1134
- [project]
1135
- name = "test-package-no-scm"
1136
- dynamic = ["version"]
1137
- """
1138
- wd .write ("pyproject.toml" , pyproject_content )
1139
-
1115
+ from setuptools_scm ._integration .pyproject_reading import PyProjectData
1140
1116
from setuptools_scm ._integration .setuptools import infer_version
1141
1117
1118
+ # Create pyproject data: setuptools-scm NOT required, no tool section, project with dynamic=['version']
1119
+ pyproject_data = PyProjectData .for_testing (
1120
+ is_required = False , # This is the key: NOT in build-system.requires
1121
+ section_present = False ,
1122
+ project_present = True ,
1123
+ project_name = "test-package-no-scm" ,
1124
+ has_dynamic_version = True ,
1125
+ )
1126
+
1142
1127
# Create clean distribution
1143
1128
dist = create_clean_distribution ("test-package-no-scm" )
1144
1129
1145
- infer_version (dist )
1130
+ # Call infer_version with direct data injection - should silently return
1131
+ infer_version (dist , _given_pyproject_data = pyproject_data )
1146
1132
assert dist .metadata .version is None
1147
1133
1148
1134
@@ -1154,27 +1140,25 @@ def test_version_keyword_no_scm_dependency_works(
1154
1140
wd ("git tag 1.0.0" )
1155
1141
monkeypatch .chdir (wd .cwd )
1156
1142
1157
- # Create a pyproject.toml file WITHOUT setuptools_scm in build-system.requires
1158
- # and WITHOUT [tool.setuptools_scm] section
1159
- pyproject_content = """
1160
- [build-system]
1161
- requires = ["setuptools>=80"]
1162
- build-backend = "setuptools.build_meta"
1163
-
1164
- [project]
1165
- name = "test-package-no-scm"
1166
- dynamic = ["version"]
1167
- """
1168
- wd .write ("pyproject.toml" , pyproject_content )
1169
-
1170
1143
import setuptools
1171
1144
1145
+ from setuptools_scm ._integration .pyproject_reading import PyProjectData
1172
1146
from setuptools_scm ._integration .setuptools import version_keyword
1173
1147
1148
+ # Create pyproject data: setuptools-scm NOT required, no tool section, project with dynamic=['version']
1149
+ pyproject_data = PyProjectData .for_testing (
1150
+ is_required = False , # This is the key: NOT in build-system.requires
1151
+ section_present = False ,
1152
+ project_present = True ,
1153
+ project_name = "test-package-no-scm" ,
1154
+ has_dynamic_version = True ,
1155
+ )
1156
+
1174
1157
# Create distribution
1175
1158
dist = setuptools .Distribution ({"name" : "test-package-no-scm" })
1176
1159
1177
- version_keyword (dist , "use_scm_version" , True )
1160
+ # Call version_keyword with direct data injection - should work regardless of config
1161
+ version_keyword (dist , "use_scm_version" , True , _given_pyproject_data = pyproject_data )
1178
1162
assert dist .metadata .version == "1.0.0"
1179
1163
1180
1164
@@ -1242,33 +1226,28 @@ def test_infer_version_logs_debug_when_missing_dynamic_version(
1242
1226
wd : WorkDir , monkeypatch : pytest .MonkeyPatch
1243
1227
) -> None :
1244
1228
"""Test that infer_version gracefully handles and logs debug info when setuptools-scm is in build-system.requires but dynamic=['version'] is missing"""
1245
- if sys .version_info < (3 , 11 ):
1246
- pytest .importorskip ("tomli" )
1247
-
1248
1229
# Set up a git repository with a tag
1249
1230
wd .commit_testfile ("test" )
1250
1231
wd ("git tag 1.0.0" )
1251
1232
monkeypatch .chdir (wd .cwd )
1252
1233
1253
- # Create a pyproject.toml file with setuptools-scm in build-system.requires but NO dynamic=['version']
1254
- pyproject_content = """
1255
- [build-system]
1256
- requires = ["setuptools>=80", "setuptools-scm>=8"]
1257
- build-backend = "setuptools.build_meta"
1258
-
1259
- [project]
1260
- name = "test-package-missing-dynamic"
1261
- # Missing: dynamic = ["version"]
1262
- """
1263
- wd .write ("pyproject.toml" , pyproject_content )
1264
-
1234
+ from setuptools_scm ._integration .pyproject_reading import PyProjectData
1265
1235
from setuptools_scm ._integration .setuptools import infer_version
1266
1236
1237
+ # Create pyproject data: setuptools-scm required, project present, but no dynamic=['version']
1238
+ pyproject_data = PyProjectData .for_testing (
1239
+ is_required = True ,
1240
+ section_present = False ,
1241
+ project_present = True ,
1242
+ project_name = "test-package-missing-dynamic" ,
1243
+ has_dynamic_version = False , # This is the key: missing dynamic=['version']
1244
+ )
1245
+
1267
1246
# Create clean distribution
1268
1247
dist = create_clean_distribution ("test-package-missing-dynamic" )
1269
1248
1270
- # This should not raise an error, but should log debug info about the configuration issue
1271
- infer_version (dist )
1249
+ # This should not raise an error, but should silently return ( the configuration issue is handled internally)
1250
+ infer_version (dist , _given_pyproject_data = pyproject_data )
1272
1251
1273
1252
# Verify that version was not set due to configuration issue
1274
1253
assert dist .metadata .version is None
0 commit comments