Reformatted sources with 'Black'. eric7

Tue, 20 Sep 2022 17:00:19 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 20 Sep 2022 17:00:19 +0200
branch
eric7
changeset 50
4d34c264a71d
parent 49
ef86e0082122
child 51
619765dd3aa8

Reformatted sources with 'Black'.

.hgignore file | annotate | diff | comparison | revisions
PluginWizardDataUriEncoder.epj file | annotate | diff | comparison | revisions
PluginWizardDataUriEncoder.py file | annotate | diff | comparison | revisions
WizardDataUriEncoder/DataUriEncoderWizardDialog.py file | annotate | diff | comparison | revisions
--- a/.hgignore	Thu Dec 30 13:58:24 2021 +0100
+++ b/.hgignore	Tue Sep 20 17:00:19 2022 +0200
@@ -1,6 +1,7 @@
 glob:.eric7project
 glob:.eric6project
 glob:.ropeproject
+glob:.jedi
 glob:.directory
 glob:**.pyc
 glob:**.pyo
--- a/PluginWizardDataUriEncoder.epj	Thu Dec 30 13:58:24 2021 +0100
+++ b/PluginWizardDataUriEncoder.epj	Tue Sep 20 17:00:19 2022 +0200
@@ -1,19 +1,21 @@
 {
   "header": {
     "comment": "eric project file for project PluginWizardDataUriEncoder",
-    "copyright": "Copyright (C) 2021 Detlev Offenbach, detlevqdie-offenbachs.de"
+    "copyright": "Copyright (C) 2022 Detlev Offenbach, detlev@die-offenbachs.de"
   },
   "project": {
     "AUTHOR": "Detlev Offenbach",
     "CHECKERSPARMS": {
       "Pep8Checker": {
         "AnnotationsChecker": {
+          "AllowStarArgAny": false,
           "AllowUntypedDefs": false,
           "AllowUntypedNested": false,
           "DispatchDecorators": [
             "singledispatch",
             "singledispatchmethod"
           ],
+          "ForceFutureAnnotations": false,
           "MaximumComplexity": 3,
           "MaximumLength": 7,
           "MinimumCoverage": 75,
@@ -59,7 +61,7 @@
         },
         "CopyrightAuthor": "",
         "CopyrightMinFileSize": 0,
-        "DocstringType": "eric",
+        "DocstringType": "eric_black",
         "EnabledCheckerCategories": "C, D, E, M, N, S, Y, W",
         "ExcludeFiles": "*/Ui_*.py, */*_rc.py",
         "ExcludeMessages": "C101,E265,E266,E305,E402,M201,M301,M302,M303,M304,M305,M306,M307,M308,M311,M312,M313,M314,M315,M321,M701,M702,M811,M834,N802,N803,N807,N808,N821,W293,W504,Y119,Y401,Y402",
@@ -67,12 +69,17 @@
         "FixIssues": false,
         "FutureChecker": "",
         "HangClosing": false,
+        "ImportsChecker": {
+          "ApplicationPackageNames": [],
+          "BanRelativeImports": "",
+          "BannedModules": []
+        },
         "IncludeMessages": "",
         "LineComplexity": 25,
         "LineComplexityScore": 10,
         "MaxCodeComplexity": 10,
-        "MaxDocLineLength": 79,
-        "MaxLineLength": 79,
+        "MaxDocLineLength": 88,
+        "MaxLineLength": 88,
         "NoFixCodes": "E501",
         "RepeatMessages": true,
         "SecurityChecker": {
@@ -129,7 +136,8 @@
         "useRecursion": true
       }
     },
-    "EMAIL": "detlevqdie-offenbachs.de",
+    "EMAIL": "detlev@die-offenbachs.de",
+    "EMBEDDED_VENV": false,
     "EOL": 1,
     "FILETYPES": {
       "*.epj": "OTHERS",
@@ -163,6 +171,7 @@
     },
     "INTERFACES": [],
     "LEXERASSOCS": {},
+    "LICENSE": "GNU General Public License v3 or later (GPLv3+)",
     "MAINSCRIPT": "PluginWizardDataUriEncoder.py",
     "MAKEPARAMS": {
       "MakeEnabled": false,
@@ -177,12 +186,29 @@
       ".hgignore",
       "ChangeLog",
       "PKGLIST",
+      "PluginWizardDataUriEncoder.epj",
       "PluginWizardDataUriEncoder.zip",
       "WizardDataUriEncoder/Documentation/LICENSE.GPL3",
-      "WizardDataUriEncoder/Documentation/source",
-      "PluginWizardDataUriEncoder.epj"
+      "WizardDataUriEncoder/Documentation/source"
     ],
-    "OTHERTOOLSPARMS": {},
+    "OTHERTOOLSPARMS": {
+      "Black": {
+        "exclude": "/(\\.direnv|\\.eggs|\\.git|\\.hg|\\.mypy_cache|\\.nox|\\.tox|\\.venv|venv|\\.svn|_build|buck-out|build|dist|__pypackages__)/",
+        "extend-exclude": "",
+        "force-exclude": "",
+        "line-length": 88,
+        "skip-magic-trailing-comma": false,
+        "skip-string-normalization": false,
+        "source": "project",
+        "target-version": [
+          "py311",
+          "py310",
+          "py39",
+          "py38",
+          "py37"
+        ]
+      }
+    },
     "PACKAGERSPARMS": {},
     "PROGLANGUAGE": "Python3",
     "PROJECTTYPE": "E7Plugin",
@@ -204,6 +230,7 @@
     "SPELLEXCLUDES": "",
     "SPELLLANGUAGE": "en_US",
     "SPELLWORDS": "",
+    "TESTING_FRAMEWORK": "",
     "TRANSLATIONEXCEPTIONS": [],
     "TRANSLATIONPATTERN": "WizardDataUriEncoder/i18n/datauriencoder_%language%.ts",
     "TRANSLATIONS": [
--- a/PluginWizardDataUriEncoder.py	Thu Dec 30 13:58:24 2021 +0100
+++ b/PluginWizardDataUriEncoder.py	Tue Sep 20 17:00:19 2022 +0200
@@ -40,33 +40,34 @@
     """
     Class implementing the base64 data URI encoder wizard plug-in.
     """
+
     def __init__(self, ui):
         """
         Constructor
-        
+
         @param ui reference to the user interface object
         @type UserInterface
         """
         QObject.__init__(self, ui)
-        
+
         self.__ui = ui
         self.__action = None
-        
+
         self.__translator = None
         self.__loadTranslator()
-    
+
     def activate(self):
         """
         Public method to activate this plug-in.
-        
+
         @return tuple of None and activation status
         @rtype (None, bool)
         """
         self.__initAction()
         self.__initMenu()
-        
+
         return None, True
-    
+
     def deactivate(self):
         """
         Public method to deactivate this plug-in.
@@ -74,8 +75,8 @@
         menu = self.__ui.getMenu("wizards")
         if menu:
             menu.removeAction(self.__action)
-        self.__ui.removeEricActions([self.__action], 'wizards')
-    
+        self.__ui.removeEricActions([self.__action], "wizards")
+
     def __loadTranslator(self):
         """
         Private method to load the translation file.
@@ -84,7 +85,8 @@
             loc = self.__ui.getLocale()
             if loc and loc != "C":
                 locale_dir = os.path.join(
-                    os.path.dirname(__file__), "WizardDataUriEncoder", "i18n")
+                    os.path.dirname(__file__), "WizardDataUriEncoder", "i18n"
+                )
                 translation = "datauriencoder_{0}".format(loc)
                 translator = QTranslator(None)
                 loaded = translator.load(translation, locale_dir)
@@ -92,29 +94,35 @@
                     self.__translator = translator
                     ericApp().installTranslator(self.__translator)
                 else:
-                    print("Warning: translation file '{0}' could not be"
-                          " loaded.".format(translation))
+                    print(
+                        "Warning: translation file '{0}' could not be"
+                        " loaded.".format(translation)
+                    )
                     print("Using default.")
-    
+
     def __initAction(self):
         """
         Private method to initialize the action.
         """
         self.__action = EricAction(
-            self.tr('Base64 Data Uri Encoder Wizard'),
-            self.tr('Base&64 Data Uri Encoder Wizard...'),
-            0, 0, self,
-            'wizards_datauriencoder')
-        self.__action.setStatusTip(self.tr(
-            'Base64 Data Uri Encoder Wizard'))
-        self.__action.setWhatsThis(self.tr(
-            """<b>Base64 Data Uri Encoder Wizard</b>"""
-            """<p>This wizard opens a dialog for entering all the parameters"""
-            """ needed to create code for a base64 encoded data URI.</p>"""
-        ))
+            self.tr("Base64 Data Uri Encoder Wizard"),
+            self.tr("Base&64 Data Uri Encoder Wizard..."),
+            0,
+            0,
+            self,
+            "wizards_datauriencoder",
+        )
+        self.__action.setStatusTip(self.tr("Base64 Data Uri Encoder Wizard"))
+        self.__action.setWhatsThis(
+            self.tr(
+                """<b>Base64 Data Uri Encoder Wizard</b>"""
+                """<p>This wizard opens a dialog for entering all the parameters"""
+                """ needed to create code for a base64 encoded data URI.</p>"""
+            )
+        )
         self.__action.triggered.connect(self.__handle)
-        
-        self.__ui.addEricActions([self.__action], 'wizards')
+
+        self.__ui.addEricActions([self.__action], "wizards")
 
     def __initMenu(self):
         """
@@ -123,22 +131,24 @@
         menu = self.__ui.getMenu("wizards")
         if menu:
             menu.addAction(self.__action)
-    
+
     def __handle(self):
         """
         Private method to handle the wizards action.
         """
         editor = ericApp().getObject("ViewManager").activeWindow()
-        
+
         if editor is None:
             EricMessageBox.critical(
                 self.__ui,
-                self.tr('No current editor'),
-                self.tr('Please open or create a file first.'))
+                self.tr("No current editor"),
+                self.tr("Please open or create a file first."),
+            )
         else:
             from WizardDataUriEncoder.DataUriEncoderWizardDialog import (
-                DataUriEncoderWizardDialog
+                DataUriEncoderWizardDialog,
             )
+
             dlg = DataUriEncoderWizardDialog(None)
             if dlg.exec() == QDialog.DialogCode.Accepted:
                 code = dlg.getCode()
@@ -149,5 +159,6 @@
                     editor.insertAt(code, line, index)
                     editor.endUndoAction()
 
+
 #
 # eflag: noqa = M801
--- a/WizardDataUriEncoder/DataUriEncoderWizardDialog.py	Thu Dec 30 13:58:24 2021 +0100
+++ b/WizardDataUriEncoder/DataUriEncoderWizardDialog.py	Tue Sep 20 17:00:19 2022 +0200
@@ -15,9 +15,7 @@
 import os
 
 from PyQt6.QtCore import pyqtSlot
-from PyQt6.QtWidgets import (
-    QDialog, QDialogButtonBox, QApplication, QInputDialog
-)
+from PyQt6.QtWidgets import QDialog, QDialogButtonBox, QApplication, QInputDialog
 
 from EricWidgets import EricMessageBox
 from EricWidgets.EricPathPicker import EricPathPickerModes
@@ -29,34 +27,31 @@
 
 
 DataUriTemplates = {
-    "Python3": "\n".join([
-        "#!/usr/bin/env python3",
-        "# -*- coding: utf-8 -*-",
-        "",
-        "from base64 import b64decode",
-        "from io import BytesIO",
-        "",
-        "#metadata",
-        "__author__ = '{0}'",
-        "__date__ = '{1}'",
-        "",
-        "",
-        "embedded_file = BytesIO(b64decode(",
-        "    {2}",
-        "))",
-        "print(embedded_file.read())",
-    ]),
-    
-    "CSS":
-        "html, body {{ margin:0; padding:0; background: url({0})"
-        " no-repeat center center fixed; background-size:cover"
-        " }}",
-    
+    "Python3": "\n".join(
+        [
+            "#!/usr/bin/env python3",
+            "# -*- coding: utf-8 -*-",
+            "",
+            "from base64 import b64decode",
+            "from io import BytesIO",
+            "",
+            "#metadata",
+            "__author__ = '{0}'",
+            "__date__ = '{1}'",
+            "",
+            "",
+            "embedded_file = BytesIO(b64decode(",
+            "    {2}",
+            "))",
+            "print(embedded_file.read())",
+        ]
+    ),
+    "CSS": "html, body {{ margin:0; padding:0; background: url({0})"
+    " no-repeat center center fixed; background-size:cover"
+    " }}",
     "HTML": '<img src={0} alt="{1}" title="{1}"/>',
-    
     "JavaScript": "var embedded_file = window.atob({0}); ",
-    
-    "QML": "Image {{ source: {0} }} "
+    "QML": "Image {{ source: {0} }} ",
 }
 
 
@@ -64,47 +59,50 @@
     """
     Class implementing the base64 data URI encoder wizard dialog.
     """
+
     def __init__(self, parent=None):
         """
         Constructor
-        
+
         @param parent reference to the parent widget
         @type QWidget
         """
         super().__init__(parent)
         self.setupUi(self)
-        
-        self.buttonBox.button(
-            QDialogButtonBox.StandardButton.Ok).setEnabled(False)
-        
+
+        self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(False)
+
         self.filePicker.setWindowTitle(self.tr("Data URI Encoder"))
         self.filePicker.setMode(EricPathPickerModes.OPEN_FILE_MODE)
-        self.filePicker.setFilters(self.tr(
-            "Audio Files (*.flac *.mp3 *.ogg *.wav *.weba *.wma);;"
-            "Image Files (*.gif *.ico *.jpg *.png *.svg *.tif *.webp"
-            " *.xpm);;"
-            "Video Files (*.3gp *.avi *.flv *.mp4 *.ogv *.webm *.wmv);;"
-            "All Files (*)"
-        ))
+        self.filePicker.setFilters(
+            self.tr(
+                "Audio Files (*.flac *.mp3 *.ogg *.wav *.weba *.wma);;"
+                "Image Files (*.gif *.ico *.jpg *.png *.svg *.tif *.webp"
+                " *.xpm);;"
+                "Video Files (*.3gp *.avi *.flv *.mp4 *.ogv *.webm *.wmv);;"
+                "All Files (*)"
+            )
+        )
         self.filePicker.setDefaultDirectory(
-            Preferences.getMultiProject("Workspace") or
-            Utilities.getHomeDir()
+            Preferences.getMultiProject("Workspace") or Utilities.getHomeDir()
         )
-        
-        self.embeddingComboBox.addItems([
-            self.tr('Do not generate code'),                    # 0
-            self.tr('Generate Python3 embedding code'),         # 1
-            self.tr('Generate CSS embedding code'),             # 2
-            self.tr('Generate HTML embedding code'),            # 3
-            self.tr('Generate JavaScript embedding code'),      # 4
-            self.tr('Generate QML embedding code'),             # 5
-        ])
-    
+
+        self.embeddingComboBox.addItems(
+            [
+                self.tr("Do not generate code"),  # 0
+                self.tr("Generate Python3 embedding code"),  # 1
+                self.tr("Generate CSS embedding code"),  # 2
+                self.tr("Generate HTML embedding code"),  # 3
+                self.tr("Generate JavaScript embedding code"),  # 4
+                self.tr("Generate QML embedding code"),  # 5
+            ]
+        )
+
     @pyqtSlot(int)
     def on_embeddingComboBox_currentIndexChanged(self, index):
         """
         Private slot to handle the selection of an embedding method.
-        
+
         @param index index of the selected entry
         @type int
         """
@@ -114,7 +112,7 @@
         else:
             self.encryptCheckBox.setChecked(False)
             self.dataCheckBox.setChecked(False)
-    
+
     @pyqtSlot()
     def on_encodeButton_clicked(self):
         """
@@ -123,7 +121,7 @@
         filepath = self.filePicker.text().strip()
         mime = mimetypes.guess_type(filepath, strict=False)
         mimetype = mime if mime is not None else self.__askMime()
-        
+
         if os.path.getsize(filepath) // 1024 // 1024 >= 1:
             res = EricMessageBox.warning(
                 self,
@@ -131,21 +129,21 @@
                 self.tr(
                     """The file size is > 1 Megabyte. Encoding this will"""
                     """ take some time depending on your CPU processing"""
-                    """ power!"""),
-                EricMessageBox.Cancel |
-                EricMessageBox.Ok,
-                EricMessageBox.Cancel)
+                    """ power!"""
+                ),
+                EricMessageBox.Cancel | EricMessageBox.Ok,
+                EricMessageBox.Cancel,
+            )
             if res == EricMessageBox.Cancel:
                 return
