Use importlib instead of imp.

importlib is deprecated.
This commit is contained in:
Valentin Lorentz 2020-01-26 11:22:59 +01:00
parent 9891b0fca4
commit 9ab908759a
67 changed files with 87 additions and 79 deletions

View File

@ -48,7 +48,7 @@ __contributors__ = {}
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
if world.testing:

View File

@ -53,8 +53,8 @@ __url__ = '' # 'http://supybot.com/Members/yourname/Aka/download'
from . import config
from . import plugin
from imp import reload
from imp import reload
from importlib import reload
from importlib import reload
# In case we're being reloaded.
reload(config)
reload(plugin)

View File

@ -48,7 +48,7 @@ __contributors__ = {}
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
# Add more reloads here if you add third-party modules and want them to be
# reloaded when this plugin is reloaded. Don't forget to import them as well!

View File

@ -47,7 +47,7 @@ __contributors__ = {}
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
# Add more reloads here if you add third-party modules and want them to be
# reloaded when this plugin is reloaded. Don't forget to import them as well!

View File

@ -49,7 +49,7 @@ __contributors__ = {}
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
# Add more reloads here if you add third-party modules and want them to be
# reloaded when this plugin is reloaded. Don't forget to import them as well!

View File

@ -48,7 +48,7 @@ __contributors__ = {}
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
# Add more reloads here if you add third-party modules and want them to be
# reloaded when this plugin is reloaded. Don't forget to import them as well!

View File

