-
-
Notifications
You must be signed in to change notification settings - Fork 405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor module (un|re)loading #1053
Conversation
fc1e194
to
a604e3f
Compare
a604e3f
to
ba63dda
Compare
Dunno if this patch still works, but I rebased it anyway. Will probably test later today. |
Yeah, I'm still available. Should be rebased now. |
Sorry @calebj, needs rebasing again. 😅 Could you test whether/how this affects #1056? If this helps at all, even if it doesn't fix all the issues, it might be a big step just the same. Also curious how this interacts with #990, if at all. No rush on this, it's all future stuff not scheduled to be in any release yet. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've left some line notes for specific things, but my overall impression from running this is not great at the moment. It made the duplicated-command behavior from #1056 worse: Commands from reloaded modules now output three times instead of twice.
04:20:27 <~dgw> ,wa dgw
04:20:34 <Sopel> [W|A] Converse County Airport = Douglas, Wyoming, United States
04:20:34 <~dgw> ,reload wolfram
04:20:36 <Sopel> dgw: <module 'wolfram' from '/usr/lib/python3.6/site-packages/sopel_modules/wolfram/__init__.py'> (version: 2018-04-06 09:11:42)
04:20:42 <~dgw> ,wa dgw
04:20:45 <~dgw> how many...
04:20:49 <Sopel> [W|A] Converse County Airport = Douglas, Wyoming, United States
04:20:50 <Sopel> [W|A] Converse County Airport = Douglas, Wyoming, United States
04:20:51 <Sopel> [W|A] Converse County Airport = Douglas, Wyoming, United States
At a bare minimum, for this to get merged it must not cause any regressions. Fixing something would be good too, though. 😁 And as mentioned in a line note, the "command groups" bit should probably become its own PR, so this one doesn't turn into too much of a hydra. I understand if the help changes require this refactor before they can work, but fixing the reloading issues is much more important at the moment.
sopel/bot.py
Outdated
def unregister_module(self, module): | ||
for obj_name, obj in iteritems(vars(module)): | ||
self.unregister(obj) | ||
callables, _, _ = sopel.loader.clean_module(module, self.config) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This causes a ValueError
; clean_module()
only returns one value.
sopel/modules/help.py
Outdated
@@ -63,6 +63,7 @@ def help(bot, trigger): | |||
for category, cmds in collections.OrderedDict(sorted(bot.command_groups.items())).items(): | |||
category = category.upper().ljust(name_length) | |||
cmds = set(cmds) # remove duplicates | |||
cmds = ['|'.join(cg) for cg in cmds] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe let's split command-group help into its own PR?
sopel/modules/reload.py
Outdated
|
||
|
||
@sopel.module.nickname_commands("reload") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a fan of changing the command behavior just for the hell of it. Sopel: reload modulename
should continue to work.
sopel/modules/reload.py
Outdated
@@ -33,54 +32,40 @@ def f_reload(bot, trigger): | |||
'medium': collections.defaultdict(list), | |||
'low': collections.defaultdict(list) | |||
} | |||
bot.shutdown_methods.clear() | |||
bot.scheduler.clear_jobs() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the refactor in bot.py
to remove only the specified job, why is the reload
module now clearing the whole queue? Why is reload
clearing all shutdown methods for the entire bot instead of only the specified module? Keeping #831 in mind, this refactor is a good opportunity to stop clearing things that shouldn't be.
0ac67a5
to
72dd79e
Compare
I think reloading should work for you now. Both of my PRs are having issues with that URL check, but it tests fine locally. I would like to squash and add a 'fixes' keyword if these are acceptable to merge. |
Kicked Travis, test passed. Bing can be an utter diva. It'd be easier to fix if it failed consistently… Squashing sounds great! But not just yet, sorry. Don't have as much time as I'd like right now to go back and do another in-depth test of this, and the moved functions make even reviewing the diff hard. I will, however, put this (and your other rebased PR) at the top of my to-do list, so it shouldn't be more than a few days before I have a chance to look at both of them. 😸 |
Requested changes addressed. Larger direction being discussed before next review.
Rebased, and appears to be working with core modules, wolfram and youtube on Python 2.7, 3.6, and 3.7 🎉 I implemented some of the ideas from #1314, but used code I adapted from an existing module in another project. This should fix #1324 and, of course, #1056. #990 still applies cleanly. @ralienpp, would you mind testing this branch with your own modules? |
No luck yet, @calebj. Here's what I did, just to make sure we're on the same page:
I sent a pull request that adds the module in question to the built-in set; the functions are quite simple in their nature: #1366 Most of the logic in my headless systems (updates, status checks, etc) is implemented through the execution of programs via this |
Weird. That happens on my end too... but not if I run it from the repo, or pip install from the repo folder. Something isn't making it to the repo, even though it says my working tree is clean. Will investigate. |
Found it. You used pip install git+https://github.com/sopel-irc/sopel.git@a970dee4336133bc5c5c9dece33c5b41301c8bed --upgrade works as expected. You should get a |
This is what I get when I run the command with the
This has happened before, please see the history here: #1056 (comment) |
Try passing it my fork URL instead: pip install --user git+https://github.com/calebj/sopel.git@a970dee4336133bc5c5c9dece33c5b41301c8bed --upgrade |
I had to adjust your command and remove the I will let this picture express my feelings in a more dramatic way https://cdn.theatlantic.com/static/mt/assets/science/JPL.gif |
Hey @calebj, any ideas on this behavior?
(The last In this test, @commands('wa2')
def wa2(bot, trigger):
bot.say('wa2 command added') And to test removal, I simply removed the whole function and its decorators. FWIW, my reloading overhaul in #1314 also bugs out on removed methods, but it only adds one repetition. Yours seems to add four, and I'm not sure why. (Not that I'm yet sure why mine adds even one…) |
The whole practice of modifying the command function object directly isn't the best thing to work with, but I fixed it in my latest push. In a future update, I would advocate moving to a single |
I'm more than a little squeamish about doing anything like Reloading support is probably not worth completely rejiggering the decorators, honestly. Keeping multiple versions of callable objects around doesn't tickle my fancy either. :/ |
The handling here has been robust in my experience, and only Sopel modules are removed from |
I need to dig way into this at a computer, hmm. There must be a good way to have our cake and eat it too re: modifying functions during load… |
Having used that patched version for a while, I have found that the problem persists, unfortunately. My first thought is that the initial test, where I use
|
So, @HumorBaby is putting a lot of work into the reloading logic, and @Exirel is working on refactoring the plugin/module system itself. Between the two of them, they're likely to duplicate a lot of this PR. Given that this PR has kind of stalled, I'm going to say it'll wind up getting closed unmerged unless @calebj reappears to continue work on it relatively soon. |
Closing in favor of #1479 |
Commit summary stolen for use as PR description, since @calebj didn't enter one. — @dgw