File: generate-features

package info (click to toggle)
dnspython 2.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,448 kB
  • sloc: python: 34,885; sh: 7; makefile: 4
file content (32 lines) | stat: -rwxr-xr-x 1,074 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python3

# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license

import os
import tomllib

with open("pyproject.toml", "rb") as pp:
    pyproject = tomllib.load(pp)

FEATURES = "dns/_features.py"
NEW_FEATURES = FEATURES + ".new"
skip = False
with open(FEATURES, "r") as input:
    with open(NEW_FEATURES, "w") as output:
        for l in input.readlines():
            l = l.rstrip()
            if l.startswith("    ### BEGIN generated requirements"):
                print(l, file=output)
                for name, deps in pyproject["project"]["optional-dependencies"].items():
                    if name == "dev":
                        continue
                    print(
                        f"    {repr(name)}: {repr(deps)},".replace("'", '"'),
                        file=output,
                    )
                skip = True
            elif l.startswith("    ### END generated requirements"):
                skip = False
            if not skip:
                print(l, file=output)
os.rename(NEW_FEATURES, FEATURES)