(script: str)
| 147 | |
| 148 | |
| 149 | def _parse_script_metadata(script: str) -> ScriptMetadata: |
| 150 | blocks = [(m.group("type"), m.group("content")) for m in _SCRIPT_METADATA_RE.finditer(script)] |
| 151 | script_blocks = [(t, c) for t, c in blocks if t == "script"] |
| 152 | if len(script_blocks) > 1: |
| 153 | msg = "multiple [script] metadata blocks found in script" |
| 154 | raise ValueError(msg) |
| 155 | if not script_blocks: |
| 156 | return ScriptMetadata() |
| 157 | content = script_blocks[0][1] |
| 158 | stripped = "".join( |
| 159 | line[2:] if len(line) > 1 and line[1] == " " else line[1:] for line in content.splitlines(keepends=True) |
| 160 | ) |
| 161 | metadata = tomllib.loads(stripped) |
| 162 | return ScriptMetadata( |
| 163 | requires_python=metadata.get("requires-python"), |
| 164 | dependencies=metadata.get("dependencies", []), |
| 165 | ) |
| 166 | |
| 167 | |
| 168 | __all__ = [ |
no test coverage detected
searching dependent graphs…