@ -50,7 +50,7 @@ __contributors__ = {
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
if world.testing:

View File

@ -47,7 +47,7 @@ __contributors__ = {}
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
# Add more reloads here if you add third-party modules and want them to be
# reloaded when this plugin is reloaded. Don't forget to import them as well!

View File

@ -49,7 +49,7 @@ __contributors__ = {}
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
# Add more reloads here if you add third-party modules and want them to be
# reloaded when this plugin is reloaded. Don't forget to import them as well!

View File

@ -53,7 +53,7 @@ __url__ = '' # 'http://supybot.com/Members/yourname/Conditional/download'
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
# Add more reloads here if you add third-party modules and want them to be
# reloaded when this plugin is reloaded. Don't forget to import them as well!

View File

@ -47,7 +47,7 @@ __contributors__ = {}
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
if world.testing:

View File

@ -46,7 +46,7 @@ __contributors__ = {}
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
# Add more reloads here if you add third-party modules and want them to be
# reloaded when this plugin is reloaded. Don't forget to import them as well!

View File

@ -47,9 +47,9 @@ __contributors__ = {}
from . import config
from . import plugin
from imp import reload
from importlib import reload
if version_info[0] >= 3:
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
if world.testing:

View File

@ -47,7 +47,7 @@ __contributors__ = {}
from . import config
from . import plugin
from imp import reload
from importlib import reload
from .local import dictclient
reload(plugin) # In case we're being reloaded.
reload(dictclient)

View File

@ -51,7 +51,7 @@ __contributors__ = {
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
# Add more reloads here if you add third-party modules and want them to be
# reloaded when this plugin is reloaded. Don't forget to import them as well!

View File

@ -51,7 +51,7 @@ __url__ = '' # 'http://supybot.com/Members/yourname/Factoids/download'
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
# Add more reloads here if you add third-party modules and want them to be
# reloaded when this plugin is reloaded. Don't forget to import them as well!

View File

@ -48,7 +48,7 @@ __contributors__ = {}
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
if world.testing:

View File

@ -47,7 +47,7 @@ __contributors__ = {}
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
if world.testing:

View File

@ -51,8 +51,8 @@ __url__ = ''
from . import config
from . import plugin
from imp import reload
from imp import reload
from importlib import reload
from importlib import reload
# In case we're being reloaded.
reload(config)
reload(plugin)

View File

@ -47,7 +47,7 @@ __contributors__ = {}
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
# Add more reloads here if you add third-party modules and want them to be
# reloaded when this plugin is reloaded. Don't forget to import them as well!

View File

@ -47,7 +47,7 @@ __contributors__ = {}
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
# Add more reloads here if you add third-party modules and want them to be
# reloaded when this plugin is reloaded. Don't forget to import them as well!

View File

@ -47,7 +47,7 @@ __contributors__ = {}
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
# Add more reloads here if you add third-party modules and want them to be
# reloaded when this plugin is reloaded. Don't forget to import them as well!

View File

@ -48,7 +48,7 @@ __contributors__ = {}
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
if world.testing:

View File

@ -47,7 +47,7 @@ __contributors__ = {supybot.authors.jamessan: ['whois']}
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
# Add more reloads here if you add third-party modules and want them to be
# reloaded when this plugin is reloaded. Don't forget to import them as well!

View File

@ -47,7 +47,7 @@ __contributors__ = {}
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
# Add more reloads here if you add third-party modules and want them to be
# reloaded when this plugin is reloaded. Don't forget to import them as well!

View File

@ -47,7 +47,7 @@ __contributors__ = {}
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
# Add more reloads here if you add third-party modules and want them to be
# reloaded when this plugin is reloaded. Don't forget to import them as well!

View File

@ -49,7 +49,7 @@ __contributors__ = {}
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
# Add more reloads here if you add third-party modules and want them to be
# reloaded when this plugin is reloaded. Don't forget to import them as well!

View File

@ -47,7 +47,7 @@ __contributors__ = {}
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
# Add more reloads here if you add third-party modules and want them to be
# reloaded when this plugin is reloaded. Don't forget to import them as well!

View File

@ -47,7 +47,7 @@ __contributors__ = {supybot.Author('Keith Jones', 'kmj', ''): ['convert']}
from . import config
from . import plugin
from imp import reload
from importlib import reload
from .local import convertcore
reload(plugin) # In case we're being reloaded.
reload(convertcore)

View File

@ -52,7 +52,7 @@ __url__ = ''
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
# Add more reloads here if you add third-party modules and want them to be
# reloaded when this plugin is reloaded. Don't forget to import them as well!

View File

@ -47,7 +47,7 @@ __contributors__ = {}
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
if world.testing:

View File

@ -30,7 +30,6 @@
import re
import os
import imp
import sys
import json
import time
@ -58,12 +57,6 @@ _ = PluginInternationalization('Misc')
if minisix.PY2:
from itertools import ifilter as filter
def get_suffix(file):
for suffix in imp.get_suffixes():
if file[-len(suffix[0]):] == suffix[0]:
return suffix
return None
def getPluginsInDirectory(directory):
# get modules in a given directory
plugins = []

View File

@ -49,7 +49,7 @@ __contributors__ = {}
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
# Add more reloads here if you add third-party modules and want them to be
# reloaded when this plugin is reloaded. Don't forget to import them as well!

View File

@ -48,7 +48,7 @@ __contributors__ = {}
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
if world.testing:

View File

@ -51,7 +51,7 @@ __url__ = '' # 'http://supybot.com/Members/yourname/News/download'
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
# Add more reloads here if you add third-party modules and want them to be
# reloaded when this plugin is reloaded. Don't forget to import them as well!

View File

@ -51,7 +51,7 @@ __url__ = ''
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
# Add more reloads here if you add third-party modules and want them to be
# reloaded when this plugin is reloaded. Don't forget to import them as well!

View File

@ -48,7 +48,7 @@ __contributors__ = {}
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
# Add more reloads here if you add third-party modules and want them to be
# reloaded when this plugin is reloaded. Don't forget to import them as well!

View File

@ -67,7 +67,7 @@ __contributors__ = {}
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
# Add more reloads here if you add third-party modules and want them to be
# reloaded when this plugin is reloaded. Don't forget to import them as well!

View File

@ -48,7 +48,7 @@ __contributors__ = { supybot.authors.inkedmn: ['Original implementation.'] }
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
# Add more reloads here if you add third-party modules and want them to be
# reloaded when this plugin is reloaded. Don't forget to import them as well!

View File

@ -48,7 +48,7 @@ __contributors__ = {}
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
if world.testing:

View File

@ -478,7 +478,7 @@ class Owner(callbacks.Plugin):
if hasattr(module, 'reload') and 'x' in locals():
module.reload(x)
if hasattr(module, 'config'):
from imp import reload
from importlib import reload
reload(module.config)
for callback in callbacks:
callback.die()

View File

@ -49,7 +49,7 @@ __contributors__ = {
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
# Add more reloads here if you add third-party modules and want them to be
# reloaded when this plugin is reloaded. Don't forget to import them as well!

View File

@ -52,7 +52,7 @@ __url__ = '' # 'http://supybot.com/Members/yourname/PluginDownloader/download'
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
# Add more reloads here if you add third-party modules and want them to be
# reloaded when this plugin is reloaded. Don't forget to import them as well!

View File

@ -147,7 +147,7 @@ class GithubRepository(GitRepository):
reload_imported = True
elif not reload_imported and \
b'reload(' in line:
fd.write(b'from imp import reload\n')
fd.write(b'from importlib import reload\n')
reload_imported = True
fd.write(line)
if newFileName.endswith('__init__.py'):

View File

@ -47,7 +47,7 @@ __contributors__ = {}
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
# Add more reloads here if you add third-party modules and want them to be
# reloaded when this plugin is reloaded. Don't forget to import them as well!

View File

@ -48,7 +48,7 @@ __contributors__ = {}
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
# Add more reloads here if you add third-party modules and want them to be
# reloaded when this plugin is reloaded. Don't forget to import them as well!

View File

@ -47,7 +47,7 @@ __contributors__ = {}
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
# Add more reloads here if you add third-party modules and want them to be
# reloaded when this plugin is reloaded. Don't forget to import them as well!

View File

@ -51,7 +51,7 @@ __contributors__ = {}
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
if world.testing:

View File

@ -47,7 +47,7 @@ __contributors__ = {}
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
# Add more reloads here if you add third-party modules and want them to be
# reloaded when this plugin is reloaded. Don't forget to import them as well!

View File

@ -47,7 +47,7 @@ __contributors__ = {}
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
# Add more reloads here if you add third-party modules and want them to be
# reloaded when this plugin is reloaded. Don't forget to import them as well!

View File

@ -48,7 +48,7 @@ __contributors__ = {}
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
# Add more reloads here if you add third-party modules and want them to be
# reloaded when this plugin is reloaded. Don't forget to import them as well!

View File

@ -48,7 +48,7 @@ __contributors__ = {}
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
# Add more reloads here if you add third-party modules and want them to be
# reloaded when this plugin is reloaded. Don't forget to import them as well!

View File

@ -47,7 +47,7 @@ __contributors__ = {}
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
# Add more reloads here if you add third-party modules and want them to be
# reloaded when this plugin is reloaded. Don't forget to import them as well!

View File

@ -47,7 +47,7 @@ __contributors__ = {}
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
# Add more reloads here if you add third-party modules and want them to be
# reloaded when this plugin is reloaded. Don't forget to import them as well!

View File

@ -47,7 +47,7 @@ __contributors__ = {supybot.authors.jamessan: ['xrl.us support',
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
# Add more reloads here if you add third-party modules and want them to be
# reloaded when this plugin is reloaded. Don't forget to import them as well!

View File

@ -48,7 +48,7 @@ __contributors__ = {}
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
if world.testing:

View File

@ -47,7 +47,7 @@ __contributors__ = {}
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
# Add more reloads here if you add third-party modules and want them to be
# reloaded when this plugin is reloaded. Don't forget to import them as well!

View File

@ -48,7 +48,7 @@ __contributors__ = {}
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
# Add more reloads here if you add third-party modules and want them to be
# reloaded when this plugin is reloaded. Don't forget to import them as well!

View File

@ -50,7 +50,7 @@ __contributors__ = {supybot.authors.progval: ['tztime'],
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
# Add more reloads here if you add third-party modules and want them to be
# reloaded when this plugin is reloaded. Don't forget to import them as well!

View File

@ -48,7 +48,7 @@ __contributors__ = {}
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
# Add more reloads here if you add third-party modules and want them to be
# reloaded when this plugin is reloaded. Don't forget to import them as well!

View File

@ -47,7 +47,7 @@ __contributors__ = { supybot.authors.stepnem: ['persistence support'] }
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
# Add more reloads here if you add third-party modules and want them to be
# reloaded when this plugin is reloaded. Don't forget to import them as well!

View File

@ -49,7 +49,7 @@ __contributors__ = {}
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
# Add more reloads here if you add third-party modules and want them to be
# reloaded when this plugin is reloaded. Don't forget to import them as well!

View File

@ -50,7 +50,7 @@ __url__ = '' # 'http://supybot.com/Members/yourname/Unix/download'
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
# Add more reloads here if you add third-party modules and want them to be
# reloaded when this plugin is reloaded. Don't forget to import them as well!

View File

@ -47,7 +47,7 @@ __contributors__ = {}
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
if world.testing:

View File

@ -47,7 +47,7 @@ __contributors__ = {}
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
if world.testing:

View File

@ -45,7 +45,7 @@ __contributors__ = {}
from . import config
from . import plugin
from imp import reload
from importlib import reload
reload(plugin) # In case we're being reloaded.
# Add more reloads here if you add third-party modules and want them to be
# reloaded when this plugin is reloaded. Don't forget to import them as well!

View File

@ -28,11 +28,15 @@
###
import os
import re
import sys
import imp
import os.path
import linecache
import re
import importlib.util
if not hasattr(importlib.util, 'module_from_spec'):
# Python < 3.5
import imp
from . import callbacks, conf, log, registry
@ -60,9 +64,20 @@ def loadPluginModule(name, ignoreDeprecation=False):
name = matched_names[0]
else:
raise ImportError(name)
moduleInfo = imp.find_module(name, pluginDirs)
try:
module = imp.load_module(name, *moduleInfo)
if hasattr(importlib.util, 'module_from_spec'):
# Python >= 3.5
spec = importlib.machinery.PathFinder.find_spec(name, pluginDirs)
if spec is None:
assert ImportError(name)
module = importlib.util.module_from_spec(spec)
sys.modules[module.__name__] = module
spec.loader.exec_module(module)
else:
# Python < 3.5
moduleInfo = imp.find_module(name, pluginDirs)
module = imp.load_module(name, *moduleInfo)
except:
sys.modules.pop(name, None)
keys = list(sys.modules.keys())