| 
4 | 4 | 
 
  | 
5 | 5 | import dataclasses  | 
6 | 6 | import re  | 
7 |  | -from typing import Dict, List, Optional  | 
 | 7 | +from typing import Dict, List, Optional, Union  | 
8 | 8 | 
 
  | 
9 | 9 | _arch_re = re.compile(r"\{\{\s*ARCH\s*\}\}")  | 
10 | 10 | _os_re = re.compile(r"\{\{\s*OS\s*\}\}")  | 
@@ -60,6 +60,28 @@ class TypeCasterConfig:  | 
60 | 60 |     headers: List[TypeCasterHeader] = dataclasses.field(default_factory=list)  | 
61 | 61 | 
 
  | 
62 | 62 | 
 
  | 
 | 63 | +@dataclasses.dataclass  | 
 | 64 | +class ConditionalHeader:  | 
 | 65 | +    """  | 
 | 66 | +    Allows specifying that a header will only be autogenerated if the specified  | 
 | 67 | +    condition is true.  | 
 | 68 | +
  | 
 | 69 | +    .. code-block:: toml  | 
 | 70 | +
  | 
 | 71 | +        [tool.semiwrap.extension_modules."PACKAGE.NAME".headers]  | 
 | 72 | +        Name = { header="header.h", enable_if = "platform_machine == 'aarch64'" }  | 
 | 73 | +
  | 
 | 74 | +    """  | 
 | 75 | + | 
 | 76 | +    #: Name of the header file  | 
 | 77 | +    header: str  | 
 | 78 | + | 
 | 79 | +    #: This is a PEP 508 environment marker specification.  | 
 | 80 | +    #:  | 
 | 81 | +    #: The header will not be parsed if this does not evaluate to true  | 
 | 82 | +    enable_if: str  | 
 | 83 | + | 
 | 84 | + | 
63 | 85 | @dataclasses.dataclass  | 
64 | 86 | class ExtensionModuleConfig:  | 
65 | 87 |     """  | 
@@ -123,7 +145,9 @@ class ExtensionModuleConfig:  | 
123 | 145 |     #:  | 
124 | 146 |     #: .. seealso:: :ref:`autowrap`  | 
125 | 147 |     #:  | 
126 |  | -    headers: Dict[str, str] = dataclasses.field(default_factory=dict)  | 
 | 148 | +    headers: Dict[str, Union[str, ConditionalHeader]] = dataclasses.field(  | 
 | 149 | +        default_factory=dict  | 
 | 150 | +    )  | 
127 | 151 | 
 
  | 
128 | 152 |     #: Path to a directory of yaml files. Generation data will be looked up  | 
129 | 153 |     #: using the key in the headers dictionary.  | 
 | 
0 commit comments