mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 02:34:06 -04:00
add option --strict to 'setup.py check'
Perform the checking more strictely. See the file "ruff-strict-pep8.toml"
This commit is contained in:
parent
fe7536dd2a
commit
c1f7c9dd95
@ -9,7 +9,8 @@ include = ['*.py', '*.recipe']
|
|||||||
exclude = [
|
exclude = [
|
||||||
"*_ui.py",
|
"*_ui.py",
|
||||||
"bypy/*",
|
"bypy/*",
|
||||||
"setup/*",
|
"setup/polib.py",
|
||||||
|
"setup/linux-installer.py",
|
||||||
"src/css_selectors/*",
|
"src/css_selectors/*",
|
||||||
"src/polyglot/*",
|
"src/polyglot/*",
|
||||||
"src/templite/*",
|
"src/templite/*",
|
||||||
@ -20,7 +21,7 @@ exclude = [
|
|||||||
quote-style = 'single'
|
quote-style = 'single'
|
||||||
|
|
||||||
[tool.ruff.lint]
|
[tool.ruff.lint]
|
||||||
ignore = ['E402', 'E722', 'E741', 'E401']
|
ignore = ['E402', 'E722', 'E741']
|
||||||
select = ['E', 'F', 'I', 'W', 'INT']
|
select = ['E', 'F', 'I', 'W', 'INT']
|
||||||
|
|
||||||
[tool.ruff.lint.per-file-ignores]
|
[tool.ruff.lint.per-file-ignores]
|
||||||
|
38
ruff-strict-pep8.toml
Normal file
38
ruff-strict-pep8.toml
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
line-length = 160
|
||||||
|
target-version = 'py38'
|
||||||
|
builtins = ['_', 'I', 'P']
|
||||||
|
include = ['*.py', '*.recipe']
|
||||||
|
exclude = [
|
||||||
|
"*_ui.py",
|
||||||
|
"bypy/*",
|
||||||
|
"setup/polib.py",
|
||||||
|
"setup/linux-installer.py",
|
||||||
|
"src/css_selectors/*",
|
||||||
|
"src/polyglot/*",
|
||||||
|
"src/templite/*",
|
||||||
|
"src/tinycss/*",
|
||||||
|
]
|
||||||
|
|
||||||
|
[format]
|
||||||
|
quote-style = 'single'
|
||||||
|
|
||||||
|
[lint]
|
||||||
|
ignore = ['E402', 'E722', 'E741']
|
||||||
|
select = ['E', 'F', 'I', 'W', 'INT']
|
||||||
|
|
||||||
|
[lint.per-file-ignores]
|
||||||
|
"src/calibre/ebooks/unihandecode/*codepoints.py" = ['E501', 'W191']
|
||||||
|
"src/qt/*.py" = ['I']
|
||||||
|
"src/qt/*.pyi" = ['I']
|
||||||
|
|
||||||
|
[lint.isort]
|
||||||
|
detect-same-package = true
|
||||||
|
extra-standard-library = ["aes", "elementmaker", "encodings"]
|
||||||
|
known-first-party = ["calibre_extensions", "calibre_plugins", "polyglot"]
|
||||||
|
known-third-party = ["odf", "qt", "templite", "tinycss", "css_selectors"]
|
||||||
|
relative-imports-order = "closest-to-furthest"
|
||||||
|
split-on-trailing-comma = false
|
||||||
|
section-order = ['__python__', "future", "standard-library", "third-party", "first-party", "local-folder"]
|
||||||
|
|
||||||
|
[lint.isort.sections]
|
||||||
|
'__python__' = ['__python__']
|
@ -23,15 +23,19 @@ class Message:
|
|||||||
return f'{self.filename}:{self.lineno}: {self.msg}'
|
return f'{self.filename}:{self.lineno}: {self.msg}'
|
||||||
|
|
||||||
|
|
||||||
|
def get_ruff_config(is_strict_check):
|
||||||
|
if is_strict_check:
|
||||||
|
return ['--config=ruff-strict-pep8.toml']
|
||||||
|
else:
|
||||||
|
return []
|
||||||
|
|
||||||
|
|
||||||
def checkable_python_files(SRC):
|
def checkable_python_files(SRC):
|
||||||
for dname in ('odf', 'calibre'):
|
for dname in ('odf', 'calibre'):
|
||||||
for x in os.walk(os.path.join(SRC, dname)):
|
for x in os.walk(os.path.join(SRC, dname)):
|
||||||
for f in x[-1]:
|
for f in x[-1]:
|
||||||
y = os.path.join(x[0], f)
|
y = os.path.join(x[0], f)
|
||||||
if (f.endswith('.py') and f not in (
|
if f.endswith('.py') and not f.endswith('_ui.py'):
|
||||||
'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 y
|
||||||
|
|
||||||
|
|
||||||
@ -40,12 +44,15 @@ class Check(Command):
|
|||||||
description = 'Check for errors in the calibre source code'
|
description = 'Check for errors in the calibre source code'
|
||||||
|
|
||||||
CACHE = 'check.json'
|
CACHE = 'check.json'
|
||||||
|
CACHE_STRICT = 'check-strict.json'
|
||||||
|
|
||||||
def add_options(self, parser):
|
def add_options(self, parser):
|
||||||
parser.add_option('--fix', '--auto-fix', default=False, action='store_true',
|
parser.add_option('--fix', '--auto-fix', default=False, action='store_true',
|
||||||
help='Try to automatically fix some of the smallest errors')
|
help='Try to automatically fix some of the smallest errors')
|
||||||
parser.add_option('--pep8', '--pep8-commit', default=False, action='store_true',
|
parser.add_option('--pep8', '--pep8-commit', default=False, action='store_true',
|
||||||
help='Try to automatically fix some of the smallest errors, then perform a pep8 commit')
|
help='Try to automatically fix some of the smallest errors, then perform a pep8 commit')
|
||||||
|
parser.add_option('--strict', '--strict-pep8', default=False, action='store_true',
|
||||||
|
help='Perform the checking more strictely. See the file "strict-pep8.toml"')
|
||||||
|
|
||||||
def get_files(self):
|
def get_files(self):
|
||||||
yield from checkable_python_files(self.SRC)
|
yield from checkable_python_files(self.SRC)
|
||||||
@ -80,7 +87,7 @@ class Check(Command):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def cache_file(self):
|
def cache_file(self):
|
||||||
return self.j(build_cache_dir(), self.CACHE)
|
return self.j(build_cache_dir(), self.CACHE_STRICT if self.is_strict_check else self.CACHE)
|
||||||
|
|
||||||
def save_cache(self, cache):
|
def save_cache(self, cache):
|
||||||
dump_json(cache, self.cache_file)
|
dump_json(cache, self.cache_file)
|
||||||
@ -88,8 +95,8 @@ class Check(Command):
|
|||||||
def file_has_errors(self, f):
|
def file_has_errors(self, f):
|
||||||
ext = os.path.splitext(f)[1]
|
ext = os.path.splitext(f)[1]
|
||||||
if ext in {'.py', '.recipe'}:
|
if ext in {'.py', '.recipe'}:
|
||||||
p2 = subprocess.Popen(['ruff', 'check', f])
|
p = subprocess.Popen(['ruff', 'check', f] + get_ruff_config(self.is_strict_check))
|
||||||
return p2.wait() != 0
|
return p.wait() != 0
|
||||||
if ext == '.pyj':
|
if ext == '.pyj':
|
||||||
p = subprocess.Popen(['rapydscript', 'lint', f])
|
p = subprocess.Popen(['rapydscript', 'lint', f])
|
||||||
return p.wait() != 0
|
return p.wait() != 0
|
||||||
@ -113,11 +120,15 @@ class Check(Command):
|
|||||||
if opts.fix and opts.pep8:
|
if opts.fix and opts.pep8:
|
||||||
self.info('setup.py check: error: options --fix and --pep8 are mutually exclusive')
|
self.info('setup.py check: error: options --fix and --pep8 are mutually exclusive')
|
||||||
raise SystemExit(2)
|
raise SystemExit(2)
|
||||||
|
if opts.strict and opts.pep8:
|
||||||
|
self.info('setup.py check: error: options --strict and --pep8 are mutually exclusive')
|
||||||
|
raise SystemExit(2)
|
||||||
|
|
||||||
self.fhash_cache = {}
|
self.fhash_cache = {}
|
||||||
self.wn_path = os.path.expanduser('~/work/srv/main/static')
|
self.wn_path = os.path.expanduser('~/work/srv/main/static')
|
||||||
self.has_changelog_check = os.path.exists(self.wn_path)
|
self.has_changelog_check = os.path.exists(self.wn_path)
|
||||||
self.auto_fix = opts.fix
|
self.auto_fix = opts.fix
|
||||||
|
self.is_strict_check = opts.strict
|
||||||
if opts.pep8:
|
if opts.pep8:
|
||||||
self.run_pep8_commit()
|
self.run_pep8_commit()
|
||||||
else:
|
else:
|
||||||
@ -167,8 +178,9 @@ class Check(Command):
|
|||||||
self.info('\t\t', str(err))
|
self.info('\t\t', str(err))
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
|
for cache_file in [self.j(build_cache_dir(), self.CACHE), self.j(build_cache_dir(), self.CACHE_STRICT)]:
|
||||||
try:
|
try:
|
||||||
os.remove(self.cache_file)
|
os.remove(cache_file)
|
||||||
except OSError as err:
|
except OSError as err:
|
||||||
if err.errno != errno.ENOENT:
|
if err.errno != errno.ENOENT:
|
||||||
raise
|
raise
|
||||||
|
Loading…
x
Reference in New Issue
Block a user