diff options
author | Jean-Marie LEMETAYER <jean-marie.lemetayer@savoirfairelinux.com> | 2020-01-24 18:08:04 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2020-01-27 16:44:22 +0000 |
commit | 61ac4e825fa7afbb76282030586abc9ee4ac215c (patch) | |
tree | b90940ad371dec85520e4c8f2c7e6fc25bf91924 /lib/bb/utils.py | |
parent | 80e2216e2b41cb6170292009064864449bc48bbe (diff) | |
download | bitbake-61ac4e825fa7afbb76282030586abc9ee4ac215c.tar.gz |
utils: add is_semver function
This function checks if a string is a semantic version:
https://semver.org/spec/v2.0.0.html
The npm fetcher needs this function to validate its version parameter.
Signed-off-by: Jean-Marie LEMETAYER <jean-marie.lemetayer@savoirfairelinux.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'lib/bb/utils.py')
-rw-r--r-- | lib/bb/utils.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/bb/utils.py b/lib/bb/utils.py index 28368f0a6..47805d02c 100644 --- a/lib/bb/utils.py +++ b/lib/bb/utils.py @@ -1611,3 +1611,29 @@ class LogCatcher(logging.Handler): self.messages.append(bb.build.logformatter.format(record)) def contains(self, message): return (message in self.messages) + +def is_semver(version): + """ + Is the version string following the semver semantic? + + https://semver.org/spec/v2.0.0.html + """ + regex = re.compile( + r""" + ^ + (0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*) + (?:-( + (?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*) + (?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))* + ))? + (?:\+( + [0-9a-zA-Z-]+ + (?:\.[0-9a-zA-Z-]+)* + ))? + $ + """, re.VERBOSE) + + if regex.match(version) is None: + return False + + return True |