@@ -97,7 +97,7 @@ class BuildOptions:
97
97
repair_command : str
98
98
manylinux_images : dict [str , str ] | None
99
99
musllinux_images : dict [str , str ] | None
100
- dependency_constraints : DependencyConstraints | None
100
+ dependency_constraints : DependencyConstraints
101
101
test_command : str | None
102
102
before_test : str | None
103
103
test_sources : list [str ]
@@ -591,6 +591,10 @@ def __init__(
591
591
except FileNotFoundError :
592
592
self .pyproject_toml = None
593
593
594
+ # cache the build options method so repeated calls don't need to
595
+ # resolve the options again
596
+ self .build_options = functools .cache (self ._compute_build_options )
597
+
594
598
@functools .cached_property
595
599
def config_file_path (self ) -> Path | None :
596
600
args = self .command_line_arguments
@@ -667,9 +671,11 @@ def globals(self) -> GlobalOptions:
667
671
allow_empty = allow_empty ,
668
672
)
669
673
670
- def build_options (self , identifier : str | None ) -> BuildOptions :
674
+ def _compute_build_options (self , identifier : str | None ) -> BuildOptions :
671
675
"""
672
- Compute BuildOptions for a single run configuration.
676
+ Compute BuildOptions for a single run configuration. Normally accessed
677
+ through the `build_options` method, which is the same but the result
678
+ is cached.
673
679
"""
674
680
675
681
with self .reader .identifier (identifier ):
@@ -687,7 +693,6 @@ def build_options(self, identifier: str | None) -> BuildOptions:
687
693
"config-settings" , option_format = ShlexTableFormat (sep = " " , pair_sep = "=" )
688
694
)
689
695
690
- dependency_versions = self .reader .get ("dependency-versions" )
691
696
test_command = self .reader .get ("test-command" , option_format = ListFormat (sep = " && " ))
692
697
before_test = self .reader .get ("before-test" , option_format = ListFormat (sep = " && " ))
693
698
test_sources = shlex .split (
@@ -733,15 +738,18 @@ def build_options(self, identifier: str | None) -> BuildOptions:
733
738
with contextlib .suppress (KeyError ):
734
739
environment .add (env_var_name , self .env [env_var_name ], prepend = True )
735
740
736
- if dependency_versions == "pinned" :
737
- dependency_constraints : DependencyConstraints | None = (
738
- DependencyConstraints .with_defaults ()
741
+ dependency_versions_str = self .reader .get (
742
+ "dependency-versions" ,
743
+ env_plat = True ,
744
+ option_format = ShlexTableFormat (sep = "; " , pair_sep = ":" , allow_merge = False ),
745
+ )
746
+ try :
747
+ dependency_constraints = DependencyConstraints .from_config_string (
748
+ dependency_versions_str
739
749
)
740
- elif dependency_versions == "latest" :
741
- dependency_constraints = None
742
- else :
743
- dependency_versions_path = Path (dependency_versions )
744
- dependency_constraints = DependencyConstraints (dependency_versions_path )
750
+ except (ValueError , OSError ) as e :
751
+ msg = f"Failed to parse dependency versions. { e } "
752
+ raise errors .ConfigurationError (msg ) from e
745
753
746
754
if test_extras :
747
755
test_extras = f"[{ test_extras } ]"
0 commit comments