@@ -372,22 +372,22 @@ def _whl_repo(*, src, whl_library_args, is_multiple_versions, download_only, net
372372 ),
373373 )
374374
375- def _configure (config , * , platform , os_name , arch_name , override = False , ** values ):
375+ def _configure (config , * , platform , os_name , arch_name , override = False , env = {} ):
376376 """Set the value in the config if the value is provided"""
377377 config .setdefault ("platforms" , {})
378378 if platform :
379379 if not override and config .get ("platforms" , {}).get (platform ):
380380 return
381381
382+ for key in env :
383+ if key not in _SUPPORTED_PEP508_KEYS :
384+ fail ("Unsupported key in the PEP508 environment: {}" .format (key ))
385+
382386 config ["platforms" ][platform ] = struct (
383387 name = platform .replace ("-" , "_" ).lower (),
384388 os_name = os_name ,
385389 arch_name = arch_name ,
386- env = {
387- k [4 :]: v
388- for k , v in values .items ()
389- if k .startswith ("env_" ) and v
390- },
390+ env = env ,
391391 )
392392 else :
393393 config ["platforms" ].pop (platform )
@@ -411,9 +411,9 @@ def _create_config(defaults):
411411 _configure (
412412 defaults ,
413413 arch_name = cpu ,
414- env_platform_version = "0" ,
415414 os_name = "linux" ,
416415 platform = "linux_{}" .format (cpu ),
416+ env = {"platform_version" : "0" },
417417 )
418418 for cpu in [
419419 "aarch64" ,
@@ -424,15 +424,15 @@ def _create_config(defaults):
424424 arch_name = cpu ,
425425 # We choose the oldest non-EOL version at the time when we release `rules_python`.
426426 # See https://endoflife.date/macos
427- env_platform_version = " 14.0" ,
427+ env = { "platform_version" : " 14.0"} ,
428428 os_name = "osx" ,
429429 platform = "osx_{}" .format (cpu ),
430430 )
431431
432432 _configure (
433433 defaults ,
434434 arch_name = "x86_64" ,
435- env_platform_version = "0" ,
435+ env = { "platform_version" : "0" } ,
436436 os_name = "windows" ,
437437 platform = "windows_x86_64" ,
438438 )
@@ -500,14 +500,7 @@ You cannot use both the additive_build_content and additive_build_content_file a
500500 _configure (
501501 defaults ,
502502 arch_name = tag .arch_name ,
503- # The env_ values is only used if the `PIPSTAR` is enabled
504- env_implementation_name = tag .env_implementation_name ,
505- env_os_name = tag .env_os_name ,
506- env_platform_machine = tag .env_platform_machine ,
507- env_platform_release = tag .env_platform_release ,
508- env_platform_system = tag .env_platform_system ,
509- env_platform_version = tag .env_platform_version ,
510- env_sys_platform = tag .env_sys_platform ,
503+ env = tag .env ,
511504 os_name = tag .os_name ,
512505 platform = tag .platform ,
513506 override = mod .is_root ,
@@ -791,7 +784,7 @@ _default_attrs = {
791784 The CPU architecture name to be used.
792785
793786:::{note}
794- Either this or {attr}`env_platform_machine` should be specified.
787+ Either this or {attr}`env` `platform_machine` key should be specified.
795788:::
796789""" ,
797790 ),
@@ -800,7 +793,7 @@ Either this or {attr}`env_platform_machine` should be specified.
800793 The OS name to be used.
801794
802795:::{note}
803- Either this or the appropriate `env_*` attributes should be specified.
796+ Either this or the appropriate `env` keys should be specified.
804797:::
805798""" ,
806799 ),
@@ -814,30 +807,37 @@ If you are defining custom platforms in your project and don't want things to cl
814807""" ,
815808 ),
816809} | {
817- # The values for PEP508 env marker evaluation during the lock file parsing
818- "env_implementation_name" : attr .string (
819- doc = "Value for `implementation_name` to evaluate environment markers. Defaults to `cpython`." ,
820- ),
821- "env_os_name" : attr .string (
822- doc = "Value for `os_name` to evaluate environment markers. Defaults to a value inferred from the {attr}`os_name`." ,
823- ),
824- "env_platform_machine" : attr .string (
825- doc = "Value for `platform_machine` to evaluate environment markers. Defaults to a value inferred from the {attr}`arch_name`." ,
826- ),
827- "env_platform_release" : attr .string (
828- doc = "Value for `platform_machine` to evaluate environment markers. Defaults to an empty value." ,
829- ),
830- "env_platform_system" : attr .string (
831- doc = "Value for `platform_system` to evaluate environment markers. Defaults to a value inferred from the {attr}`os_name`." ,
832- ),
833- "env_platform_version" : attr .string (
834- doc = "Value for `platform_machine` to evaluate environment markers. Defaults to `0`." ,
835- ),
836- "env_sys_platform" : attr .string (
837- doc = "Value for `sys_platform` to evaluate environment markers. Defaults to a value inferred from the {attr}`os_name`." ,
810+ "env" : attr .string_dict (
811+ doc = """\
812+ Values for the PEP508 environment marker evaluation during lock file parsing.
813+
814+ Supported keys:
815+ * `implementation_name`, defaults to `cpython`.
816+ * `os_name`, defaults to a value inferred from the {attr}`os_name`.
817+ * `platform_machine`, defaults to a value inferred from the {attr}`arch_name`.
818+ * `platform_release`, defaults to an empty value.
819+ * `platform_system`, defaults to a value inferred from the {attr}`os_name`.
820+ * `platform_version`, defaults to `0`.
821+ * `sys_platform`, defaults to a value inferred from the {attr}`os_name`.
822+
823+ ::::{note}
824+ This is only used if the {envvar}`RULES_PYTHON_ENABLE_PIPSTAR` is enabled.
825+ ::::
826+ """ ,
838827 ),
828+ # The values for PEP508 env marker evaluation during the lock file parsing
839829}
840830
831+ _SUPPORTED_PEP508_KEYS = [
832+ "implementation_name" ,
833+ "os_name" ,
834+ "platform_machine" ,
835+ "platform_release" ,
836+ "platform_system" ,
837+ "platform_version" ,
838+ "sys_platform" ,
839+ ]
840+
841841def _pip_parse_ext_attrs (** kwargs ):
842842 """Get the attributes for the pip extension.
843843
0 commit comments