diff --git a/recipes/folhadesaopaulo_sub.recipe b/recipes/folhadesaopaulo_sub.recipe index c3a4ac2cf6..eed2870645 100644 --- a/recipes/folhadesaopaulo_sub.recipe +++ b/recipes/folhadesaopaulo_sub.recipe @@ -125,7 +125,7 @@ img { background: none !important; float: none; margin: 0px; } break elif strpost.startswith(' post: ', post) diff --git a/ruff-strict-pep8.toml b/ruff-strict-pep8.toml index 62eb3e1300..5d0aeb3fb2 100644 --- a/ruff-strict-pep8.toml +++ b/ruff-strict-pep8.toml @@ -22,7 +22,7 @@ quote-style = 'single' explicit-preview-rules = true ignore = [ 'E402', 'E722', 'E741', - 'UP012', 'UP030', 'UP032', 'UP038', 'C413', 'C420', 'PIE790', 'PIE794', 'PIE810', + 'UP012', 'UP030', 'UP032', 'UP038', 'C413', 'C420', 'PIE790', 'PIE794', 'RUF001', 'RUF002', 'RUF003', 'RUF005', 'RUF012', 'RUF013', 'RUF015', 'RUF031', 'RUF100', 'F841', # because in preview, unused tuple unpacking variable that not use dummy syntax (prefix '_' underscore) # raise error 'unused-variable', sigh (https://github.com/astral-sh/ruff/issues/8884) diff --git a/setup/build.py b/setup/build.py index 685f166126..db3f567cde 100644 --- a/setup/build.py +++ b/setup/build.py @@ -520,7 +520,7 @@ class Build(Command): def get(src: str, env: Environment, for_tooling: bool = False) -> CompileCommand: compiler = env.cxx if ext.needs_cxx else env.cc obj = self.j(obj_dir, os.path.splitext(self.b(src))[0]+env.obj_suffix) - inf = env.cc_input_cpp_flag if src.endswith('.cpp') or src.endswith('.cxx') else env.cc_input_c_flag + inf = env.cc_input_cpp_flag if src.endswith(('.cpp', '.cxx')) else env.cc_input_c_flag sinc = [inf, src] if env.cc_output_flag.startswith('/'): if for_tooling: # clangd gets confused by cl.exe style source and output flags diff --git a/setup/gui.py b/setup/gui.py index 054eccf200..b94dfb5fbf 100644 --- a/setup/gui.py +++ b/setup/gui.py @@ -30,7 +30,7 @@ class GUI(Command): path = os.path.abspath(os.path.join(root, name)) if name.endswith('.ui'): forms.append(path) - elif name.endswith('_ui.py') or name.endswith('_ui.pyc'): + elif name.endswith(('_ui.py', '_ui.pyc')): fname = path.rpartition('_')[0] + '.ui' if not os.path.exists(fname): os.remove(path) diff --git a/setup/hosting.py b/setup/hosting.py index 8dc1a73144..d7a265959b 100644 --- a/setup/hosting.py +++ b/setup/hosting.py @@ -349,7 +349,7 @@ def generate_index(): # {{{ .format(osx[0], 'OS X Disk Image (.dmg)') ) linux = [ - x for x in files if x.endswith('.txz') or x.endswith('tar.bz2') + x for x in files if x.endswith(('.txz', 'tar.bz2')) ] if linux: def ldesc(x): @@ -366,7 +366,7 @@ def generate_index(): # {{{ ' '.join(linux) ) ) - source = [x for x in files if x.endswith('.xz') or x.endswith('.gz')] + source = [x for x in files if x.endswith(('.xz', '.gz'))] if source: body.append( '
Source Code
{1}
' diff --git a/src/calibre/devices/kobo/driver.py b/src/calibre/devices/kobo/driver.py index cf65ff326c..23b93b26b9 100644 --- a/src/calibre/devices/kobo/driver.py +++ b/src/calibre/devices/kobo/driver.py @@ -637,7 +637,7 @@ class KOBO(USBMS): # print('Add book to metadata: ') # print('prefix: ' + prefix) lpath = path.partition(prefix)[2] - if lpath.startswith('/') or lpath.startswith('\\'): + if lpath.startswith(('/', '\\')): lpath = lpath[1:] # print('path: ' + lpath) book = self.book_class(prefix, lpath, info.title, other=info) diff --git a/src/calibre/devices/smart_device_app/driver.py b/src/calibre/devices/smart_device_app/driver.py index 0ad6ba8d38..ab01d6d23d 100644 --- a/src/calibre/devices/smart_device_app/driver.py +++ b/src/calibre/devices/smart_device_app/driver.py @@ -472,7 +472,7 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin): special_tag = None if mdata.tags: for t in mdata.tags: - if t.startswith(_('News')) or t.startswith('/'): + if t.startswith((_('News'), '/')): special_tag = t break diff --git a/src/calibre/devices/usbms/driver.py b/src/calibre/devices/usbms/driver.py index 88562bd864..9810fc9d4f 100644 --- a/src/calibre/devices/usbms/driver.py +++ b/src/calibre/devices/usbms/driver.py @@ -386,7 +386,7 @@ class USBMS(CLI, Device): self._main_prefix) continue lpath = path.partition(prefix)[2] - if lpath.startswith('/') or lpath.startswith('\\'): + if lpath.startswith(('/', '\\')): lpath = lpath[1:] book = self.book_class(prefix, lpath, other=info) if book.size is None: diff --git a/src/calibre/devices/utils.py b/src/calibre/devices/utils.py index da71e3dbfe..56ce60e81c 100644 --- a/src/calibre/devices/utils.py +++ b/src/calibre/devices/utils.py @@ -80,7 +80,7 @@ def create_upload_path(mdata, fname, template, sanitize, special_tag = None if mdata.tags: for t in mdata.tags: - if t.startswith(_('News')) or t.startswith('/'): + if t.startswith((_('News'), '/')): special_tag = t break diff --git a/src/calibre/ebooks/conversion/cli.py b/src/calibre/ebooks/conversion/cli.py index 53db521631..872c26778d 100644 --- a/src/calibre/ebooks/conversion/cli.py +++ b/src/calibre/ebooks/conversion/cli.py @@ -347,7 +347,7 @@ def create_option_parser(args, log): def abspath(x): - if x.startswith('http:') or x.startswith('https:'): + if x.startswith(('http:', 'https:')): return x return os.path.abspath(os.path.expanduser(x)) diff --git a/src/calibre/ebooks/conversion/preprocess.py b/src/calibre/ebooks/conversion/preprocess.py index 3a9bc01b99..79d3daedb2 100644 --- a/src/calibre/ebooks/conversion/preprocess.py +++ b/src/calibre/ebooks/conversion/preprocess.py @@ -326,8 +326,7 @@ class CSSPreProcessor: ans, namespaced = [], False for line in data.splitlines(): ll = line.lstrip() - if not (namespaced or ll.startswith('@import') or not ll or - ll.startswith('@charset')): + if not (namespaced or ll.startswith(('@import', '@charset')) or not ll): ans.append(XHTML_CSS_NAMESPACE.strip()) namespaced = True ans.append(line) diff --git a/src/calibre/ebooks/docx/dump.py b/src/calibre/ebooks/docx/dump.py index 2e566571dc..5de53987fd 100644 --- a/src/calibre/ebooks/docx/dump.py +++ b/src/calibre/ebooks/docx/dump.py @@ -17,7 +17,7 @@ from calibre.utils.zipfile import ZipFile def pretty_all_xml_in_dir(path): for f in walk(path): - if f.endswith('.xml') or f.endswith('.rels'): + if f.endswith(('.xml', '.rels')): with open(f, 'r+b') as stream: raw = stream.read() if raw: diff --git a/src/calibre/ebooks/mobi/reader/markup.py b/src/calibre/ebooks/mobi/reader/markup.py index a65885f721..c4aec0b073 100644 --- a/src/calibre/ebooks/mobi/reader/markup.py +++ b/src/calibre/ebooks/mobi/reader/markup.py @@ -145,7 +145,7 @@ def update_flow_links(mobi8_reader, resource_map, log): for j in range(1, len(srcpieces), 2): tag = srcpieces[j] - if tag.startswith('.+)') - if url_pattern.startswith('http:') or url_pattern.startswith('https:'): + if url_pattern.startswith(('http:', 'https:')): url_pattern = '(?:http|https):' + url_pattern.partition(':')[2] new_id = re.compile(url_pattern) new_id = new_id.search(text).group('new_id') diff --git a/src/calibre/gui2/tag_browser/model.py b/src/calibre/gui2/tag_browser/model.py index 2ff3aeb686..b6461e433f 100644 --- a/src/calibre/gui2/tag_browser/model.py +++ b/src/calibre/gui2/tag_browser/model.py @@ -1443,7 +1443,7 @@ class TagsModel(QAbstractItemModel): # {{{ def key_func(val): if order == 'display_name': return icu_lower(self.db.field_metadata[val]['name']) - return icu_lower(val[1:] if val.startswith('#') or val.startswith('@') else val) + return icu_lower(val[1:] if val.startswith(('#', '@')) else val) direction = tweaks.get('tag_browser_category_default_sort_direction', 'ascending') if direction not in ('ascending', 'descending'): print('Tweak tag_browser_category_default_sort_direction is not valid. Ignored') diff --git a/src/calibre/gui2/viewer/main.py b/src/calibre/gui2/viewer/main.py index 022b5fb0b2..39f4bbeadb 100644 --- a/src/calibre/gui2/viewer/main.py +++ b/src/calibre/gui2/viewer/main.py @@ -203,8 +203,7 @@ def main(args=sys.argv): opts, args = parser.parse_args(args) oat = opts.open_at if oat and not ( - oat.startswith('toc:') or oat.startswith('toc-href:') or oat.startswith('toc-href-contains:') or - oat.startswith('epubcfi(/') or is_float(oat) or oat.startswith('ref:') or oat.startswith('search:') or oat.startswith('regex:')): + oat.startswith(('toc:', 'toc-href:', 'toc-href-contains:', 'epubcfi(/', 'ref:', 'search:', 'regex:')) or is_float(oat)): raise SystemExit(f'Not a valid --open-at value: {opts.open_at}') if not opts.new_instance and get_session_pref('singleinstance', False): diff --git a/src/calibre/gui2/viewer/web_view.py b/src/calibre/gui2/viewer/web_view.py index cea2c3fbd8..753d687898 100644 --- a/src/calibre/gui2/viewer/web_view.py +++ b/src/calibre/gui2/viewer/web_view.py @@ -112,7 +112,7 @@ def background_image(encoded_fname=''): with open(make_long_path_useable(img_path), 'rb') as f: return mt, f.read() except FileNotFoundError: - if fname.startswith('https://') or fname.startswith('http://'): + if fname.startswith(('https://', 'http://')): from calibre import browser br = browser() try: diff --git a/src/calibre/gui2/widgets.py b/src/calibre/gui2/widgets.py index 5bc0b9b0d1..134099049a 100644 --- a/src/calibre/gui2/widgets.py +++ b/src/calibre/gui2/widgets.py @@ -1012,13 +1012,13 @@ class PythonHighlighter(QSyntaxHighlighter): # {{{ self.setFormat(0, textLength, self.Formats['normal']) - if text.startswith('Traceback') or text.startswith('Error: '): + if text.startswith(('Traceback', 'Error: ')): self.setCurrentBlockState(ERROR) self.setFormat(0, textLength, self.Formats['error']) return if prevState == ERROR and \ - not (text.startswith('>>>') or text.startswith('#')): + not (text.startswith(('>>>', '#'))): self.setCurrentBlockState(ERROR) self.setFormat(0, textLength, self.Formats['error']) diff --git a/src/calibre/library/caches.py b/src/calibre/library/caches.py index 3ce620f9b0..d8bb096ad0 100644 --- a/src/calibre/library/caches.py +++ b/src/calibre/library/caches.py @@ -395,7 +395,7 @@ class ResultCache(SearchQueryParser): # {{{ elif query in self.local_thismonth: qd = now() field_count = 2 - elif query.endswith(self.local_daysago) or query.endswith(self.untrans_daysago): + elif query.endswith((self.local_daysago, self.untrans_daysago)): num = query[0:-(self.untrans_daysago_len if query.endswith(self.untrans_daysago) else self.local_daysago_len)] try: qd = now() - timedelta(int(num)) diff --git a/src/calibre/srv/http_response.py b/src/calibre/srv/http_response.py index 97b6ec910e..557bb05dec 100644 --- a/src/calibre/srv/http_response.py +++ b/src/calibre/srv/http_response.py @@ -677,8 +677,7 @@ class HTTPConnection(HTTPRequest): else: output = GeneratedOutput(output) ct = outheaders.get('Content-Type', '').partition(';')[0] - compressible = (not ct or ct.startswith('text/') or ct.startswith('image/svg') or - ct.partition(';')[0] in COMPRESSIBLE_TYPES) + compressible = (not ct or ct.startswith(('text/', 'image/svg')) or ct.partition(';')[0] in COMPRESSIBLE_TYPES) compressible = (compressible and request.status_code == http_client.OK and (opts.compress_min_size > -1 and output.content_length >= opts.compress_min_size) and acceptable_encoding(request.inheaders.get('Accept-Encoding', '')) and not is_http1) diff --git a/src/calibre/utils/run_tests.py b/src/calibre/utils/run_tests.py index 56c49dda0a..e9de38617e 100644 --- a/src/calibre/utils/run_tests.py +++ b/src/calibre/utils/run_tests.py @@ -65,7 +65,7 @@ def find_tests_in_package(package, excludes=('main.py',)): excludes = set(excludes) | {x + 'c' for x in excludes} seen = set() for x in items: - if (x.endswith('.py') or x.endswith('.pyc')) and x not in excludes: + if (x.endswith(('.py', '.pyc'))) and x not in excludes: q = x.rpartition('.')[0] if q in seen: continue diff --git a/src/calibre/web/feeds/news.py b/src/calibre/web/feeds/news.py index 78282a1d99..4cab2dcf87 100644 --- a/src/calibre/web/feeds/news.py +++ b/src/calibre/web/feeds/news.py @@ -623,7 +623,7 @@ class BasicNewsRecipe(Recipe): for key in article.keys(): if key.endswith('_origlink'): url = article[key] - if url and (url.startswith('http://') or url.startswith('https://')): + if url and (url.startswith(('http://', 'https://'))): return url ans = article.get('link', None) if not ans and getattr(article, 'links', None):