From 4419e7d65a733d8a7ae6d72b03a133c24b639faa Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 10 Jan 2023 19:31:32 +0530 Subject: [PATCH] Move to ruff for ./setup.py check --- .gitignore | 2 +- recipes/dunyahalleri.recipe | 3 ++- recipes/dunyahalleri_haftaninozeti.recipe | 3 ++- recipes/el_correo.recipe | 2 +- recipes/elpais_impreso.recipe | 2 +- recipes/expansion_spanish.recipe | 2 +- recipes/onda_rock.recipe | 15 +++++++++++++-- recipes/respekt_magazine.recipe | 2 +- setup/check.py | 2 +- src/calibre/translations/dynamic.py | 3 ++- src/calibre/utils/localization.py | 14 +++++++------- 11 files changed, 32 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index 4e35b4d848..26d1a08a98 100644 --- a/.gitignore +++ b/.gitignore @@ -41,7 +41,7 @@ setup/installer/windows/calibre/build.log setup/pyqt_enums tags nbproject/ -translations/ +/translations/ *.mdproj *.pidb *.sln diff --git a/recipes/dunyahalleri.recipe b/recipes/dunyahalleri.recipe index 2cb4ad86f9..8d7df9ba4d 100644 --- a/recipes/dunyahalleri.recipe +++ b/recipes/dunyahalleri.recipe @@ -10,6 +10,7 @@ from shutil import copyfile from calibre import strftime from calibre.ebooks.BeautifulSoup import Tag from calibre.web.feeds.recipes import BasicNewsRecipe +from calibre.utils.resources import get_path from PIL import Image, ImageDraw, ImageFont __license__ = 'GPL v3' @@ -168,7 +169,7 @@ class DunyaHalleri(BasicNewsRecipe): self.cover_img_path = None 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) width, height = draw.textsize(text, font=font) left = max(int((self.COVER_WIDTH - width) / 2.), 0) diff --git a/recipes/dunyahalleri_haftaninozeti.recipe b/recipes/dunyahalleri_haftaninozeti.recipe index 808976910c..60bedc5c5d 100644 --- a/recipes/dunyahalleri_haftaninozeti.recipe +++ b/recipes/dunyahalleri_haftaninozeti.recipe @@ -10,6 +10,7 @@ from shutil import copyfile from contextlib import closing from calibre.ebooks.BeautifulSoup import BeautifulSoup, BeautifulStoneSoup, Tag from calibre.web.feeds.recipes import BasicNewsRecipe +from calibre.utils.resources import get_path from PIL import Image, ImageDraw, ImageFont __license__ = 'GPL v3' @@ -232,7 +233,7 @@ class DunyaHalleri_HaftaninOzeti(BasicNewsRecipe): self.cover_img_path = None 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) width, height = draw.textsize(text, font=font) left = max(int((self.COVER_WIDTH - width) / 2.), 0) diff --git a/recipes/el_correo.recipe b/recipes/el_correo.recipe index 3854eb5074..7af992a5c6 100644 --- a/recipes/el_correo.recipe +++ b/recipes/el_correo.recipe @@ -130,7 +130,7 @@ class elcorreo(BasicNewsRecipe): # 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) else: link = None diff --git a/recipes/elpais_impreso.recipe b/recipes/elpais_impreso.recipe index fb67faedcb..8e288527e7 100644 --- a/recipes/elpais_impreso.recipe +++ b/recipes/elpais_impreso.recipe @@ -81,7 +81,7 @@ class ElPais_RSS(BasicNewsRecipe): def 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 self.log('Skipping non-article', url) return None diff --git a/recipes/expansion_spanish.recipe b/recipes/expansion_spanish.recipe index 74fec85199..7ba76a1723 100644 --- a/recipes/expansion_spanish.recipe +++ b/recipes/expansion_spanish.recipe @@ -147,7 +147,7 @@ class expansion_spanish(BasicNewsRecipe): # 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) else: link = None diff --git a/recipes/onda_rock.recipe b/recipes/onda_rock.recipe index 7c96cc5385..fc0f0d811d 100644 --- a/recipes/onda_rock.recipe +++ b/recipes/onda_rock.recipe @@ -26,5 +26,16 @@ class AdvancedUserRecipe1328535130(BasicNewsRecipe): masthead_url = 'http://api.ning.com/files/4ot8ampp*-rYQuwL2NoaHvVqcyu7VMyWyan12a9QMsJUWxk-q5V1-34wnD-Wj9B5qWjc1yPMLGiwQg8hZJxaySeaG2lx8hpV/2009_banner_ondarock.gif' # 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; + } + ''' diff --git a/recipes/respekt_magazine.recipe b/recipes/respekt_magazine.recipe index 41fed613e0..c9256aae49 100644 --- a/recipes/respekt_magazine.recipe +++ b/recipes/respekt_magazine.recipe @@ -159,7 +159,7 @@ class respektRecipe(BasicNewsRecipe): for par in paragraphs[:-1]: prev = par.getprevious() # 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" # Fix subtitle for Téma try: diff --git a/setup/check.py b/setup/check.py index f3e9e7a307..22c88ccd31 100644 --- a/setup/check.py +++ b/setup/check.py @@ -77,7 +77,7 @@ class Check(Command): def file_has_errors(self, f): ext = os.path.splitext(f)[1] 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 if ext == '.pyj': p = subprocess.Popen(['rapydscript', 'lint', f]) diff --git a/src/calibre/translations/dynamic.py b/src/calibre/translations/dynamic.py index 97d1478fcf..5ad04e3cd0 100644 --- a/src/calibre/translations/dynamic.py +++ b/src/calibre/translations/dynamic.py @@ -8,6 +8,7 @@ __copyright__ = '2008, Marshall T. Vandegrift ' import io from gettext import GNUTranslations from calibre.utils.localization import get_lc_messages_path +from calibre.utils.resources import get_path from zipfile import ZipFile __all__ = ['translate'] @@ -22,7 +23,7 @@ def translate(lang, text): else: mpath = get_lc_messages_path(lang) 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: try: buf = io.BytesIO(zf.read(mpath + '/messages.mo')) diff --git a/src/calibre/utils/localization.py b/src/calibre/utils/localization.py index efb30ea1ed..6e0112e615 100644 --- a/src/calibre/utils/localization.py +++ b/src/calibre/utils/localization.py @@ -1,14 +1,14 @@ #!/usr/bin/env python +# License: GPLv3 Copyright: 2009, Kovid Goyal -__license__ = 'GPL v3' -__copyright__ = '2009, Kovid Goyal ' -__docformat__ = 'restructuredtext en' - -import os, locale, re, io +import io +import locale +import os +import re 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 _available_translations = None @@ -29,7 +29,7 @@ def available_translations(): def get_system_locale(): - from calibre.constants import iswindows, ismacos + from calibre.constants import ismacos, iswindows lang = None if iswindows: try: