@@ -923,6 +923,125 @@ def test_integration_function_call_order(
923923 )
924924
925925
926+ def test_infer_version_with_build_requires_no_tool_section (
927+ wd : WorkDir , monkeypatch : pytest .MonkeyPatch
928+ ) -> None :
929+ """Test that infer_version works when setuptools-scm is in build_requires but no [tool.setuptools_scm] section"""
930+ if sys .version_info < (3 , 11 ):
931+ pytest .importorskip ("tomli" )
932+
933+ # Set up a git repository with a tag
934+ wd .commit_testfile ("test" )
935+ wd ("git tag 1.0.0" )
936+ monkeypatch .chdir (wd .cwd )
937+
938+ # Create a pyproject.toml file with setuptools_scm in build-system.requires but NO [tool.setuptools_scm] section
939+ pyproject_content = """
940+ [build-system]
941+ requires = ["setuptools>=80", "setuptools_scm>=8"]
942+ build-backend = "setuptools.build_meta"
943+
944+ [project]
945+ name = "test-package-infer-version"
946+ dynamic = ["version"]
947+ """
948+ wd .write ("pyproject.toml" , pyproject_content )
949+
950+ import setuptools
951+
952+ from setuptools_scm ._integration .setuptools import infer_version
953+
954+ # Create distribution
955+ dist = setuptools .Distribution ({"name" : "test-package-infer-version" })
956+
957+ # Call infer_version - this should work because setuptools_scm is in build-system.requires
958+ infer_version (dist )
959+
960+ # Verify that version was set
961+ assert dist .metadata .version is not None
962+ assert dist .metadata .version == "1.0.0"
963+
964+ # Verify that the marker was set
965+ assert getattr (dist , "_setuptools_scm_version_set_by_infer" , False ) is True
966+
967+
968+ def test_infer_version_with_build_requires_dash_variant_no_tool_section (
969+ wd : WorkDir , monkeypatch : pytest .MonkeyPatch
970+ ) -> None :
971+ """Test that infer_version works when setuptools-scm (dash variant) is in build_requires but no [tool.setuptools_scm] section"""
972+ if sys .version_info < (3 , 11 ):
973+ pytest .importorskip ("tomli" )
974+
975+ # Set up a git repository with a tag
976+ wd .commit_testfile ("test" )
977+ wd ("git tag 1.0.0" )
978+ monkeypatch .chdir (wd .cwd )
979+
980+ # Create a pyproject.toml file with setuptools-scm (dash variant) in build-system.requires but NO [tool.setuptools_scm] section
981+ pyproject_content = """
982+ [build-system]
983+ requires = ["setuptools>=80", "setuptools-scm>=8"]
984+ build-backend = "setuptools.build_meta"
985+
986+ [project]
987+ name = "test-package-infer-version-dash"
988+ dynamic = ["version"]
989+ """
990+ wd .write ("pyproject.toml" , pyproject_content )
991+
992+ import setuptools
993+
994+ from setuptools_scm ._integration .setuptools import infer_version
995+
996+ # Create distribution
997+ dist = setuptools .Distribution ({"name" : "test-package-infer-version-dash" })
998+
999+ # Call infer_version - this should work because setuptools-scm is in build-system.requires
1000+ infer_version (dist )
1001+
1002+ # Verify that version was set
1003+ assert dist .metadata .version is not None
1004+ assert dist .metadata .version == "1.0.0"
1005+
1006+ # Verify that the marker was set
1007+ assert getattr (dist , "_setuptools_scm_version_set_by_infer" , False ) is True
1008+
1009+
1010+ def test_infer_version_without_build_requires_no_tool_section_silently_returns (
1011+ wd : WorkDir , monkeypatch : pytest .MonkeyPatch
1012+ ) -> None :
1013+ """Test that infer_version silently returns when setuptools-scm is NOT in build_requires and no [tool.setuptools_scm] section"""
1014+ if sys .version_info < (3 , 11 ):
1015+ pytest .importorskip ("tomli" )
1016+
1017+ # Set up a git repository with a tag
1018+ wd .commit_testfile ("test" )
1019+ wd ("git tag 1.0.0" )
1020+ monkeypatch .chdir (wd .cwd )
1021+
1022+ # Create a pyproject.toml file WITHOUT setuptools_scm in build-system.requires and NO [tool.setuptools_scm] section
1023+ pyproject_content = """
1024+ [build-system]
1025+ requires = ["setuptools>=80", "wheel"]
1026+ build-backend = "setuptools.build_meta"
1027+
1028+ [project]
1029+ name = "test-package-no-scm"
1030+ dynamic = ["version"]
1031+ """
1032+ wd .write ("pyproject.toml" , pyproject_content )
1033+
1034+ import setuptools
1035+
1036+ from setuptools_scm ._integration .setuptools import infer_version
1037+
1038+ # Create distribution
1039+ dist = setuptools .Distribution ({"name" : "test-package-no-scm" })
1040+
1041+ infer_version (dist )
1042+ assert dist .metadata .version is None
1043+
1044+
9261045def test_version_keyword_no_scm_dependency_works (
9271046 wd : WorkDir , monkeypatch : pytest .MonkeyPatch
9281047) -> None :
0 commit comments