From 4cf2d04ffa3035b7f6336edb07e7a8866d63b7c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustaf=20Alh=C3=A4ll?= Date: Tue, 13 Nov 2018 17:39:31 +0100 Subject: [PATCH 1/6] reload: fix shutdown routines not called on .reload --- sopel/bot.py | 2 ++ sopel/modules/reload.py | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/sopel/bot.py b/sopel/bot.py index 7b2b09801d..7509c48e0a 100644 --- a/sopel/bot.py +++ b/sopel/bot.py @@ -580,6 +580,8 @@ def _shutdown(self): shutdown_method.__module__, e ) ) + # Avoid calling shutdown methods if we already have. + self.shutdown_methods = [] def cap_req(self, module_name, capability, arg=None, failure_callback=None, success_callback=None): diff --git a/sopel/modules/reload.py b/sopel/modules/reload.py index 99fe786a95..20c0054b81 100644 --- a/sopel/modules/reload.py +++ b/sopel/modules/reload.py @@ -11,7 +11,7 @@ import collections import sys import time -from sopel.tools import iteritems +from sopel.tools import stderr, iteritems import sopel.loader import sopel.module import subprocess @@ -41,6 +41,7 @@ def f_reload(bot, trigger): 'medium': collections.defaultdict(list), 'low': collections.defaultdict(list) } + bot._shutdown() bot._command_groups = collections.defaultdict(list) for m in sopel.loader.enumerate_modules(bot.config): @@ -67,6 +68,22 @@ def reload_module_tree(bot, name, seen=None, silent=False): old_callables = {} for obj_name, obj in iteritems(vars(old_module)): if callable(obj): + if (getattr(obj, '__name__', None) == 'shutdown' and + obj in bot.shutdown_methods): + # If this is a shutdown method, call it first. + try: + stderr( + "calling %s.%s" % ( + obj.__module__, obj.__name__, + ) + ) + obj(bot) + except Exception as e: + stderr( + "Error calling shutdown method for module %s:%s" % ( + obj.__module__, e + ) + ) bot.unregister(obj) elif (type(obj) is ModuleType and obj.__name__.startswith(name + '.') and From decf6d6c1e76c7b1f5ec408dd15da58e11fa144b Mon Sep 17 00:00:00 2001 From: dgw Date: Thu, 28 Feb 2019 05:02:04 -0600 Subject: [PATCH 2/6] reload: don't call shutdown methods twice for * (all) reload_module_tree() already calls shutdown methods, so calling bot._shutdown() before getting into that function is redundant. This is an artifact of my rebase, NOT Hanicef's original work (which happened before reload_module_tree() even existed). --- sopel/modules/reload.py | 1 - 1 file changed, 1 deletion(-) diff --git a/sopel/modules/reload.py b/sopel/modules/reload.py index 20c0054b81..5955dc34ed 100644 --- a/sopel/modules/reload.py +++ b/sopel/modules/reload.py @@ -41,7 +41,6 @@ def f_reload(bot, trigger): 'medium': collections.defaultdict(list), 'low': collections.defaultdict(list) } - bot._shutdown() bot._command_groups = collections.defaultdict(list) for m in sopel.loader.enumerate_modules(bot.config): From 61f74338e8c851846bb6b3af2d9e55533ed9cbbf Mon Sep 17 00:00:00 2001 From: Rusty Bower Date: Sat, 16 Mar 2019 04:06:16 -0500 Subject: [PATCH 3/6] reddit: fix praw 4.0+ compatibility Co-Authored-By: dgw --- sopel/modules/reddit.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sopel/modules/reddit.py b/sopel/modules/reddit.py index 5c74a7101a..13da2a3be9 100644 --- a/sopel/modules/reddit.py +++ b/sopel/modules/reddit.py @@ -121,8 +121,10 @@ def redditor_info(bot, trigger, match=None): client_secret=None, ) match = match or trigger - try: + try: # praw <4.0 style u = r.get_redditor(match.group(2)) + except AttributeError: # praw >=4.0 style + u = r.redditor(match.group(2)) except Exception: # TODO: Be specific if commanded: bot.say('No such Redditor.') From c014a053b2df437b350df3f9d330c3d5f50bda36 Mon Sep 17 00:00:00 2001 From: dgw Date: Fri, 22 Mar 2019 07:44:05 -0500 Subject: [PATCH 4/6] url: Actually clean URLs when auto-fetching titles A change that should have been made in #1413, but was overlooked. This proves why having more than one developer review changes is useful. @Exirel indirectly found this omission during an overhaul of Sopel's URL-handling for version 7. See https://github.com/sopel-irc/sopel/pull/1510#discussion_r268139814 --- sopel/modules/url.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel/modules/url.py b/sopel/modules/url.py index 6009063edc..26078fe013 100644 --- a/sopel/modules/url.py +++ b/sopel/modules/url.py @@ -166,7 +166,7 @@ def title_auto(bot, trigger): if bot.memory['safety_cache'][trigger]['positives'] > 1: return - urls = find_urls(trigger) + urls = find_urls(trigger, clean=True) if len(urls) == 0: return From fa42aef77e2c5b1674f9eeec9e36abde043d9e01 Mon Sep 17 00:00:00 2001 From: dgw Date: Sat, 23 Mar 2019 23:58:52 -0500 Subject: [PATCH 5/6] url: Clean up logic in trim_url() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Python 2 doesn't like `thing is unicode`; it wants `thing == unicode`. Of course, it just works with regular str in both py2 and py3… Oh well. This is another find from @Exirel's overhaul of URL handling for 7.x. As long as I was touching the line anyway, I added parentheses to make the operator precedence explicit. Likely unnecessary, but probably easier to read by some small measure. --- sopel/modules/url.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel/modules/url.py b/sopel/modules/url.py index 6009063edc..8bd1de4374 100644 --- a/sopel/modules/url.py +++ b/sopel/modules/url.py @@ -99,7 +99,7 @@ def trim_url(url): # clean unmatched parentheses/braces/brackets for (opener, closer) in [('(', ')'), ('[', ']'), ('{', '}'), ('<', '>')]: - if url[-1] is closer and url.count(opener) < url.count(closer): + if (url[-1] == closer) and (url.count(opener) < url.count(closer)): url = url[:-1] return url From 6e6f710b028064fd12775b0e50efa7855b77c605 Mon Sep 17 00:00:00 2001 From: dgw Date: Sun, 24 Mar 2019 14:03:21 -0500 Subject: [PATCH 6/6] Release 6.6.5 --- NEWS | 17 +++++++++++++++++ sopel/__init__.py | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index cd3c31efd7..2a3ebe6c11 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,23 @@ This file is used to auto-generate the "Changelog" section of Sopel's website. When adding new entries, follow the style guide in NEWS.spec.md to avoid causing problems with the site build. +Changes between 6.6.4 and 6.6.5 +=============================== + +Module changes +-------------- + +* Fixed url module not cleaning punctuation when auto-titling [[#1515][]] +* Fixed url module's punctuation-cleaning on Python 2 [[#1517][]] +* Fixed `.redditor` command with newer `praw` versions (4.0+) [[#1506][]] +* Reloading modules now runs their `shutdown()` routines [[#1412][]] + + [#1412]: https://github.com/sopel-irc/sopel/pull/1412 + [#1506]: https://github.com/sopel-irc/sopel/pull/1506 + [#1515]: https://github.com/sopel-irc/sopel/pull/1515 + [#1517]: https://github.com/sopel-irc/sopel/pull/1517 + + Changes between 6.6.3 and 6.6.4 =============================== diff --git a/sopel/__init__.py b/sopel/__init__.py index 6ebcf3d217..a0cbdaf6ee 100644 --- a/sopel/__init__.py +++ b/sopel/__init__.py @@ -30,7 +30,7 @@ import traceback import signal -__version__ = '6.6.4' +__version__ = '6.6.5' def _version_info(version=__version__):