From 38531382cb2c967b51938eb8864e819eae1dff22 Mon Sep 17 00:00:00 2001 From: chfw Date: Wed, 7 Nov 2018 07:25:37 +0000 Subject: [PATCH 1/5] :egg: :ferris_wheel: release 0.0.6. fix #6 --- CHANGELOG.rst | 8 ++++++++ changelog.yml | 6 ++++++ docs/source/conf.py | 4 ++-- lml.yml | 6 +++--- lml/_version.py | 2 +- lml/utils.py | 18 +++++++----------- setup.py | 12 +++++++----- tests/test_utils.py | 5 +++-- 8 files changed, 37 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 8493832..a2c5667 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,14 @@ Change log ================================================================================ +0.0.6 - 07/11/2018 +-------------------------------------------------------------------------------- + +Fixed +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +#. Revert the version 0.0.5 changes. Raise Import error and log the exception + 0.0.5 - 06/11/2018 -------------------------------------------------------------------------------- diff --git a/changelog.yml b/changelog.yml index 2b41253..d85c7aa 100644 --- a/changelog.yml +++ b/changelog.yml @@ -1,6 +1,12 @@ name: lml organisation: chfw releases: +- changes: + - action: Fixed + details: + - "Revert the version 0.0.5 changes. Raise Import error and log the exception" + date: 07/11/2018 + version: 0.0.6 - changes: - action: Fixed details: diff --git a/docs/source/conf.py b/docs/source/conf.py index 0ec7a42..3244eec 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -28,9 +28,9 @@ copyright = u'2017-2018 Onni Software Ltd.' author = u'C.W.' # The short X.Y version -version = u'0.0.5' +version = u'0.0.6' # The full version, including alpha/beta/rc tags -release = u'0.0.5' +release = u'0.0.6' # -- General configuration --------------------------------------------------- diff --git a/lml.yml b/lml.yml index 49373c6..8965338 100644 --- a/lml.yml +++ b/lml.yml @@ -4,9 +4,9 @@ organisation: "chfw" author: "C.W." contact: "wangc_2011@hotmail.com" company: "Onni Software Ltd." -version: "0.0.5" -current_version: "0.0.5" -release: "0.0.5" +version: "0.0.6" +current_version: "0.0.6" +release: "0.0.6" copyright_year: 2017-2018 license: New BSD dependencies: [] diff --git a/lml/_version.py b/lml/_version.py index 21b9c1f..9fd994c 100644 --- a/lml/_version.py +++ b/lml/_version.py @@ -1,2 +1,2 @@ -__version__ = "0.0.5" +__version__ = "0.0.6" __author__ = "C.W." diff --git a/lml/utils.py b/lml/utils.py index e9fc8b5..45c474d 100644 --- a/lml/utils.py +++ b/lml/utils.py @@ -12,7 +12,6 @@ import logging from json import JSONEncoder, dumps PY2 = sys.version_info[0] == 2 -PY36 = sys.version_info[0] == 3 and sys.version_info[1] >= 6 log = logging.getLogger(__name__) @@ -39,16 +38,13 @@ def json_dumps(keywords): def do_import(plugin_module_name): """dynamically import a module""" - if PY36: - try: - return _do_import(plugin_module_name) - except (ImportError, ModuleNotFoundError): # noqa: F821 - log.exception("failed to import %s", plugin_module_name) - else: - try: - return _do_import(plugin_module_name) - except ImportError: - log.exception("failed to import %s", plugin_module_name) + try: + return _do_import(plugin_module_name) + except ImportError: + log.exception( + "%s is abscent or cannot be imported", plugin_module_name + ) + raise def _do_import(plugin_module_name): diff --git a/setup.py b/setup.py index 72f8f68..1169be1 100644 --- a/setup.py +++ b/setup.py @@ -5,20 +5,22 @@ import os import sys import codecs from shutil import rmtree -from setuptools import setup, find_packages, Command + +from setuptools import Command, setup, find_packages + PY2 = sys.version_info[0] == 2 PY26 = PY2 and sys.version_info[1] < 7 NAME = 'lml' AUTHOR = 'C.W.' -VERSION = '0.0.5' +VERSION = '0.0.6' EMAIL = 'wangc_2011@hotmail.com' LICENSE = 'New BSD' DESCRIPTION = ( 'Load me later. A lazy plugin management system.' ) URL = 'https://github.com/chfw/lml' -DOWNLOAD_URL = '%s/archive/0.0.5.tar.gz' % URL +DOWNLOAD_URL = '%s/archive/0.0.6.tar.gz' % URL FILES = ['README.rst', 'CHANGELOG.rst'] KEYWORDS = [ 'python', @@ -46,8 +48,8 @@ EXTRAS_REQUIRE = {} # You do not need to read beyond this line PUBLISH_COMMAND = '{0} setup.py sdist bdist_wheel upload -r pypi'.format( sys.executable) -GS_COMMAND = ('gs lml v0.0.5 ' + - "Find 0.0.5 in changelog for more details") +GS_COMMAND = ('gs lml v0.0.6 ' + + "Find 0.0.6 in changelog for more details") NO_GS_MESSAGE = ('Automatic github release is disabled. ' + 'Please install gease to enable it.') UPLOAD_FAILED_MSG = ( diff --git a/tests/test_utils.py b/tests/test_utils.py index e64211a..0f4a605 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,7 +1,7 @@ from mock import patch from lml.utils import do_import, json_dumps from lml.plugin import PluginManager -from nose.tools import eq_ +from nose.tools import eq_, raises def test_json_dumps(): @@ -27,10 +27,11 @@ def test_do_import_2(): eq_(plugin, themodule) +@raises(ImportError) @patch("lml.utils.log.exception") def test_do_import_error(mock_exception): do_import("non.exist") - mock_exception.assert_called_with("failed to import %s", "non.exist") + mock_exception.assert_called_with("No module named 'non'") def test_do_import_cls(): From 92b65ac0223da9f4b5eaa192d7b169fb779cc7ff Mon Sep 17 00:00:00 2001 From: chfw Date: Sat, 17 Nov 2018 22:52:43 +0000 Subject: [PATCH 2/5] :bug: fix get_primary_key will fail when a module is loaded later. fix #8 --- lml/plugin.py | 20 +++++++++++--------- tests/test_plugin_manager.py | 3 +++ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/lml/plugin.py b/lml/plugin.py index 7c36802..70629fc 100644 --- a/lml/plugin.py +++ b/lml/plugin.py @@ -255,8 +255,7 @@ class PluginManager(object): a instance of plugin info """ self._logger.debug("load %s later", plugin_info.absolute_import_path) - for key in plugin_info.tags(): - self.registry[key.lower()].append(plugin_info) + self._update_registry_and_expand_tag_groups(plugin_info) def load_me_now(self, key, library=None, **keywords): """ @@ -319,18 +318,21 @@ class PluginManager(object): a instance of plugin info """ self._logger.debug("register %s", _show_me_your_name(plugin_cls)) - primary_tag = None - for index, key in enumerate(plugin_info.tags()): - plugin_info.cls = plugin_cls - self.registry[key.lower()].append(plugin_info) - if index == 0: - primary_tag = key.lower() - self.tag_groups[key.lower()] = primary_tag + plugin_info.cls = plugin_cls + self._update_registry_and_expand_tag_groups(plugin_info) def get_primary_key(self, key): __key = key.lower() return self.tag_groups.get(__key, None) + def _update_registry_and_expand_tag_groups(self, plugin_info): + primary_tag = None + for index, key in enumerate(plugin_info.tags()): + self.registry[key.lower()].append(plugin_info) + if index == 0: + primary_tag = key.lower() + self.tag_groups[key.lower()] = primary_tag + def _register_class(cls): """Reigister a newly created plugin manager""" diff --git a/tests/test_plugin_manager.py b/tests/test_plugin_manager.py index 5b447c6..49ea972 100644 --- a/tests/test_plugin_manager.py +++ b/tests/test_plugin_manager.py @@ -33,6 +33,8 @@ def test_load_me_now(mock_import): manager.load_me_later(plugin_info) actual = manager.load_me_now(test_plugin) eq_(actual, custom_class) + eq_(manager.tag_groups, {"my plugin": "my plugin"}) + eq_(plugin_info, manager.registry["my plugin"][0]) @raises(Exception) @@ -87,6 +89,7 @@ def test_register_a_plugin(): manager.register_a_plugin(TestClass, plugin_info) eq_(plugin_info.cls, TestClass) eq_(manager.registry["my"][0], plugin_info) + eq_(manager.tag_groups, {"my": "my"}) def test_get_a_plugin(): From b02a5c81ddb78ae93867e4d14de1390ce535da25 Mon Sep 17 00:00:00 2001 From: chfw Date: Sat, 17 Nov 2018 22:53:33 +0000 Subject: [PATCH 3/5] :fire: deprecated older styled plugin scanner --- lml/loader.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lml/loader.py b/lml/loader.py index 3574d61..d28307f 100644 --- a/lml/loader.py +++ b/lml/loader.py @@ -12,6 +12,7 @@ import re import logging import pkgutil +import warnings from itertools import chain from lml.utils import do_import @@ -59,6 +60,7 @@ def scan_plugins( is listed in white_list. """ __plugin_name_patterns = "^%s.+$" % prefix + warnings.warn("Deprecated! since version 0.0.3") scan_plugins_regex( plugin_name_patterns=__plugin_name_patterns, pyinstaller_path=pyinstaller_path, From b183865e0cae65a3970d67f028acb4344c7b504d Mon Sep 17 00:00:00 2001 From: chfw Date: Sat, 17 Nov 2018 22:55:36 +0000 Subject: [PATCH 4/5] :fire: deprecated older styled plugin scanner --- lml/loader.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lml/loader.py b/lml/loader.py index d28307f..cbfda22 100644 --- a/lml/loader.py +++ b/lml/loader.py @@ -60,7 +60,8 @@ def scan_plugins( is listed in white_list. """ __plugin_name_patterns = "^%s.+$" % prefix - warnings.warn("Deprecated! since version 0.0.3") + warnings.warn( + "Deprecated! since version 0.0.3. Please use scan_plugins_regex!") scan_plugins_regex( plugin_name_patterns=__plugin_name_patterns, pyinstaller_path=pyinstaller_path, From 27a5a62d809d8495cc23b9b236bda3f53a99a9b7 Mon Sep 17 00:00:00 2001 From: chfw Date: Sat, 17 Nov 2018 22:57:09 +0000 Subject: [PATCH 5/5] :egg: :ferris_wheel: release 0.0.7 --- CHANGELOG.rst | 10 ++++++++++ changelog.yml | 7 +++++++ docs/source/conf.py | 4 ++-- lml.yml | 6 +++--- lml/_version.py | 2 +- lml/loader.py | 3 ++- setup.py | 8 ++++---- 7 files changed, 29 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index a2c5667..3461721 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,16 @@ Change log ================================================================================ +0.0.7 - 17/11/2018 +-------------------------------------------------------------------------------- + +Fixed +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +#. `#8 `_: get_primary_key will fail when + a module is loaded later +#. deprecated old style plugin scanner: scan_plugins + 0.0.6 - 07/11/2018 -------------------------------------------------------------------------------- diff --git a/changelog.yml b/changelog.yml index d85c7aa..7101867 100644 --- a/changelog.yml +++ b/changelog.yml @@ -1,6 +1,13 @@ name: lml organisation: chfw releases: +- changes: + - action: Fixed + details: + - "`#8`: get_primary_key will fail when a module is loaded later" + - "deprecated old style plugin scanner: scan_plugins" + date: 17/11/2018 + version: 0.0.7 - changes: - action: Fixed details: diff --git a/docs/source/conf.py b/docs/source/conf.py index 3244eec..cd2ef0b 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -28,9 +28,9 @@ copyright = u'2017-2018 Onni Software Ltd.' author = u'C.W.' # The short X.Y version -version = u'0.0.6' +version = u'0.0.7' # The full version, including alpha/beta/rc tags -release = u'0.0.6' +release = u'0.0.7' # -- General configuration --------------------------------------------------- diff --git a/lml.yml b/lml.yml index 8965338..984fdf0 100644 --- a/lml.yml +++ b/lml.yml @@ -4,9 +4,9 @@ organisation: "chfw" author: "C.W." contact: "wangc_2011@hotmail.com" company: "Onni Software Ltd." -version: "0.0.6" -current_version: "0.0.6" -release: "0.0.6" +version: "0.0.7" +current_version: "0.0.7" +release: "0.0.7" copyright_year: 2017-2018 license: New BSD dependencies: [] diff --git a/lml/_version.py b/lml/_version.py index 9fd994c..5dc9d91 100644 --- a/lml/_version.py +++ b/lml/_version.py @@ -1,2 +1,2 @@ -__version__ = "0.0.6" +__version__ = "0.0.7" __author__ = "C.W." diff --git a/lml/loader.py b/lml/loader.py index cbfda22..a4cb1ca 100644 --- a/lml/loader.py +++ b/lml/loader.py @@ -61,7 +61,8 @@ def scan_plugins( """ __plugin_name_patterns = "^%s.+$" % prefix warnings.warn( - "Deprecated! since version 0.0.3. Please use scan_plugins_regex!") + "Deprecated! since version 0.0.3. Please use scan_plugins_regex!" + ) scan_plugins_regex( plugin_name_patterns=__plugin_name_patterns, pyinstaller_path=pyinstaller_path, diff --git a/setup.py b/setup.py index 1169be1..5dcb9a9 100644 --- a/setup.py +++ b/setup.py @@ -13,14 +13,14 @@ PY26 = PY2 and sys.version_info[1] < 7 NAME = 'lml' AUTHOR = 'C.W.' -VERSION = '0.0.6' +VERSION = '0.0.7' EMAIL = 'wangc_2011@hotmail.com' LICENSE = 'New BSD' DESCRIPTION = ( 'Load me later. A lazy plugin management system.' ) URL = 'https://github.com/chfw/lml' -DOWNLOAD_URL = '%s/archive/0.0.6.tar.gz' % URL +DOWNLOAD_URL = '%s/archive/0.0.7.tar.gz' % URL FILES = ['README.rst', 'CHANGELOG.rst'] KEYWORDS = [ 'python', @@ -48,8 +48,8 @@ EXTRAS_REQUIRE = {} # You do not need to read beyond this line PUBLISH_COMMAND = '{0} setup.py sdist bdist_wheel upload -r pypi'.format( sys.executable) -GS_COMMAND = ('gs lml v0.0.6 ' + - "Find 0.0.6 in changelog for more details") +GS_COMMAND = ('gs lml v0.0.7 ' + + "Find 0.0.7 in changelog for more details") NO_GS_MESSAGE = ('Automatic github release is disabled. ' + 'Please install gease to enable it.') UPLOAD_FAILED_MSG = (