From 55721050762f9fa77efd6adffceeb6fd86d9ed75 Mon Sep 17 00:00:00 2001 From: un-pogaz <46523284+un-pogaz@users.noreply.github.com> Date: Fri, 24 Jan 2025 11:14:16 +0100 Subject: [PATCH] upgrade code to Python 3 (auto-fix) ruff 'UP' --- icons/icns/make_iconsets.py | 1 - icons/make_ico_files.py | 1 - imgsrc/generate.py | 1 - imgsrc/render-logo.py | 1 - imgsrc/srv/generate.py | 1 - manual/build.py | 1 - manual/conf.py | 21 ++++++++++---------- manual/custom.py | 2 +- ruff-strict-pep8.toml | 10 ++++++++-- src/calibre/devices/kindle/bookmark.py | 2 +- src/calibre/devices/kobo/bookmark.py | 2 +- src/calibre/ebooks/djvu/djvubzzdec.py | 2 +- src/calibre/ebooks/rtf/preprocess.py | 22 ++++++++++----------- src/calibre/gui2/dialogs/tag_list_editor.py | 2 +- src/calibre/utils/filenames.py | 2 +- 15 files changed, 35 insertions(+), 36 deletions(-) diff --git a/icons/icns/make_iconsets.py b/icons/icns/make_iconsets.py index c9bf6f88dc..bdc919e4da 100644 --- a/icons/icns/make_iconsets.py +++ b/icons/icns/make_iconsets.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' diff --git a/icons/make_ico_files.py b/icons/make_ico_files.py index 179d7606db..968be7bc56 100644 --- a/icons/make_ico_files.py +++ b/icons/make_ico_files.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' diff --git a/imgsrc/generate.py b/imgsrc/generate.py index 9adaeab79f..8d0e0c5426 100755 --- a/imgsrc/generate.py +++ b/imgsrc/generate.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2016, Kovid Goyal import argparse diff --git a/imgsrc/render-logo.py b/imgsrc/render-logo.py index 82d85072ae..0403760849 100755 --- a/imgsrc/render-logo.py +++ b/imgsrc/render-logo.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2016, Kovid Goyal diff --git a/imgsrc/srv/generate.py b/imgsrc/srv/generate.py index c56f3140f6..7f2d870774 100644 --- a/imgsrc/srv/generate.py +++ b/imgsrc/srv/generate.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2016, Kovid Goyal diff --git a/manual/build.py b/manual/build.py index f90eaf7b7a..e0dd62b30b 100755 --- a/manual/build.py +++ b/manual/build.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' diff --git a/manual/conf.py b/manual/conf.py index 3702a507c1..f9a896fd2a 100644 --- a/manual/conf.py +++ b/manual/conf.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # calibre documentation build configuration file, created by # sphinx-quickstart.py on Sun Mar 23 01:23:55 2008. @@ -64,7 +63,7 @@ language = os.environ.get('CALIBRE_OVERRIDE_LANG', 'en') def generated_langs(): try: return os.listdir(os.path.join(base, 'generated')) - except EnvironmentError as e: + except OSError as e: if e.errno != errno.ENOENT: raise return () @@ -105,7 +104,7 @@ if needs_localization: import gettext try: t = gettext.translation('simple_index', locale_dirs[0], [language]) - except IOError: + except OSError: pass else: title = t.gettext(title) @@ -176,7 +175,7 @@ def sort_languages(x): lc, name = x if lc == language: return '' - return sort_key(type(u'')(name)) + return sort_key(str(name)) website = 'https://calibre-ebook.com' @@ -193,13 +192,13 @@ extlinks = { } del sort_languages, get_language -epub_author = u'Kovid Goyal' -epub_publisher = u'Kovid Goyal' -epub_copyright = u'© {} Kovid Goyal'.format(date.today().year) -epub_description = u'Comprehensive documentation for calibre' -epub_identifier = u'https://manual.calibre-ebook.com' -epub_scheme = u'url' -epub_uid = u'S54a88f8e9d42455e9c6db000e989225f' +epub_author = 'Kovid Goyal' +epub_publisher = 'Kovid Goyal' +epub_copyright = '© {} Kovid Goyal'.format(date.today().year) +epub_description = 'Comprehensive documentation for calibre' +epub_identifier = 'https://manual.calibre-ebook.com' +epub_scheme = 'url' +epub_uid = 'S54a88f8e9d42455e9c6db000e989225f' epub_tocdepth = 4 epub_tocdup = True epub_cover = ('epub_cover.jpg', 'epub_cover_template.html') diff --git a/manual/custom.py b/manual/custom.py index cd588b5c28..89a28a279e 100644 --- a/manual/custom.py +++ b/manual/custom.py @@ -397,7 +397,7 @@ def add_html_context(app, pagename, templatename, context, *args): def guilabel_role(typ, rawtext, text, *args, **kwargs): from sphinx.roles import GUILabel - text = text.replace(u'->', u'\N{THIN SPACE}\N{RIGHTWARDS ARROW}\N{THIN SPACE}') + text = text.replace('->', '\N{THIN SPACE}\N{RIGHTWARDS ARROW}\N{THIN SPACE}') return GUILabel()(typ, rawtext, text, *args, **kwargs) diff --git a/ruff-strict-pep8.toml b/ruff-strict-pep8.toml index 986c49a613..b2dc7b31c4 100644 --- a/ruff-strict-pep8.toml +++ b/ruff-strict-pep8.toml @@ -17,11 +17,17 @@ exclude = [ quote-style = 'single' [lint] -ignore = ['E402', 'E722', 'E741'] -select = ['E', 'F', 'I', 'W', 'INT', 'Q'] +ignore = ['E402', 'E722', 'E741', 'UP012', 'UP030', 'UP031', 'UP032', 'UP038'] +select = ['E', 'F', 'I', 'W', 'INT', 'Q', 'UP'] [lint.per-file-ignores] +"recipes/*" = ['UP'] +"manual/plugin_examples/*" = ['UP'] "src/calibre/ebooks/unihandecode/*codepoints.py" = ['E501'] +"src/calibre/ebooks/metadata/sources/*" = ['UP'] +"src/calibre/gui2/store/stores/*" = ['UP'] +"src/calibre/gui2/tts/manager.py" = ['UP037'] +"src/calibre/utils/copy_files.py" = ['UP037'] "src/qt/*.py" = ['I'] "src/qt/*.pyi" = ['I'] diff --git a/src/calibre/devices/kindle/bookmark.py b/src/calibre/devices/kindle/bookmark.py index 52968c0446..72fdf61dea 100644 --- a/src/calibre/devices/kindle/bookmark.py +++ b/src/calibre/devices/kindle/bookmark.py @@ -6,7 +6,7 @@ import os from struct import unpack -class Bookmark(): # {{{ +class Bookmark: # {{{ ''' A simple class fetching bookmark data Kindle-specific diff --git a/src/calibre/devices/kobo/bookmark.py b/src/calibre/devices/kobo/bookmark.py index 75c437225d..e7739ae3f5 100644 --- a/src/calibre/devices/kobo/bookmark.py +++ b/src/calibre/devices/kobo/bookmark.py @@ -7,7 +7,7 @@ import os from calibre.prints import debug_print -class Bookmark(): # {{{ +class Bookmark: # {{{ ''' A simple class fetching bookmark data kobo-specific diff --git a/src/calibre/ebooks/djvu/djvubzzdec.py b/src/calibre/ebooks/djvu/djvubzzdec.py index 94fd53bac6..b1c8ede695 100644 --- a/src/calibre/ebooks/djvu/djvubzzdec.py +++ b/src/calibre/ebooks/djvu/djvubzzdec.py @@ -389,7 +389,7 @@ xmtf = ( # }}} -class BZZDecoder(): +class BZZDecoder: def __init__(self, infile, outfile): self.instream = infile diff --git a/src/calibre/ebooks/rtf/preprocess.py b/src/calibre/ebooks/rtf/preprocess.py index 2e9024a0de..e199c12b0f 100644 --- a/src/calibre/ebooks/rtf/preprocess.py +++ b/src/calibre/ebooks/rtf/preprocess.py @@ -14,7 +14,7 @@ In the process the UTF8 tokens are altered to be supported by the RTF2XML and al ''' -class tokenDelimitatorStart(): +class tokenDelimitatorStart: def __init__(self): pass @@ -26,7 +26,7 @@ class tokenDelimitatorStart(): return '{' -class tokenDelimitatorEnd(): +class tokenDelimitatorEnd: def __init__(self): pass @@ -38,7 +38,7 @@ class tokenDelimitatorEnd(): return '}' -class tokenControlWord(): +class tokenControlWord: def __init__(self, name, separator=''): self.name = name @@ -51,7 +51,7 @@ class tokenControlWord(): return self.name + self.separator -class tokenControlWordWithNumericArgument(): +class tokenControlWordWithNumericArgument: def __init__(self, name, argument, separator=''): self.name = name @@ -65,7 +65,7 @@ class tokenControlWordWithNumericArgument(): return self.name + repr(self.argument) + self.separator -class tokenControlSymbol(): +class tokenControlSymbol: def __init__(self, name): self.name = name @@ -77,7 +77,7 @@ class tokenControlSymbol(): return self.name -class tokenData(): +class tokenData: def __init__(self, data): self.data = data @@ -89,7 +89,7 @@ class tokenData(): return self.data -class tokenBinN(): +class tokenBinN: def __init__(self, data, separator=''): self.data = data @@ -102,7 +102,7 @@ class tokenBinN(): return '\\bin' + repr(len(self.data)) + self.separator + self.data -class token8bitChar(): +class token8bitChar: def __init__(self, data): self.data = data @@ -114,7 +114,7 @@ class token8bitChar(): return "\\'" + self.data -class tokenUnicode(): +class tokenUnicode: def __init__(self, data, separator='', current_ucn=1, eqList=[]): self.data = data @@ -155,7 +155,7 @@ def isString(buffer, string): return buffer == string -class RtfTokenParser(): +class RtfTokenParser: def __init__(self, tokens): self.tokens = tokens @@ -256,7 +256,7 @@ class RtfTokenParser(): return ''.join(result) -class RtfTokenizer(): +class RtfTokenizer: def __init__(self, rtfData): self.rtfData = [] diff --git a/src/calibre/gui2/dialogs/tag_list_editor.py b/src/calibre/gui2/dialogs/tag_list_editor.py index deb766b886..dded08503f 100644 --- a/src/calibre/gui2/dialogs/tag_list_editor.py +++ b/src/calibre/gui2/dialogs/tag_list_editor.py @@ -151,7 +151,7 @@ class NotesTableWidgetItem(QTableWidgetItem): return self._sort_val < other._sort_val -class NotesUtilities(): +class NotesUtilities: def __init__(self, table, category, item_id_getter): self.table = table diff --git a/src/calibre/utils/filenames.py b/src/calibre/utils/filenames.py index 83e3b5d098..6a4d4c74d1 100644 --- a/src/calibre/utils/filenames.py +++ b/src/calibre/utils/filenames.py @@ -416,7 +416,7 @@ class WindowsAtomicFolderMove: self.close_handles() if e.winerror == winutil.ERROR_SHARING_VIOLATION: - err = IOError(errno.EACCES, + err = OSError(errno.EACCES, _('File is open in another process')) err.filename = f raise err