PluginMetricsRadon.py

branch
eric7
changeset 109
47df4b69f699
parent 107
0843dd7239f6
child 110
261babeb7cc6
equal deleted inserted replaced
108:19970127c936 109:47df4b69f699
11 import os 11 import os
12 12
13 from PyQt6.QtCore import QObject, QTranslator, pyqtSignal 13 from PyQt6.QtCore import QObject, QTranslator, pyqtSignal
14 from PyQt6.QtGui import QAction 14 from PyQt6.QtGui import QAction
15 15
16 from eric7 import Preferences 16 from eric7 import Globals, Preferences
17 from eric7.EricGui.EricAction import EricAction 17 from eric7.EricGui.EricAction import EricAction
18 from eric7.EricWidgets import EricMessageBox 18 from eric7.EricWidgets import EricMessageBox
19 from eric7.EricWidgets.EricApplication import ericApp 19 from eric7.EricWidgets.EricApplication import ericApp
20 from eric7.Project.ProjectBrowserModel import ProjectBrowserFileItem 20 from eric7.Project.ProjectBrowserModel import ProjectBrowserFileItem
21 21
629 "Warning: translation file '{0}' could not be" 629 "Warning: translation file '{0}' could not be"
630 " loaded.".format(translation) 630 " loaded.".format(translation)
631 ) 631 )
632 print("Using default.") 632 print("Using default.")
633 633
634 def __projectShowMenu(self, menuName, menu): # noqa: U100 634 def __projectShowMenu(
635 self,
636 menuName,
637 menu, # noqa: U100
638 ):
635 """ 639 """
636 Private slot called, when the the project menu or a submenu is 640 Private slot called, when the the project menu or a submenu is
637 about to be shown. 641 about to be shown.
638 642
639 @param menuName name of the menu to be shown 643 @param menuName name of the menu to be shown
779 if menu is not None: 783 if menu is not None:
780 menu.addAction(self.__editorSeparatorActs[0]) 784 menu.addAction(self.__editorSeparatorActs[0])
781 menu.addActions(self.__editorMetricsActs) 785 menu.addActions(self.__editorMetricsActs)
782 menu.addAction(self.__editorSeparatorActs[1]) 786 menu.addAction(self.__editorSeparatorActs[1])
783 787
784 def __editorShowMenu(self, menuName, menu, editor): # noqa: U100 788 def __editorShowMenu(
789 self,
790 menuName,
791 menu, # noqa: U100
792 editor,
793 ):
785 """ 794 """
786 Private slot called, when the the editor context menu or a submenu is 795 Private slot called, when the the editor context menu or a submenu is
787 about to be shown. 796 about to be shown.
788 797
789 @param menuName name of the menu to be shown 798 @param menuName name of the menu to be shown
814 for file in project.getSources() 823 for file in project.getSources()
815 if file.endswith(tuple(Preferences.getPython("Python3Extensions"))) 824 if file.endswith(tuple(Preferences.getPython("Python3Extensions")))
816 ] 825 ]
817 826
818 if self.__projectRawMetricsDialog is None: 827 if self.__projectRawMetricsDialog is None:
819 from RadonMetrics.RawMetricsDialog import RawMetricsDialog 828 from RadonMetrics.RawMetricsDialog import RawMetricsDialog # noqa: I101
820 829
821 self.__projectRawMetricsDialog = RawMetricsDialog(self) 830 self.__projectRawMetricsDialog = RawMetricsDialog(self)
822 self.__projectRawMetricsDialog.show() 831 self.__projectRawMetricsDialog.show()
823 self.__projectRawMetricsDialog.prepare(files, project) 832 self.__projectRawMetricsDialog.prepare(files, project)
824 833
838 fn = itm.fileName() 847 fn = itm.fileName()
839 except AttributeError: 848 except AttributeError:
840 fn = itm.dirName() 849 fn = itm.dirName()
841 850
842 if self.__projectBrowserRawMetricsDialog is None: 851 if self.__projectBrowserRawMetricsDialog is None:
843 from RadonMetrics.RawMetricsDialog import RawMetricsDialog 852 from RadonMetrics.RawMetricsDialog import RawMetricsDialog # noqa: I101
844 853
845 self.__projectBrowserRawMetricsDialog = RawMetricsDialog(self) 854 self.__projectBrowserRawMetricsDialog = RawMetricsDialog(self)
846 self.__projectBrowserRawMetricsDialog.show() 855 self.__projectBrowserRawMetricsDialog.show()
847 self.__projectBrowserRawMetricsDialog.start(fn) 856 self.__projectBrowserRawMetricsDialog.start(fn)
848 857
856 editor is not None 865 editor is not None
857 and editor.checkDirty() 866 and editor.checkDirty()
858 and editor.getFileName() is not None 867 and editor.getFileName() is not None
859 ): 868 ):
860 if self.__editorRawMetricsDialog is None: 869 if self.__editorRawMetricsDialog is None:
861 from RadonMetrics.RawMetricsDialog import RawMetricsDialog 870 from RadonMetrics.RawMetricsDialog import RawMetricsDialog # noqa: I101
862 871
863 self.__editorRawMetricsDialog = RawMetricsDialog(self) 872 self.__editorRawMetricsDialog = RawMetricsDialog(self)
864 self.__editorRawMetricsDialog.show() 873 self.__editorRawMetricsDialog.show()
865 self.__editorRawMetricsDialog.start(editor.getFileName()) 874 self.__editorRawMetricsDialog.start(editor.getFileName())
866 875
881 for file in project.getSources() 890 for file in project.getSources()
882 if file.endswith(tuple(Preferences.getPython("Python3Extensions"))) 891 if file.endswith(tuple(Preferences.getPython("Python3Extensions")))
883 ] 892 ]
884 893
885 if self.__projectMIDialog is None: 894 if self.__projectMIDialog is None:
886 from RadonMetrics.MaintainabilityIndexDialog import ( 895 from RadonMetrics.MaintainabilityIndexDialog import ( # noqa: I101
887 MaintainabilityIndexDialog, 896 MaintainabilityIndexDialog,
888 ) 897 )
889 898
890 self.__projectMIDialog = MaintainabilityIndexDialog(self) 899 self.__projectMIDialog = MaintainabilityIndexDialog(self)
891 self.__projectMIDialog.show() 900 self.__projectMIDialog.show()
907 fn = itm.fileName() 916 fn = itm.fileName()
908 except AttributeError: 917 except AttributeError:
909 fn = itm.dirName() 918 fn = itm.dirName()
910 919
911 if self.__projectBrowserMIDialog is None: 920 if self.__projectBrowserMIDialog is None:
912 from RadonMetrics.MaintainabilityIndexDialog import ( 921 from RadonMetrics.MaintainabilityIndexDialog import ( # noqa: I101
913 MaintainabilityIndexDialog, 922 MaintainabilityIndexDialog,
914 ) 923 )
915 924
916 self.__projectBrowserMIDialog = MaintainabilityIndexDialog(self) 925 self.__projectBrowserMIDialog = MaintainabilityIndexDialog(self)
917 self.__projectBrowserMIDialog.show() 926 self.__projectBrowserMIDialog.show()
927 editor is not None 936 editor is not None
928 and editor.checkDirty() 937 and editor.checkDirty()
929 and editor.getFileName() is not None 938 and editor.getFileName() is not None
930 ): 939 ):
931 if self.__editorMIDialog is None: 940 if self.__editorMIDialog is None:
932 from RadonMetrics.MaintainabilityIndexDialog import ( 941 from RadonMetrics.MaintainabilityIndexDialog import ( # noqa: I101
933 MaintainabilityIndexDialog, 942 MaintainabilityIndexDialog,
934 ) 943 )
935 944
936 self.__editorMIDialog = MaintainabilityIndexDialog(self) 945 self.__editorMIDialog = MaintainabilityIndexDialog(self)
937 self.__editorMIDialog.show() 946 self.__editorMIDialog.show()
954 for file in project.getSources() 963 for file in project.getSources()
955 if file.endswith(tuple(Preferences.getPython("Python3Extensions"))) 964 if file.endswith(tuple(Preferences.getPython("Python3Extensions")))
956 ] 965 ]
957 966
958 if self.__projectCCDialog is None: 967 if self.__projectCCDialog is None:
959 from RadonMetrics.CyclomaticComplexityDialog import ( 968 from RadonMetrics.CyclomaticComplexityDialog import ( # noqa: I101
960 CyclomaticComplexityDialog, 969 CyclomaticComplexityDialog,
961 ) 970 )
962 971
963 self.__projectCCDialog = CyclomaticComplexityDialog(self) 972 self.__projectCCDialog = CyclomaticComplexityDialog(self)
964 self.__projectCCDialog.show() 973 self.__projectCCDialog.show()
980 fn = itm.fileName() 989 fn = itm.fileName()
981 except AttributeError: 990 except AttributeError:
982 fn = itm.dirName() 991 fn = itm.dirName()
983 992
984 if self.__projectBrowserCCDialog is None: 993 if self.__projectBrowserCCDialog is None:
985 from RadonMetrics.CyclomaticComplexityDialog import ( 994 from RadonMetrics.CyclomaticComplexityDialog import ( # noqa: I101
986 CyclomaticComplexityDialog, 995 CyclomaticComplexityDialog,
987 ) 996 )
988 997
989 self.__projectBrowserCCDialog = CyclomaticComplexityDialog( 998 self.__projectBrowserCCDialog = CyclomaticComplexityDialog(
990 self, isSingle=True 999 self, isSingle=True
1002 editor is not None 1011 editor is not None
1003 and editor.checkDirty() 1012 and editor.checkDirty()
1004 and editor.getFileName() is not None 1013 and editor.getFileName() is not None
1005 ): 1014 ):
1006 if self.__editorCCDialog is None: 1015 if self.__editorCCDialog is None:
1007 from RadonMetrics.CyclomaticComplexityDialog import ( 1016 from RadonMetrics.CyclomaticComplexityDialog import ( # noqa: I101
1008 CyclomaticComplexityDialog, 1017 CyclomaticComplexityDialog,
1009 ) 1018 )
1010 1019
1011 self.__editorCCDialog = CyclomaticComplexityDialog(self, isSingle=True) 1020 self.__editorCCDialog = CyclomaticComplexityDialog(self, isSingle=True)
1012 self.__editorCCDialog.show() 1021 self.__editorCCDialog.show()
1018 1027
1019 def __showRadonVersion(self): 1028 def __showRadonVersion(self):
1020 """ 1029 """
1021 Private slot to show the version number of the used radon library. 1030 Private slot to show the version number of the used radon library.
1022 """ 1031 """
1023 from radon import __version__ 1032 from radon import __version__ # noqa: I102
1024 1033
1025 EricMessageBox.information( 1034 EricMessageBox.information(
1026 None, 1035 None,
1027 self.tr("Radon"), 1036 self.tr("Radon"),
1028 self.tr( 1037 self.tr(
1060 1069
1061 @param pipInstall function to be called with a list of package names. 1070 @param pipInstall function to be called with a list of package names.
1062 @type function 1071 @type function
1063 """ 1072 """
1064 try: 1073 try:
1065 from radon import __version__ as radon_version 1074 from radon import __version__ as radon_version # noqa: I101, I102
1066
1067 from eric7 import Globals
1068 1075
1069 if Globals.versionToTuple(radon_version) < (4, 5, 0): 1076 if Globals.versionToTuple(radon_version) < (4, 5, 0):
1070 # force an upgrade 1077 # force an upgrade
1071 pipInstall(["radon>=4.5.0"]) 1078 pipInstall(["radon>=4.5.0"])
1072 except ImportError: 1079 except ImportError:

eric ide

mercurial