From e6803060e972ab9ddfda2eca14b9ea89412e9d2e Mon Sep 17 00:00:00 2001 From: Matthew Einhorn Date: Wed, 15 May 2019 23:39:58 -0400 Subject: [PATCH 1/2] Fix require to use regex. --- kivy/__init__.py | 42 +++++++++++++++--------------------------- 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/kivy/__init__.py b/kivy/__init__.py index fb6a252db..710c5454d 100644 --- a/kivy/__init__.py +++ b/kivy/__init__.py @@ -34,6 +34,7 @@ from getopt import getopt, GetoptError from os import environ, mkdir from os.path import dirname, join, basename, exists, expanduser import pkgutil +import re from kivy.compat import PY2 from kivy.logger import Logger, LOG_LEVELS from kivy.utils import platform @@ -82,14 +83,14 @@ def require(version): The Kivy version string is built like this:: - X.Y.Z[-tag[-tagrevision]] + X.Y.Z[tag[tagrevision]] X is the major version Y is the minor version Z is the bugfixes revision - The tag is optional, but may be one of 'dev', 'alpha', or 'beta'. - The tagrevision is the revision of the tag. + The tag is optional, but may be one of '.dev', 'a', 'b', or 'rc'. + The tagrevision is the revision number of the tag. .. warning:: @@ -101,37 +102,24 @@ def require(version): ''' def parse_version(version): - # check for tag - tag = None - tagrev = None - if '-' in version: - v = version.split('-') - if len(v) == 2: - version, tag = v - elif len(v) == 3: - version, tag, tagrev = v - else: - raise Exception('Revision format must be X.Y.Z[-tag]') + m = re.match( + '^([0-9]+)\\.([0-9]+)\\.([0-9]+?)(rc|a|b|\\.dev)?([0-9]+)?$', + version) + if m is None: + raise Exception('Revision format must be X.Y.Z[-tag]') - # check x y z - v = version.split('.') - if len(v) != 3: - if 'dev0' in v: - tag = v.pop() - else: - raise Exception('Revision format must be X.Y.Z[-tag]') - return [int(x) for x in v], tag, tagrev + major, minor, micro, tag, tagrev = m.groups() + if tag == '.dev': + tag = 'dev' + return [int(major), int(minor), int(micro)], tag, tagrev # user version revision, tag, tagrev = parse_version(version) # current version sysrevision, systag, systagrev = parse_version(__version__) - # ensure that the required version don't contain tag, except dev - if tag not in (None, 'dev'): - raise Exception('Revision format must not have any tag except "dev"') - if tag == 'dev' and systag != 'dev': - Logger.warning('Application requested a -dev version of Kivy. ' + if tag and not systag: + Logger.warning('Application requested a dev version of Kivy. ' '(You have %s, but the application requires %s)' % ( __version__, version)) # not tag rev (-alpha-1, -beta-x) allowed. From 9ebad2d19041ddb4094455ffcdd932ce66ec0719 Mon Sep 17 00:00:00 2001 From: Matthew Einhorn Date: Thu, 16 May 2019 00:25:21 -0400 Subject: [PATCH 2/2] Fix CI to accept all kivy version formats. [build wheel] --- .travis.yml | 10 ++++++---- appveyor.yml | 8 +++++--- kivy/__init__.py | 35 ++++++++++++++++++++--------------- 3 files changed, 31 insertions(+), 22 deletions(-) diff --git a/.travis.yml b/.travis.yml index e3cc1f0c9..9842cd230 100644 --- a/.travis.yml +++ b/.travis.yml @@ -170,13 +170,14 @@ script: mkdir wheelhouse; wheel_date=$(python -c "from datetime import datetime; print(datetime.utcnow().strftime('%Y%m%d'))"); git_tag=$(git rev-parse --short HEAD); - wheel_name="dev0.$wheel_date.$git_tag"; + tag_name=$(python -c "import kivy; _, tag, n = kivy.parse_kivy_version(kivy.__version__); print(tag + n) if n is not None else print(tag or 'something')" --config "kivy:log_level:error"); + wheel_name="$tag_name.$wheel_date.$git_tag-"; chmod +x .ci/build-wheels-linux.sh; docker run --rm -v `pwd`:/io $DOCKER_IMAGE "/io/.ci/build-wheels-linux.sh"; ls wheelhouse/; for name in wheelhouse/*manylinux*.whl; do - new_name="${name/dev0/$wheel_name}"; + new_name="${name/$tag_name-/$wheel_name}"; if [ ! -f "$new_name" ]; then cp -n $name $new_name; fi; @@ -282,11 +283,12 @@ script: wheel_date=$(python -c "from datetime import datetime; print(datetime.utcnow().strftime('%Y%m%d'))"); git_tag=$(git rev-parse --short HEAD); - wheel_name="dev0.$wheel_date.$git_tag"; + tag_name=$(python -c "import kivy; _, tag, n = kivy.parse_kivy_version(kivy.__version__); print(tag + n) if n is not None else print(tag or 'something')" --config "kivy:log_level:error"); + wheel_name="$tag_name.$wheel_date.$git_tag-"; ls ../wheelhouse/; for name in ../wheelhouse/*.whl; do - new_name="${name/dev0/$wheel_name}"; + new_name="${name/$tag_name-/$wheel_name}"; if [ ! -f "$new_name" ]; then cp -n "$name" "$new_name"; fi; diff --git a/appveyor.yml b/appveyor.yml index c190174fb..b054753ec 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -127,10 +127,12 @@ build_script: # nightly: Kivy-X.Y.Z.dev0-cpAB-cpABm-ARCH.whl (Kivy_examples-X.Y.Z.dev0-py2.py3-none-any.whl) # archive: Kivy-X.Y.Z.dev0.YYYYMMDD.githash-cpAB-cpABm-ARCH.whl (Kivy_examples-X.Y.Z.dev0.YYYYMMDD.githash-py2.py3-none-any.whl) + $TAG_NAME = python -c "import kivy; _, tag, n = kivy.parse_kivy_version(kivy.__version__); print(tag + n) if n is not None else print(tag or 'something')" --config "kivy:log_level:error" + if ($env:APPVEYOR_REPO_TAG -eq "true"){ - $WHEEL_NAME = "dev0-" + $WHEEL_NAME = "$TAG_NAME-" } elseif (-not $env:APPVEYOR_PULL_REQUEST_NUMBER -and($env:APPVEYOR_SCHEDULED_BUILD -eq "True" -or $env:APPVEYOR_REPO_COMMIT_MESSAGE.Contains("[build wheel]") -or $env:APPVEYOR_REPO_COMMIT_MESSAGE.Contains("[build wheel win]"))){ - $WHEEL_NAME = "dev0.$WHEEL_DATE`.$GIT_TAG-" + $WHEEL_NAME = "$TAG_NAME.$WHEEL_DATE`.$GIT_TAG-" } else { $DO_WHEEL = "False" } @@ -193,7 +195,7 @@ build_script: $files = Get-ChildItem "$env:WHEEL_DIR" *.whl -Name foreach ($WHEEL_DEFAULT in $files){ echo "Wheel file: $env:WHEEL_DIR\$WHEEL_DEFAULT" - $WHEEL_NIGHTLY = $WHEEL_DEFAULT.Replace("dev0-", $WHEEL_NAME) + $WHEEL_NIGHTLY = $WHEEL_DEFAULT.Replace("$TAG_NAME-", $WHEEL_NAME) echo "Nightly file: $env:WHEEL_DIR\$WHEEL_NIGHTLY" Check-Error diff --git a/kivy/__init__.py b/kivy/__init__.py index 710c5454d..0c552ad1f 100644 --- a/kivy/__init__.py +++ b/kivy/__init__.py @@ -20,7 +20,7 @@ See http://kivy.org for more information. ''' __all__ = ( - 'require', + 'require', 'parse_kivy_version', 'kivy_configure', 'kivy_register_post_configuration', 'kivy_options', 'kivy_base_dir', 'kivy_modules_dir', 'kivy_data_dir', 'kivy_shader_dir', @@ -71,6 +71,23 @@ if platform == 'macosx' and sys.maxsize < 9223372036854775807: Logger.critical(r) +def parse_kivy_version(version): + """Parses the kivy version as described in :func:`require` into a 3-tuple + of ([x, y, z], 'rc|a|b|dev', 'N') where N is the tag revision. The last + two elements may be None. + """ + m = re.match( + '^([0-9]+)\\.([0-9]+)\\.([0-9]+?)(rc|a|b|\\.dev)?([0-9]+)?$', + version) + if m is None: + raise Exception('Revision format must be X.Y.Z[-tag]') + + major, minor, micro, tag, tagrev = m.groups() + if tag == '.dev': + tag = 'dev' + return [int(major), int(minor), int(micro)], tag, tagrev + + def require(version): '''Require can be used to check the minimum version required to run a Kivy application. For example, you can start your application code like this:: @@ -101,22 +118,10 @@ def require(version): ''' - def parse_version(version): - m = re.match( - '^([0-9]+)\\.([0-9]+)\\.([0-9]+?)(rc|a|b|\\.dev)?([0-9]+)?$', - version) - if m is None: - raise Exception('Revision format must be X.Y.Z[-tag]') - - major, minor, micro, tag, tagrev = m.groups() - if tag == '.dev': - tag = 'dev' - return [int(major), int(minor), int(micro)], tag, tagrev - # user version - revision, tag, tagrev = parse_version(version) + revision, tag, tagrev = parse_kivy_version(version) # current version - sysrevision, systag, systagrev = parse_version(__version__) + sysrevision, systag, systagrev = parse_kivy_version(__version__) if tag and not systag: Logger.warning('Application requested a dev version of Kivy. '