Changed the isort formatting dialog to ensure the cached isort config data is cleared. eric7

Fri, 04 Nov 2022 11:55:21 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Fri, 04 Nov 2022 11:55:21 +0100
branch
eric7
changeset 9468
a4d8091cd8f7
parent 9467
1798115ba35c
child 9469
87567b249ed8

Changed the isort formatting dialog to ensure the cached isort config data is cleared.

pyproject.toml file | annotate | diff | comparison | revisions
src/eric7/CodeFormatting/IsortFormattingDialog.py file | annotate | diff | comparison | revisions
--- a/pyproject.toml	Fri Nov 04 11:18:07 2022 +0100
+++ b/pyproject.toml	Fri Nov 04 11:55:21 2022 +0100
@@ -180,3 +180,8 @@
     | pipdeptree\.py
 )
 '''
+
+#[tool.isort]
+#known_first_party = ["eric7"]
+#import_heading_stdlib = "Standard Library"
+#import_heading_firstparty = "eric7 Modules"
--- a/src/eric7/CodeFormatting/IsortFormattingDialog.py	Fri Nov 04 11:18:07 2022 +0100
+++ b/src/eric7/CodeFormatting/IsortFormattingDialog.py	Fri Nov 04 11:55:21 2022 +0100
@@ -14,7 +14,7 @@
 
 from dataclasses import dataclass
 
-from isort.settings import Config
+from isort import settings
 from isort.api import check_file, sort_file
 
 from PyQt6.QtCore import pyqtSlot, Qt, QCoreApplication
@@ -92,11 +92,20 @@
         # given as a dictionary (i.e. data entered in the configuration dialog)
         # overwrites these. If the project is not passed, the isort config is based on
         # the isort defaults.
-        self.__isortConfig = (
-            Config(settings_path=project.getProjectPath(), **self.__config)
-            if project
-            else Config(**self.__config)
-        )
+        if project:
+            # clear the caches in order to force a re-read of config files
+            settings._get_config_data.cache_clear()
+            settings._find_config.cache_clear()
+        try:
+            self.__isortConfig = (
+                settings.Config(settings_path=project.getProjectPath(), **self.__config)
+                if project
+                else settings.Config(**self.__config)
+            )
+        except KeyError:
+            # invalid configuration entry found in some config file; use just the dialog
+            # parameters
+            self.__isortConfig = settings.Config(**self.__config)
 
         self.__config["__action__"] = action  # needed by the workers
 

eric ide

mercurial