22
22
from .environment import EnvironmentParseError , ParsedEnvironment , parse_environment
23
23
from .logger import log
24
24
from .oci_container import OCIContainerEngineConfig
25
- from .projectfiles import get_requires_python_str
25
+ from .projectfiles import get_requires_python_str , resolve_dependency_groups
26
26
from .typing import PLATFORMS , PlatformName
27
27
from .util import (
28
28
MANYLINUX_ARCHS ,
@@ -92,6 +92,7 @@ class BuildOptions:
92
92
before_test : str | None
93
93
test_requires : list [str ]
94
94
test_extras : str
95
+ test_groups : list [str ]
95
96
build_verbosity : int
96
97
build_frontend : BuildFrontendConfig | None
97
98
config_settings : str
@@ -550,6 +551,8 @@ def get(
550
551
551
552
552
553
class Options :
554
+ pyproject_toml : dict [str , Any ] | None
555
+
553
556
def __init__ (
554
557
self ,
555
558
platform : PlatformName ,
@@ -568,6 +571,13 @@ def __init__(
568
571
disallow = DISALLOWED_OPTIONS ,
569
572
)
570
573
574
+ self .package_dir = Path (command_line_arguments .package_dir )
575
+ try :
576
+ with self .package_dir .joinpath ("pyproject.toml" ).open ("rb" ) as f :
577
+ self .pyproject_toml = tomllib .load (f )
578
+ except FileNotFoundError :
579
+ self .pyproject_toml = None
580
+
571
581
@property
572
582
def config_file_path (self ) -> Path | None :
573
583
args = self .command_line_arguments
@@ -584,8 +594,7 @@ def config_file_path(self) -> Path | None:
584
594
585
595
@functools .cached_property
586
596
def package_requires_python_str (self ) -> str | None :
587
- args = self .command_line_arguments
588
- return get_requires_python_str (Path (args .package_dir ))
597
+ return get_requires_python_str (self .package_dir , self .pyproject_toml )
589
598
590
599
@property
591
600
def globals (self ) -> GlobalOptions :
@@ -672,6 +681,11 @@ def build_options(self, identifier: str | None) -> BuildOptions:
672
681
"test-requires" , option_format = ListFormat (sep = " " )
673
682
).split ()
674
683
test_extras = self .reader .get ("test-extras" , option_format = ListFormat (sep = "," ))
684
+ test_groups_str = self .reader .get ("test-groups" , option_format = ListFormat (sep = " " ))
685
+ test_groups = [x for x in test_groups_str .split () if x ]
686
+ test_requirements_from_groups = resolve_dependency_groups (
687
+ self .pyproject_toml , * test_groups
688
+ )
675
689
build_verbosity_str = self .reader .get ("build-verbosity" )
676
690
677
691
build_frontend_str = self .reader .get (
@@ -771,8 +785,9 @@ def build_options(self, identifier: str | None) -> BuildOptions:
771
785
return BuildOptions (
772
786
globals = self .globals ,
773
787
test_command = test_command ,
774
- test_requires = test_requires ,
788
+ test_requires = [ * test_requires , * test_requirements_from_groups ] ,
775
789
test_extras = test_extras ,
790
+ test_groups = test_groups ,
776
791
before_test = before_test ,
777
792
before_build = before_build ,
778
793
before_all = before_all ,
0 commit comments