command to upgrade source code

This commit is contained in:
Kovid Goyal 2022-01-08 11:26:18 +05:30
parent 2e56a2de31
commit 224db2bb02
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 30 additions and 11 deletions

View File

@ -19,6 +19,18 @@ class Message:
return '%s:%s: %s' % (self.filename, self.lineno, self.msg)
def checkable_python_files(SRC):
for dname in ('odf', 'calibre'):
for x in os.walk(os.path.join(SRC, dname)):
for f in x[-1]:
y = os.path.join(x[0], f)
if (f.endswith('.py') and f not in (
'dict_data.py', 'unicodepoints.py', 'krcodepoints.py',
'jacodepoints.py', 'vncodepoints.py', 'zhcodepoints.py') and
'prs500/driver.py' not in y) and not f.endswith('_ui.py'):
yield y
class Check(Command):
description = 'Check for errors in the calibre source code'
@ -26,15 +38,7 @@ class Check(Command):
CACHE = 'check.json'
def get_files(self):
for dname in ('odf', 'calibre'):
for x in os.walk(self.j(self.SRC, dname)):
for f in x[-1]:
y = self.j(x[0], f)
if (f.endswith('.py') and f not in (
'dict_data.py', 'unicodepoints.py', 'krcodepoints.py',
'jacodepoints.py', 'vncodepoints.py', 'zhcodepoints.py') and
'prs500/driver.py' not in y) and not f.endswith('_ui.py'):
yield y
yield from checkable_python_files(self.SRC)
for x in os.walk(self.j(self.d(self.SRC), 'recipes')):
for f in x[-1]:
@ -117,3 +121,17 @@ class Check(Command):
except EnvironmentError as err:
if err.errno != errno.ENOENT:
raise
class UpgradeSourceCode(Command):
description = 'Upgrade python source code'
def run(self, opts):
files = []
for path in checkable_python_files(self.SRC):
q = path.replace(os.sep, '/')
if '/metadata/sources/' in q or '/store/stores/' in q:
continue
files.append(q)
subprocess.call(['pyupgrade', '--py37-plus'] + files)

View File

@ -13,7 +13,7 @@ __all__ = [
'git_version',
'develop', 'install',
'kakasi', 'rapydscript', 'cacerts', 'recent_uas', 'resources',
'check', 'test', 'test_rs',
'check', 'test', 'test_rs', 'upgrade_source_code',
'sdist', 'bootstrap', 'extdev',
'manual', 'tag_release',
'upload_to_server',
@ -66,8 +66,9 @@ bootstrap = Bootstrap()
from setup.gui import GUI
gui = GUI()
from setup.check import Check
from setup.check import Check, UpgradeSourceCode
check = Check()
upgrade_source_code = UpgradeSourceCode()
from setup.test import Test, TestRS
test = Test()