Move to ruff for ./setup.py check

This commit is contained in:
Kovid Goyal 2023-01-10 19:31:32 +05:30
parent a981e08b2c
commit 4419e7d65a
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
11 changed files with 32 additions and 18 deletions

2
.gitignore vendored
View File

@ -41,7 +41,7 @@ setup/installer/windows/calibre/build.log
setup/pyqt_enums setup/pyqt_enums
tags tags
nbproject/ nbproject/
translations/ /translations/
*.mdproj *.mdproj
*.pidb *.pidb
*.sln *.sln

View File

@ -10,6 +10,7 @@ from shutil import copyfile
from calibre import strftime from calibre import strftime
from calibre.ebooks.BeautifulSoup import Tag from calibre.ebooks.BeautifulSoup import Tag
from calibre.web.feeds.recipes import BasicNewsRecipe from calibre.web.feeds.recipes import BasicNewsRecipe
from calibre.utils.resources import get_path
from PIL import Image, ImageDraw, ImageFont from PIL import Image, ImageDraw, ImageFont
__license__ = 'GPL v3' __license__ = 'GPL v3'
@ -168,7 +169,7 @@ class DunyaHalleri(BasicNewsRecipe):
self.cover_img_path = None self.cover_img_path = None
def draw_text(self, draw, text, text_size, top): def draw_text(self, draw, text, text_size, top):
font_path = P('fonts/liberation/LiberationSerif-Bold.ttf') font_path = get_path('fonts/liberation/LiberationSerif-Bold.ttf')
font = ImageFont.truetype(font_path, text_size) font = ImageFont.truetype(font_path, text_size)
width, height = draw.textsize(text, font=font) width, height = draw.textsize(text, font=font)
left = max(int((self.COVER_WIDTH - width) / 2.), 0) left = max(int((self.COVER_WIDTH - width) / 2.), 0)

View File

@ -10,6 +10,7 @@ from shutil import copyfile
from contextlib import closing from contextlib import closing
from calibre.ebooks.BeautifulSoup import BeautifulSoup, BeautifulStoneSoup, Tag from calibre.ebooks.BeautifulSoup import BeautifulSoup, BeautifulStoneSoup, Tag
from calibre.web.feeds.recipes import BasicNewsRecipe from calibre.web.feeds.recipes import BasicNewsRecipe
from calibre.utils.resources import get_path
from PIL import Image, ImageDraw, ImageFont from PIL import Image, ImageDraw, ImageFont
__license__ = 'GPL v3' __license__ = 'GPL v3'
@ -232,7 +233,7 @@ class DunyaHalleri_HaftaninOzeti(BasicNewsRecipe):
self.cover_img_path = None self.cover_img_path = None
def draw_text(self, draw, text, text_size, top): def draw_text(self, draw, text, text_size, top):
font_path = P('fonts/liberation/LiberationSerif-Bold.ttf') font_path = get_path('fonts/liberation/LiberationSerif-Bold.ttf')
font = ImageFont.truetype(font_path, text_size) font = ImageFont.truetype(font_path, text_size)
width, height = draw.textsize(text, font=font) width, height = draw.textsize(text, font=font)
left = max(int((self.COVER_WIDTH - width) / 2.), 0) left = max(int((self.COVER_WIDTH - width) / 2.), 0)

View File

@ -130,7 +130,7 @@ class elcorreo(BasicNewsRecipe):
# Controlamos si el artículo ha sido incluido en otro feed para eliminarlo # Controlamos si el artículo ha sido incluido en otro feed para eliminarlo
if not (link in self._processed_links): if link not in self._processed_links:
self._processed_links.append(link) self._processed_links.append(link)
else: else:
link = None link = None

View File

@ -81,7 +81,7 @@ class ElPais_RSS(BasicNewsRecipe):
def get_article_url(self, article): def get_article_url(self, article):
url = BasicNewsRecipe.get_article_url(self, article) url = BasicNewsRecipe.get_article_url(self, article)
if url and (not('/album/' in url) and not('/futbol/partido/' in url)): if url and ('/album/' not in url and '/futbol/partido/' not in url):
return url return url
self.log('Skipping non-article', url) self.log('Skipping non-article', url)
return None return None

View File

@ -147,7 +147,7 @@ class expansion_spanish(BasicNewsRecipe):
# Eliminar artículos duplicados en otros feeds # Eliminar artículos duplicados en otros feeds
if not (link in self._processed_links): if link not in self._processed_links:
self._processed_links.append(link) self._processed_links.append(link)
else: else:
link = None link = None

