-
Notifications
You must be signed in to change notification settings - Fork 0
/
check-version.py
108 lines (98 loc) · 3.66 KB
/
check-version.py
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/bin/python
# Make sure that all version strings in this repository are consistent.
#
# Authors: Malte J. Ziebarth (ziebarth@gfz-potsdam.de)
#
# Copyright (C) 2022 Malte J. Ziebarth
#
# Licensed under the EUPL, Version 1.2 or – as soon they will be approved by
# the European Commission - subsequent versions of the EUPL (the "Licence");
# You may not use this work except in compliance with the Licence.
# You may obtain a copy of the Licence at:
#
# https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the Licence is distributed on an "AS IS" basis,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the Licence for the specific language governing permissions and
# limitations under the Licence.
# Version in README.md:
version_readme = None
with open('README.md','r') as f:
state = 0
for line in f:
if state == 0:
# Scroll until changelog:
if line[:-1] == "## Changelog":
state = 1
elif state == 1:
# Find the first version:
if line[:16] == "### [Unreleased]":
continue
if line[:5] == "### [":
version_readme = line[5:].split(']')[0]
break
# Version in setup.py:
version_toml = None
with open('pyproject.toml','r') as f:
state = 0
for line in f:
if state == 0:
# Find the [project] tag:
if line[:-1] == "[project]":
state = 1
elif state == 1:
stripped = line.strip()
if stripped[:10] == "version = ":
quote = stripped[10]
version_toml = stripped.split(quote)[1]
break
# Version in the Sphinx documentation:
version_sphinx = None
with open('docs/conf.py','r') as f:
for line in f:
stripped = line.strip()
if stripped[:10] == "release = ":
quote = stripped[10]
version_sphinx = stripped.split(quote)[1]
# Version in the Meson build file:
version_meson = None
with open('meson.build','r') as f:
openparen = 0
closeparen = 0
found_project = False
for line in f:
stripped = line.strip()
if not found_project:
if stripped[:8] == 'project(':
found_project = True
if found_project:
if 'version :' in stripped:
version_meson = stripped.split('version :')[1]\
.split(',')[0].split(')')[0]
version_meson = version_meson.split('\'')[1]
openparen += stripped.count('(')
closeparen += stripped.count(')')
if openparen == closeparen:
break
# Check if any could not be determined:
if version_readme is None:
raise RuntimeError("Version in 'README.md' could not be determined.")
if version_toml is None:
raise RuntimeError("Version in 'pyproject.toml' could not be determined.")
if version_sphinx is None:
raise RuntimeError("Version in 'docs/conf.py' could not be determined.")
if version_meson is None:
raise RuntimeError("Version in 'meson.build' could not be determined.")
# Compare:
if version_readme != version_toml:
raise RuntimeError("Versions given in 'README.md' and 'pyproject.toml' "
"differ.")
if version_readme != version_sphinx:
raise RuntimeError("Versions given in 'README.md' and 'docs/conf.py' "
"differ.")
if version_readme != version_meson:
raise RuntimeError("Versions given in 'README.md' and 'meson.build' "
"differ.")
print("All four versions agree:", version_readme)