@@ -101,3 +101,79 @@ def test_pyproject_fix(
101101 "torch" ,
102102 ],
103103 }
104+
105+
106+ PYPROJECT_MULTIPLE_REQUIRES = """
107+ [build-system]
108+ requires = [
109+ "numpy<2.0; python_version<'3.9'",
110+ "numpy==2.0.2; python_version>='3.9' and python_version<'3.13'",
111+ "numpy==2.1.3; python_version=='3.13'",
112+ "packaging",
113+ "pip",
114+ "scikit-build>=0.14.0",
115+ "setuptools==59.2.0; python_version<'3.12'",
116+ "setuptools<70.0.0; python_version>='3.12'",
117+ ]
118+ """
119+
120+
121+ def test_pyproject_preserve_multiple_requires (tmp_path : pathlib .Path ) -> None :
122+ tmp_path .joinpath ("pyproject.toml" ).write_text (PYPROJECT_MULTIPLE_REQUIRES )
123+ req = Requirement ("testproject==1.0.0" )
124+ fixer = pyproject .PyprojectFix (
125+ req ,
126+ build_dir = tmp_path ,
127+ update_build_requires = ["setuptools" ],
128+ remove_build_requires = [canonicalize_name ("cmake" )],
129+ )
130+ fixer .run ()
131+ with tmp_path .joinpath ("pyproject.toml" ).open (encoding = "utf-8" ) as f :
132+ doc = tomlkit .load (f )
133+ assert isinstance (doc ["build-system" ], typing .Container )
134+ # PyprojectFix parses requirements using packaging.requirements.Requirement and then casts
135+ # to str, this may change white spaces in markers, let's do it here as well
136+ assert dict (doc ["build-system" ].items ())["requires" ] == [
137+ str (Requirement (req ))
138+ for req in [
139+ "numpy<2.0; python_version<'3.9'" ,
140+ "numpy==2.0.2; python_version>='3.9' and python_version<'3.13'" ,
141+ "numpy==2.1.3; python_version=='3.13'" ,
142+ "packaging" ,
143+ "pip" ,
144+ "scikit-build>=0.14.0" ,
145+ "setuptools" ,
146+ ]
147+ ]
148+
149+
150+ def test_pyproject_override_multiple_requires (tmp_path : pathlib .Path ) -> None :
151+ tmp_path .joinpath ("pyproject.toml" ).write_text (PYPROJECT_MULTIPLE_REQUIRES )
152+ req = Requirement ("testproject==1.0.0" )
153+ fixer = pyproject .PyprojectFix (
154+ req ,
155+ build_dir = tmp_path ,
156+ update_build_requires = [
157+ "setuptools" ,
158+ "numpy<3.0.0; python_version=='3.12'" ,
159+ "numpy==3.0.0" ,
160+ ],
161+ remove_build_requires = [canonicalize_name ("cmake" )],
162+ )
163+ fixer .run ()
164+ with tmp_path .joinpath ("pyproject.toml" ).open (encoding = "utf-8" ) as f :
165+ doc = tomlkit .load (f )
166+ assert isinstance (doc ["build-system" ], typing .Container )
167+ # PyprojectFix parses requirements using packaging.requirements.Requirement and then casts
168+ # to str, this may change white spaces in markers, let's do it here as well
169+ assert dict (doc ["build-system" ].items ())["requires" ] == [
170+ str (Requirement (req ))
171+ for req in [
172+ "numpy<3.0.0; python_version=='3.12'" ,
173+ "numpy==3.0.0" ,
174+ "packaging" ,
175+ "pip" ,
176+ "scikit-build>=0.14.0" ,
177+ "setuptools" ,
178+ ]
179+ ]
0 commit comments