@@ -24,7 +24,7 @@ load(":pip_parse.bzl", _parse = "pip_parse")
2424
2525_tests = []
2626
27- def _pypi_mock_mctx (* modules , os_name = "unittest" , arch_name = "exotic" , environ = {}, read = None ):
27+ def _pypi_mock_mctx (* modules , os_name = "unittest" , arch_name = "exotic" , environ = {}, read = None , mock_files = {} ):
2828 _ = read # @unused
2929 return mocks .mctx (
3030 modules = list (modules ),
@@ -36,7 +36,7 @@ def _pypi_mock_mctx(*modules, os_name = "unittest", arch_name = "exotic", enviro
3636 simple==0.0.1 \
3737 --hash=sha256:deadbeef \
3838 --hash=sha256:deadbaaf""" ,
39- },
39+ } | mock_files ,
4040 )
4141
4242def _default (
@@ -177,6 +177,58 @@ def _test_simple(env):
177177
178178_tests .append (_test_simple )
179179
180+ def _test_pip_parse_pyproject_toml (env ):
181+ # pip.parse() reads the version from pyproject.toml's requires-python when
182+ # python_version is not set explicitly.
183+ pypi = _parse_modules (
184+ env ,
185+ module_ctx = _pypi_mock_mctx (
186+ _mod (
187+ name = "rules_python" ,
188+ parse = [
189+ _parse (
190+ hub_name = "pypi" ,
191+ pyproject_toml = "pyproject.toml" ,
192+ simpleapi_skip = ["simple" ],
193+ requirements_lock = "requirements.txt" ,
194+ ),
195+ ],
196+ ),
197+ os_name = "linux" ,
198+ arch_name = "x86_64" ,
199+ mock_files = {
200+ "pyproject.toml" : "[project]\n requires-python = \" ==3.15.19\" \n " ,
201+ },
202+ ),
203+ available_interpreters = {
204+ "python_3_15_19_host" : "unit_test_interpreter_target" ,
205+ },
206+ minor_mapping = {"3.15" : "3.15.19" },
207+ )
208+
209+ # Resolves identically to passing python_version = "3.15.19" explicitly:
210+ # the full version drives interpreter selection, hub naming uses major.minor.
211+ pypi .exposed_packages ().contains_exactly ({"pypi" : ["simple" ]})
212+ pypi .hub_whl_map ().contains_exactly ({"pypi" : {
213+ "simple" : {
214+ "pypi_315_simple" : [
215+ whl_config_setting (
216+ version = "3.15" ,
217+ ),
218+ ],
219+ },
220+ }})
221+ pypi .whl_libraries ().contains_exactly ({
222+ "pypi_315_simple" : {
223+ "config_load" : "@pypi//:config.bzl" ,
224+ "dep_template" : "@pypi//{name}:{target}" ,
225+ "python_interpreter_target" : "unit_test_interpreter_target" ,
226+ "requirement" : "simple==0.0.1 --hash=sha256:deadbeef --hash=sha256:deadbaaf" ,
227+ },
228+ })
229+
230+ _tests .append (_test_pip_parse_pyproject_toml )
231+
180232def _test_simple_isolated (env ):
181233 """Simulate `isolate = True` with parse_modules.
182234
0 commit comments