-        
+
         try:
             with open(filepath, "rb") as f:
                 output = '"{0}{1}{2}{3}"'.format(
-                    'data:' if self.dataCheckBox.isChecked() else '',
-                    mimetype if self.dataCheckBox.isChecked() else '',
-                    ';charset=utf-8;base64,' if self.dataCheckBox.isChecked()
-                    else '',
-                    base64.b64encode(f.read()).decode()
+                    "data:" if self.dataCheckBox.isChecked() else "",
+                    mimetype if self.dataCheckBox.isChecked() else "",
+                    ";charset=utf-8;base64," if self.dataCheckBox.isChecked() else "",
+                    base64.b64encode(f.read()).decode(),
                 )
         except OSError as err:
             EricMessageBox.critical(
@@ -153,34 +151,37 @@
                 self.tr("Data URI Encoder"),
                 self.tr(
                     """<p>The file <b>{0}</b> could not be read.</p>"""
-                    """<p>Reason: {1}</p>""").format(filepath, str(err)))
+                    """<p>Reason: {1}</p>"""
+                ).format(filepath, str(err)),
+            )
             return
-        if self.embeddingComboBox.currentIndex() == 1:          # Python 3
+        if self.embeddingComboBox.currentIndex() == 1:  # Python 3
             output = DataUriTemplates["Python3"].format(
                 getpass.getuser(),
-                datetime.datetime.now().isoformat().split('.')[0], output)
-        elif self.embeddingComboBox.currentIndex() == 2:        # CSS
+                datetime.datetime.now().isoformat().split(".")[0],
+                output,
+            )
+        elif self.embeddingComboBox.currentIndex() == 2:  # CSS
             output = DataUriTemplates["CSS"].format(output)
