File: version-set.py

package info (click to toggle)
pyglossary 5.0.9-1
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,896 kB
  • sloc: python: 46,165; sh: 308; javascript: 100; xml: 42; makefile: 28
file content (44 lines) | stat: -rwxr-xr-x 1,209 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
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys
from datetime import datetime
from os.path import abspath, dirname, join

from packaging.version import parse


def main():
	version = sys.argv[1]
	parse(version)
	versionQuoted = f'"{version}"'
	rootDir = dirname(dirname(abspath(__file__)))
	replaceVar(join(rootDir, "pyglossary/core.py"), "VERSION", versionQuoted)
	replaceVar(join(rootDir, "setup.py"), "VERSION", versionQuoted)
	replaceVar(join(rootDir, "pyproject.toml"), "version", versionQuoted)

	# update copyright year number
	for fname in ("about", "_license-dialog"):
		with open(fname, encoding="utf-8") as file:
			text = file.read()
		pos = text.find("© ")
		text = text[: pos + 7] + str(datetime.now().year) + text[pos + 11 :]
		with open(fname, "w", encoding="utf-8") as file:
			file.write(text)


def replaceVar(fname: str, name: str, value: str) -> None:
	prefix = name + " = "
	lines = []
	with open(fname, encoding="utf-8") as _file:
		for _line in _file:
			line = _line
			if line.startswith(prefix):
				line = f"{name} = {value}\n"
			lines.append(line)
	with open(fname, mode="w", encoding="utf-8") as _file:
		_file.writelines(lines)


if __name__ == "__main__":
	main()