Read the pyproject.toml file from the script. Adapted from https://peps.python.org/pep-0723/#reference-implementation
(script: str)
| 22 | |
| 23 | |
| 24 | def read_pyproject_from_script(script: str) -> dict[str, Any] | None: |
| 25 | """ |
| 26 | Read the pyproject.toml file from the script. |
| 27 | |
| 28 | Adapted from https://peps.python.org/pep-0723/#reference-implementation |
| 29 | """ |
| 30 | name = "script" |
| 31 | matches = list( |
| 32 | filter(lambda m: m.group("type") == name, re.finditer(REGEX, script)) |
| 33 | ) |
| 34 | if len(matches) > 1: |
| 35 | raise ValueError(f"Multiple {name} blocks found") |
| 36 | elif len(matches) == 1: |
| 37 | content = "".join( |
| 38 | line[2:] if line.startswith("# ") else line[1:] |
| 39 | for line in matches[0].group("content").splitlines(keepends=True) |
| 40 | ) |
| 41 | |
| 42 | pyproject = toml_reader.reads(content) |
| 43 | return pyproject |
| 44 | else: |
| 45 | return None |
| 46 | |
| 47 | |
| 48 | def write_pyproject_to_script(project: dict[str, Any]) -> str: |
searching dependent graphs…