-        elif self.embeddingComboBox.currentIndex() == 3:        # HTML
-            output = DataUriTemplates["HTML"].format(
-                output, os.path.basename(filepath))
-        elif self.embeddingComboBox.currentIndex() == 4:        # JS
+        elif self.embeddingComboBox.currentIndex() == 3:  # HTML
+            output = DataUriTemplates["HTML"].format(output, os.path.basename(filepath))
+        elif self.embeddingComboBox.currentIndex() == 4:  # JS
             output = DataUriTemplates["JavaScript"].format(output)
-        elif self.embeddingComboBox.currentIndex() == 5:        # QML
+        elif self.embeddingComboBox.currentIndex() == 5:  # QML
             output = DataUriTemplates["QML"].format(output)
-        
+
         if self.encryptCheckBox.isChecked():
-            output = codecs.encode(output, 'rot_13')
-        
+            output = codecs.encode(output, "rot_13")
+
         self.outputTextEdit.setPlainText(output)
-    
+
     @pyqtSlot()
     def on_copyButton_clicked(self):
         """
         Private slot to copy the output to the clipboard.
         """
         QApplication.clipboard().setText(self.outputTextEdit.toPlainText())
-    
+
     @pyqtSlot()
     def on_outputTextEdit_textChanged(self):
         """
@@ -188,29 +189,30 @@
         """
         enable = bool(self.outputTextEdit.toPlainText())
         self.copyButton.setEnabled(enable)
-        self.buttonBox.button(
-            QDialogButtonBox.StandardButton.Ok).setEnabled(enable)
-    
+        self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(enable)
+
     @pyqtSlot(str)
     def on_filePicker_textChanged(self, txt):
         """
         Private slot to handle the editing of the file name.
-        
+
         @param txt current file name
         @type str
         """
         self.encodeButton.setEnabled(bool(txt) and os.path.isfile(txt))
-    
+
     def __askMime(self):
         """
         Private method to get the mime type from the user.
-        
+
         @return entered mime type
         @rtype str
         """
         mimetypesList = [""] + sorted(
             set(mimetypes.types_map.values()).union(
-                set(mimetypes.common_types.values())))
+                set(mimetypes.common_types.values())
+            )
+        )
         try:
             index = mimetypesList.index("application/octet-stream")
         except ValueError:
@@ -220,16 +222,18 @@
             self.tr("Data URI Encoder"),
             self.tr("Enter a mime type:"),
             mimetypesList,
-            index, True)
+            index,
+            True,
+        )
         if ok:
             return mimetype.lower()
         else:
             return ""
-    
+
     def getCode(self):
         """
         Public method to get the code.
-        
+
         @return generated code
         @rtype str
         """

eric ide

mercurial