mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-16 15:39:21 +01:00
PluginDownloader: replace automatic 2to3 step with a simple warning
The previous heuristic runs into false positives when imports are merged in __init__.py More broadly though, it's unlikely automatic 2to3 is particularly useful in 2022 - plugins that were written ~10 years ago are unlikely to work even if syntax errors are fixed.
This commit is contained in:
parent
8ccf2c7175
commit
d00113e92d
@ -121,11 +121,11 @@ class GithubRepository(GitRepository):
|
|||||||
assert directory is not None, \
|
assert directory is not None, \
|
||||||
'No valid directory in supybot.directories.plugins.'
|
'No valid directory in supybot.directories.plugins.'
|
||||||
|
|
||||||
|
possibly_incompatible = False
|
||||||
try:
|
try:
|
||||||
assert archive.getmember(prefix + dirname).isdir(), \
|
assert archive.getmember(prefix + dirname).isdir(), \
|
||||||
'This is not a valid plugin (it is a file, not a directory).'
|
'This is not a valid plugin (it is a file, not a directory).'
|
||||||
|
|
||||||
run_2to3 = minisix.PY3
|
|
||||||
for file in archive.getmembers():
|
for file in archive.getmembers():
|
||||||
if file.name.startswith(prefix + dirname):
|
if file.name.startswith(prefix + dirname):
|
||||||
extractedFile = archive.extractfile(file)
|
extractedFile = archive.extractfile(file)
|
||||||
@ -140,41 +140,17 @@ class GithubRepository(GitRepository):
|
|||||||
os.mkdir(newFileName)
|
os.mkdir(newFileName)
|
||||||
else:
|
else:
|
||||||
with open(newFileName, 'ab') as fd:
|
with open(newFileName, 'ab') as fd:
|
||||||
reload_imported = False
|
|
||||||
for line in extractedFile.readlines():
|
for line in extractedFile.readlines():
|
||||||
if minisix.PY3:
|
if file.name.endswith('__init__.py') and \
|
||||||
if b'import reload' in line:
|
line.startswith((b'import config', b'import plugin')):
|
||||||
reload_imported = True
|
possibly_incompatible = True
|
||||||
elif not reload_imported and \
|
|
||||||
b'reload(' in line:
|
|
||||||
fd.write(b'from importlib import reload\n')
|
|
||||||
reload_imported = True
|
|
||||||
fd.write(line)
|
fd.write(line)
|
||||||
if newFileName.endswith('__init__.py'):
|
|
||||||
with open(newFileName) as fd:
|
|
||||||
lines = list(filter(lambda x:'import plugin' in x,
|
|
||||||
fd.readlines()))
|
|
||||||
if lines and lines[0].startswith('from . import'):
|
|
||||||
# This should be already Python 3-compatible
|
|
||||||
run_2to3 = False
|
|
||||||
finally:
|
finally:
|
||||||
archive.close()
|
archive.close()
|
||||||
del archive
|
del archive
|
||||||
if run_2to3:
|
if possibly_incompatible:
|
||||||
try:
|
return _('Plugin installed. However, it may be incompatible with '
|
||||||
import lib2to3
|
'Python 3 and require manual code changes to work correctly.')
|
||||||
except ImportError:
|
|
||||||
return _('Plugin is probably not compatible with your '
|
|
||||||
'Python version (3.x) and could not be converted '
|
|
||||||
'because 2to3 is not installed.')
|
|
||||||
import subprocess
|
|
||||||
fixers = []
|
|
||||||
subprocess.Popen(['2to3', '-wn', os.path.join(directory, plugin)]) \
|
|
||||||
.wait()
|
|
||||||
return _('Plugin was designed for Python 2, but an attempt to '
|
|
||||||
'convert it to Python 3 has been made. There is no '
|
|
||||||
'guarantee it will work, though.')
|
|
||||||
else:
|
|
||||||
return _('Plugin successfully installed.')
|
return _('Plugin successfully installed.')
|
||||||
|
|
||||||
def getInfo(self, plugin):
|
def getInfo(self, plugin):
|
||||||
|
@ -29,11 +29,9 @@
|
|||||||
###
|
###
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
from supybot.test import *
|
from supybot.test import *
|
||||||
import supybot.utils.minisix as minisix
|
|
||||||
|
|
||||||
pluginsPath = '%s/test-plugins' % os.getcwd()
|
pluginsPath = '%s/test-plugins' % os.getcwd()
|
||||||
|
|
||||||
@ -80,17 +78,15 @@ class PluginDownloaderTestCase(PluginTestCase):
|
|||||||
self.assertNotError('plugindownloader install Hoaas DuckDuckGo')
|
self.assertNotError('plugindownloader install Hoaas DuckDuckGo')
|
||||||
self._testPluginInstalled('DuckDuckGo')
|
self._testPluginInstalled('DuckDuckGo')
|
||||||
|
|
||||||
|
def testInstallLegacyWarning(self):
|
||||||
|
self.assertRegexp('plugindownloader install frumious Codepoints',
|
||||||
|
'may be incompatible')
|
||||||
|
|
||||||
def testInfo(self):
|
def testInfo(self):
|
||||||
self.assertResponse('plugindownloader info progval Twitter',
|
self.assertResponse('plugindownloader info progval Twitter',
|
||||||
'Advanced Twitter plugin for Supybot, with capabilities '
|
'Advanced Twitter plugin for Supybot, with capabilities '
|
||||||
'handling, and per-channel user account.')
|
'handling, and per-channel user account.')
|
||||||
|
|
||||||
if minisix.PY3:
|
|
||||||
def test_2to3(self):
|
|
||||||
self.assertRegexp('plugindownloader install SpiderDave Pastebin',
|
|
||||||
'convert')
|
|
||||||
self.assertNotError('load Pastebin')
|
|
||||||
|
|
||||||
if not network:
|
if not network:
|
||||||
class PluginDownloaderTestCase(PluginTestCase):
|
class PluginDownloaderTestCase(PluginTestCase):
|
||||||
pass
|
pass
|
||||||
|
Loading…
Reference in New Issue
Block a user