From 5de4950fbaa96c1de37900630b140800124d31c6 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sun, 28 Mar 2021 12:28:22 +0100 Subject: [PATCH] Change config.appversion() to return semantic_version.Version As we're changing it to a function at this stage anyway, it might as well return this type, not a str. --- PLUGINS.md | 15 ++++++--------- config.py | 8 ++++---- docs/examples/plugintest/load.py | 16 +++++++--------- killswitch.py | 2 +- update.py | 2 +- 5 files changed, 19 insertions(+), 24 deletions(-) diff --git a/PLUGINS.md b/PLUGINS.md index d80e1e66..7393c439 100644 --- a/PLUGINS.md +++ b/PLUGINS.md @@ -180,26 +180,23 @@ import semantic_version from config import appversion ... + # Up until 5.0.0-beta1 config.appversion is a string if isinstance(appversion, str): - core_version = appversion # Up until 5.0.0-beta1 this is a string + core_version = semantic_version.Version(appversion) elif callable(appversion): - core_version = appversion() # From 5.0.0-beta1 it's a function + # From 5.0.0-beta1 it's a function, returning semantic_version.Version + core_version = appversion() - else: - core_version = '' # Paranoia + # Yes, just blow up if config.appverison is neither str or callable - # Either way you now have a string logger.info(f'Core EDMC version: {core_version}') - # The easiest way to compare is using semantic_version, so convert - core_version_sv = semantic_version.Version(core_version) # And then compare like this - if core_version_sv < semantic_version.Version('5.0.0-beta1'): + if core_version < semantic_version.Version('5.0.0-beta1'): logger.info('EDMC core version is before 5.0.0-beta1') else: logger.info('EDMC core version is at least 5.0.0-beta1') - ``` --- diff --git a/config.py b/config.py index 95fcc78c..54ece308 100644 --- a/config.py +++ b/config.py @@ -126,7 +126,7 @@ def git_shorthash_from_head() -> str: return shorthash -def appversion() -> str: +def appversion() -> semantic_version.Version: """ Determine app version including git short hash if possible. @@ -145,10 +145,10 @@ def appversion() -> str: if shorthash is None: shorthash = 'UNKNOWN' - return f'{_static_appversion}+{shorthash}' + return semantic_version.Version(f'{_static_appversion}+{shorthash}') -def appversion_nobuild() -> str: +def appversion_nobuild() -> semantic_version.Version: """ Determine app version without *any* build meta data. @@ -157,7 +157,7 @@ def appversion_nobuild() -> str: :return: str - App version without any build meta data. """ - return str(semantic_version.Version(appversion()).truncate('prerelease')) + return appversion().truncate('prerelease') ########################################################################### diff --git a/docs/examples/plugintest/load.py b/docs/examples/plugintest/load.py index c5eedd88..9f243d93 100644 --- a/docs/examples/plugintest/load.py +++ b/docs/examples/plugintest/load.py @@ -93,26 +93,24 @@ def plugin_start3(plugin_dir: str) -> str: :param plugin_dir: :return: 'Pretty' name of this plugin. """ + # Up until 5.0.0-beta1 config.appversion is a string if isinstance(appversion, str): - core_version = appversion # Up until 5.0.0-beta1 this is a string + core_version = semantic_version.Version(appversion) elif callable(appversion): - core_version = appversion() # From 5.0.0-beta1 it's a function + # From 5.0.0-beta1 it's a function, returning semantic_version.Version + core_version = appversion() - else: - core_version = '' # Paranoia - - # Either way you now have a string logger.info(f'Core EDMC version: {core_version}') - # The easiest way to compare is using semantic_version, so convert - core_version_sv = semantic_version.Version(core_version) # And then compare like this - if core_version_sv < semantic_version.Version('5.0.0-beta1'): + if core_version < semantic_version.Version('5.0.0-beta1'): logger.info('EDMC core version is before 5.0.0-beta1') else: logger.info('EDMC core version is at least 5.0.0-beta1') + # Yes, just blow up if config.appverison is neither str or callable + logger.info(f'Folder is {plugin_dir}') this.plugin_test = PluginTest(plugin_dir) diff --git a/killswitch.py b/killswitch.py index cb75c2cf..aca020aa 100644 --- a/killswitch.py +++ b/killswitch.py @@ -11,7 +11,7 @@ logger = EDMCLogging.get_main_logger() DEFAULT_KILLSWITCH_URL = 'https://raw.githubusercontent.com/EDCD/EDMarketConnector/releases/killswitches.json' -_current_version: semantic_version.Version = semantic_version.Version(config.appversion_nobuild()) +_current_version: semantic_version.Version = config.appversion_nobuild() class KillSwitch(NamedTuple): diff --git a/update.py b/update.py index e71f39b9..c025609a 100644 --- a/update.py +++ b/update.py @@ -177,7 +177,7 @@ class Updater(object): ) # Look for any remaining version greater than appversion - simple_spec = semantic_version.SimpleSpec('>' + appversion_nobuild()) + simple_spec = semantic_version.SimpleSpec(f'>{appversion_nobuild()}') newversion = simple_spec.select(items.keys()) if newversion: