Skip to content

Commit b8e3f90

Browse files
committed
Update version parsing to allow comments
1 parent e65665e commit b8e3f90

File tree

3 files changed

+30
-19
lines changed

3 files changed

+30
-19
lines changed

VERSION

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
# See PEP 440 for valid version specification
2+
# The following should include only numbers
13
VERSION_MAJOR 0
24
VERSION_MINOR 7
35
VERSION_PATCH 2
4-
VERSION_PRE
5-
VERSION_POST
6-
VERSION_DEV
6+
# The following should include their whole string and can be combined.
7+
# They must be numbered, starting from 0.
8+
VERSION_PRE # Pre release without leading dot, e.g. `a0` (alpha), `b0` (beta), or `rc0` (release candidate)
9+
VERSION_POST # Post release with leading dot, e.g. `.post0`
10+
VERSION_DEV # Dev release with leading dot, e.g. `.dev0`

dev/run.sh

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,22 @@ function test_doc {
231231

232232

233233
function file_version {
234-
local -r file_major="$(awk '/VERSION_MAJOR/{print $2}' "${source_dir}/VERSION")"
235-
local -r file_minor="$(awk '/VERSION_MINOR/{print $2}' "${source_dir}/VERSION")"
236-
local -r file_patch="$(awk '/VERSION_PATCH/{print $2}' "${source_dir}/VERSION")"
237-
local -r file_pre="$(awk '/VERSION_PRE/{print $2}' "${source_dir}/VERSION")"
238-
local -r file_post="$(awk '/VERSION_POST/{print $2}' "${source_dir}/VERSION")"
239-
local -r file_dev="$(awk '/VERSION_DEV/{print $2}' "${source_dir}/VERSION")"
234+
local -r version_text="$(cat "${source_dir}/VERSION")"
235+
236+
function find_version {
237+
local -r version="${1}"
238+
local -r regex="${version}[[:space:]]+(\.?[[:alnum:]]+)"
239+
if [[ "${version_text}" =~ $regex ]]; then
240+
echo "${BASH_REMATCH[1]}"
241+
fi
242+
}
243+
244+
local -r file_major="$(find_version 'VERSION_MAJOR')"
245+
local -r file_minor="$(find_version 'VERSION_MINOR')"
246+
local -r file_patch="$(find_version 'VERSION_PATCH')"
247+
local -r file_pre="$(find_version 'VERSION_PRE')"
248+
local -r file_post="$(find_version 'VERSION_POST')"
249+
local -r file_dev="$(find_version 'VERSION_DEV')"
240250
local version="${file_major:?}.${file_minor:?}.${file_patch:?}"
241251
version+="${file_pre}${file_post}${file_dev}"
242252
echo "${version}"

setup.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,13 @@ def get_file(file: pathlib.Path) -> str:
2020
def get_version(version_file: pathlib.Path) -> str:
2121
"""Extract version from the Ecole VERSION file according to PEP440."""
2222
lines = get_file(version_file)
23-
version_dict = re.search(
24-
r"VERSION_MAJOR\s+(?P<major>\d+)[\s\n]*"
25-
r"VERSION_MINOR\s+(?P<minor>\d+)[\s\n]*"
26-
r"VERSION_PATCH\s+(?P<patch>\d+)[\s\n]*"
27-
r"VERSION_PRE\s+(?P<pre>.*)[\s\n]*"
28-
r"VERSION_POST\s+(?P<post>.*)[\s\n]*"
29-
r"VERSION_DEV\s+(?P<dev>.*)",
30-
lines,
31-
).groupdict()
32-
return "{major}.{minor}.{patch}{pre}{post}{dev}".format(**version_dict)
23+
major = re.search(r"VERSION_MAJOR\s+(\d+)", lines).group(1)
24+
minor = re.search(r"VERSION_MINOR\s+(\d+)", lines).group(1)
25+
patch = re.search(r"VERSION_PATCH\s+(\d+)", lines).group(1)
26+
pre = re.search(r"VERSION_PRE\s+([\.\w]*)", lines).group(1)
27+
post = re.search(r"VERSION_POST\s+([\.\w]*)", lines).group(1)
28+
dev = re.search(r"VERSION_DEV\s+([\.\w]*)", lines).group(1)
29+
return f"{major}.{minor}.{patch}{pre}{post}{dev}"
3330

3431

3532
def get_cmake_args() -> List[str]:

0 commit comments

Comments
 (0)