| 1 |
#!/usr/bin/env python3 |
| 2 |
|
| 3 |
# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license |
| 4 |
|
| 5 |
import os |
| 6 |
import tomllib |
| 7 |
|
| 8 |
with open("pyproject.toml", "rb") as pp: |
| 9 |
pyproject = tomllib.load(pp) |
| 10 |
|
| 11 |
|
| 12 |
def maybe_simplify(dep: str): |
| 13 |
i = dep.find(";") |
| 14 |
if i >= 0: |
| 15 |
return dep[:i] |
| 16 |
else: |
| 17 |
return dep |
| 18 |
|
| 19 |
|
| 20 |
FEATURES = "dns/_features.py" |
| 21 |
NEW_FEATURES = FEATURES + ".new" |
| 22 |
skip = False |
| 23 |
with open(FEATURES, "r") as input: |
| 24 |
with open(NEW_FEATURES, "w") as output: |
| 25 |
for l in input.readlines(): |
| 26 |
l = l.rstrip() |
| 27 |
if l.startswith(" ### BEGIN generated requirements"): |
| 28 |
print(l, file=output) |
| 29 |
for name, deps in pyproject["project"]["optional-dependencies"].items(): |
| 30 |
if name == "dev": |
| 31 |
continue |
| 32 |
deps = [maybe_simplify(dep) for dep in deps] |
| 33 |
print( |
| 34 |
f" {repr(name)}: {repr(deps)},", |
| 35 |
file=output, |
| 36 |
) |
| 37 |
skip = True |
| 38 |
elif l.startswith(" ### END generated requirements"): |
| 39 |
skip = False |
| 40 |
if not skip: |
| 41 |
print(l, file=output) |
| 42 |
os.rename(NEW_FEATURES, FEATURES) |