Debian Codegraph @

tasks/build_/_version.py

raw symbols SCIP
1 # -*- coding: ascii -*-
2 #
3 # Copyright 2007 - 2025
4 # Andr\xe9 Malo or his licensors, as applicable
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 """
18 Release code
19 ~~~~~~~~~~~~
20
21 """
22
23 import errno as _errno
24 import os as _os
25
26
27 def update(ctx):
28 """Update version in relevant places"""
29 version = ctx.run("python setup.py --version", hide=True).stdout.strip()
30
31 _userdoc(ctx, version)
32 _download(ctx, version)
33 _changes(ctx, version)
34
35
36 def _userdoc(ctx, version):
37 """Update version in userdoc"""
38 short = ".".join(version.split(".")[:2])
39 conf = _os.path.join(ctx.doc.sphinx.source, "conf.py")
40
41 with open(conf, "rb") as fp:
42 lines = fp.read().decode("latin-1").splitlines(True)
43
44 seen = set()
45 with open(conf, "wb") as fp:
46 for line in lines:
47 if line.startswith("version"):
48 line = "version = %r\n" % (short,)
49 seen.add("version")
50 elif line.startswith("release"):
51 line = "release = %r\n" % (version,)
52 seen.add("release")
53 fp.write(line.encode("latin-1"))
54
55 assert len(seen) == 2, "version/release not found in userdoc/conf.py"
56
57
58 def _download(ctx, version): # noqa
59 """Update version in download files"""
60 # pylint: disable = too-many-branches, too-many-statements
61
62 filename = _os.path.join(ctx.doc.sphinx.source, "website_download.txt")
63 isdev = "dev" in version
64
65 dllines, dlpath = [], ""
66 if isdev:
67 oldstable, hasstable = [], False
68 try:
69 with open(filename, "rb") as fp:
70 lines = fp.read().decode("latin-1").splitlines(True)
71 except IOError as e:
72 if e.errno != _errno.ENOENT:
73 raise
74 else:
75 for line in lines:
76 if line.startswith(".. begin stable"):
77 hasstable, dllines = True, oldstable
78 oldstable.append(line)
79 if not hasstable:
80 dlpath = "dev/"
81
82 newdev = []
83 with open(filename + ".in", "rb") as fp:
84 lines = fp.read().decode("latin-1").splitlines(True)
85 if not dllines:
86 dllines = lines
87 else:
88 for line in lines:
89 if newdev:
90 newdev.append(line)
91 if line.startswith(".. end dev"):
92 break
93 elif line.startswith(".. begin dev"):
94 newdev.append(line)
95 else:
96 ctx.fail(
97 "Incomplete/missing dev marker in %s" % (filename + ".in",)
98 )
99
100 instable, indev = [], []
101 with open(filename, "wb") as fp:
102 for line in dllines:
103 if instable:
104 instable.append(line)
105 if line.startswith(".. end stable"):
106 if isdev:
107 res = "".join(instable) if hasstable else ""
108 else:
109 res = (
110 "".join(instable)
111 .replace("@@VERSION@@", version)
112 .replace("@@PATH@@", "")
113 )
114 fp.write(res.encode("latin-1"))
115 instable = []
116 elif indev:
117 indev.append(line)
118 if line.startswith(".. end dev"):
119 if not isdev:
120 res = "".join([indev[0], indev[-1]])
121 else:
122 res = (
123 "".join(newdev or indev)
124 .replace("@@DEVVERSION@@", version)
125 .replace("@@PATH@@", "dev/")
126 )
127 fp.write(res.encode("latin-1"))
128 indev = []
129 elif line.startswith(".. begin stable"):
130 instable.append(line)
131 elif line.startswith(".. begin dev"):
132 indev.append(line)
133 elif isdev and hasstable:
134 fp.write(line.encode("latin-1"))
135 else:
136 fp.write(
137 line.replace("@@VERSION@@", version)
138 .replace("@@PATH@@", dlpath)
139 .encode("latin-1")
140 )
141
142
143 def _changes(ctx, version):
144 """Update version in CHANGES"""
145 fname = ctx.shell.native("CHANGES")
146 with open(fname, "rb") as fp:
147 lines = fp.read().decode("latin-1").splitlines(True)
148
149 with open(fname, "wb") as fp:
150 for line in lines:
151 if line.rstrip() == "Changes with version":
152 line = "%s %s\n" % (line.rstrip(), version)
153 fp.write(line.encode("latin-1"))