@@ -372,22 +372,22 @@ def _whl_repo(*, src, whl_library_args, is_multiple_versions, download_only, net
372
372
),
373
373
)
374
374
375
- def _configure (config , * , platform , os_name , arch_name , override = False , ** values ):
375
+ def _configure (config , * , platform , os_name , arch_name , override = False , env = {} ):
376
376
"""Set the value in the config if the value is provided"""
377
377
config .setdefault ("platforms" , {})
378
378
if platform :
379
379
if not override and config .get ("platforms" , {}).get (platform ):
380
380
return
381
381
382
+ for key in env :
383
+ if key not in _SUPPORTED_PEP508_KEYS :
384
+ fail ("Unsupported key in the PEP508 environment: {}" .format (key ))
385
+
382
386
config ["platforms" ][platform ] = struct (
383
387
name = platform .replace ("-" , "_" ).lower (),
384
388
os_name = os_name ,
385
389
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 ,
391
391
)
392
392
else :
393
393
config ["platforms" ].pop (platform )
@@ -411,9 +411,9 @@ def _create_config(defaults):
411
411
_configure (
412
412
defaults ,
413
413
arch_name = cpu ,
414
- env_platform_version = "0" ,
415
414
os_name = "linux" ,
416
415
platform = "linux_{}" .format (cpu ),
416
+ env = {"platform_version" : "0" },
417
417
)
418
418
for cpu in [
419
419
"aarch64" ,
@@ -424,15 +424,15 @@ def _create_config(defaults):
424
424
arch_name = cpu ,
425
425
# We choose the oldest non-EOL version at the time when we release `rules_python`.
426
426
# See https://endoflife.date/macos
427
- env_platform_version = " 14.0" ,
427
+ env = { "platform_version" : " 14.0"} ,
428
428
os_name = "osx" ,
429
429
platform = "osx_{}" .format (cpu ),
430
430
)
431
431
432
432
_configure (
433
433
defaults ,
434
434
arch_name = "x86_64" ,
435
- env_platform_version = "0" ,
435
+ env = { "platform_version" : "0" } ,
436
436
os_name = "windows" ,
437
437
platform = "windows_x86_64" ,
438
438
)
@@ -500,14 +500,7 @@ You cannot use both the additive_build_content and additive_build_content_file a
500
500
_configure (
501
501
defaults ,
502
502
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 ,
511
504
os_name = tag .os_name ,
512
505
platform = tag .platform ,
513
506
override = mod .is_root ,
@@ -791,7 +784,7 @@ _default_attrs = {
791
784
The CPU architecture name to be used.
792
785
793
786
:::{note}
794
- Either this or {attr}`env_platform_machine` should be specified.
787
+ Either this or {attr}`env` `platform_machine` key should be specified.
795
788
:::
796
789
""" ,
797
790
),
@@ -800,7 +793,7 @@ Either this or {attr}`env_platform_machine` should be specified.
800
793
The OS name to be used.
801
794
802
795
:::{note}
803
- Either this or the appropriate `env_*` attributes should be specified.
796
+ Either this or the appropriate `env` keys should be specified.
804
797
:::
805
798
""" ,
806
799
),
@@ -814,30 +807,37 @@ If you are defining custom platforms in your project and don't want things to cl
814
807
""" ,
815
808
),
816
809
} | {
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
+ """ ,
838
827
),
828
+ # The values for PEP508 env marker evaluation during the lock file parsing
839
829
}
840
830
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
+
841
841
def _pip_parse_ext_attrs (** kwargs ):
842
842
"""Get the attributes for the pip extension.
843
843
0 commit comments