View File

@ -26,5 +26,16 @@ class AdvancedUserRecipe1328535130(BasicNewsRecipe):
masthead_url = 'http://api.ning.com/files/4ot8ampp*-rYQuwL2NoaHvVqcyu7VMyWyan12a9QMsJUWxk-q5V1-34wnD-Wj9B5qWjc1yPMLGiwQg8hZJxaySeaG2lx8hpV/2009_banner_ondarock.gif' # noqa masthead_url = 'http://api.ning.com/files/4ot8ampp*-rYQuwL2NoaHvVqcyu7VMyWyan12a9QMsJUWxk-q5V1-34wnD-Wj9B5qWjc1yPMLGiwQg8hZJxaySeaG2lx8hpV/2009_banner_ondarock.gif' # noqa
extra_css = ''' # noqa extra_css = ''' # noqa
.boxtabscontain_page {border: 1px solid #E0E0E0;clear: both;font-family: "Verdana", "Arial", "Helvetica", sans-serif;font-size: 10px;line-height: 17px;margin: 0px 0px 20px;padding: 10px 10px 10px 40px;position: relative;top: -1px;width: 258px;z-index: 1;} .boxtabscontain_page {
''' border: 1px solid #E0E0E0;clear: both;
font-family: "Verdana", "Arial", "Helvetica", sans-serif;
font-size: 10px;
line-height: 17px;
margin: 0px 0px 20px;
padding: 10px 10px 10px 40px;
position: relative;
top: -1px;
width: 258px;
z-index: 1;
}
'''

View File

@ -159,7 +159,7 @@ class respektRecipe(BasicNewsRecipe):
for par in paragraphs[:-1]: for par in paragraphs[:-1]:
prev = par.getprevious() prev = par.getprevious()
# Do not indent after headings # Do not indent after headings
if hasattr(prev,'tag') and not (prev.tag in ['h2','h3']): if hasattr(prev,'tag') and prev.tag not in ['h2', 'h3']:
par.attrib['class']="indent_first_line" par.attrib['class']="indent_first_line"
# Fix subtitle for Téma # Fix subtitle for Téma
try: try:

View File

@ -77,7 +77,7 @@ 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(['flake8', '--filename', '*.py,*.recipe', f]) p2 = subprocess.Popen(['ruff', '--no-update-check', f])
return p2.wait() != 0 return p2.wait() != 0
if ext == '.pyj': if ext == '.pyj':
p = subprocess.Popen(['rapydscript', 'lint', f]) p = subprocess.Popen(['rapydscript', 'lint', f])

View File

@ -8,6 +8,7 @@ __copyright__ = '2008, Marshall T. Vandegrift <llasram@gmail.com>'
import io import io
from gettext import GNUTranslations from gettext import GNUTranslations
from calibre.utils.localization import get_lc_messages_path from calibre.utils.localization import get_lc_messages_path
from calibre.utils.resources import get_path
from zipfile import ZipFile from zipfile import ZipFile
__all__ = ['translate'] __all__ = ['translate']
@ -22,7 +23,7 @@ def translate(lang, text):
else: else:
mpath = get_lc_messages_path(lang) mpath = get_lc_messages_path(lang)
if mpath is not None: if mpath is not None:
with ZipFile(P('localization/locales.zip', with ZipFile(get_path('localization/locales.zip',
allow_user_override=False), 'r') as zf: allow_user_override=False), 'r') as zf:
try: try:
buf = io.BytesIO(zf.read(mpath + '/messages.mo')) buf = io.BytesIO(zf.read(mpath + '/messages.mo'))

View File

@ -1,14 +1,14 @@
#!/usr/bin/env python #!/usr/bin/env python
# License: GPLv3 Copyright: 2009, Kovid Goyal <kovid at kovidgoyal.net>
__license__ = 'GPL v3' import io
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>' import locale
__docformat__ = 'restructuredtext en' import os
import re
import os, locale, re, io
from gettext import GNUTranslations, NullTranslations from gettext import GNUTranslations, NullTranslations
from calibre.utils.resources import get_path as P
from calibre.utils.resources import get_path as P
from polyglot.builtins import iteritems from polyglot.builtins import iteritems
_available_translations = None _available_translations = None
@ -29,7 +29,7 @@ def available_translations():
def get_system_locale(): def get_system_locale():
from calibre.constants import iswindows, ismacos from calibre.constants import ismacos, iswindows
lang = None lang = None
if iswindows: if iswindows:
try: try: