--- a/AssistantEric/APIsManager.py Tue May 25 17:22:05 2021 +0200 +++ b/AssistantEric/APIsManager.py Tue May 25 17:48:25 2021 +0200 @@ -10,13 +10,13 @@ import contextlib import os -from PyQt5.QtCore import ( +from PyQt6.QtCore import ( QTimer, QThread, QFileInfo, pyqtSignal, QDateTime, QObject, Qt ) with contextlib.suppress(ImportError): - from PyQt5.QtSql import QSqlDatabase, QSqlQuery + from PyQt6.QtSql import QSqlDatabase, QSqlQuery -from E5Gui.E5Application import e5App +from EricWidgets.EricApplication import ericApp import QScintilla.Lexers @@ -134,8 +134,10 @@ """ Private method to get the word separator characters for a language. - @param language language of the APIs object (string) - @return word separator characters (list of strings) + @param language language of the APIs object + @type str + @return word separator characters + @rtype list of str """ if language: return self.__wseps.get(language, None) @@ -153,7 +155,8 @@ Private method to load an API file, if it is newer than the one read into the database. - @param apiFile filename of the raw API file (string) + @param apiFile filename of the raw API file + @type str """ db = QSqlDatabase.database(self.__connectionName) db.transaction() @@ -192,8 +195,10 @@ """ Private method to generate class api section for class attributes. - @param module module object to get the info from (Module) - @return API information (list of strings) + @param module module object to get the info from + @type Module + @return API information + @rtype list of str """ api = [] modulePath = module.name.split('.') @@ -219,7 +224,8 @@ """ Private method to read a raw API file into the database. - @param apiFile filename of the raw API file (string) + @param apiFile filename of the raw API file + @type str """ apis = [] bases = [] @@ -271,7 +277,8 @@ Doing this avoids rereading the file whenever the API is initialized in case the given file doesn't contain API data. - @param apiFile file name of the API file (string) + @param apiFile file name of the API file + @type str """ db = QSqlDatabase.database(self.__connectionName) db.transaction() @@ -299,10 +306,14 @@ """ Private method to put the API entries into the database. - @param apis list of api entries (list of strings) - @param bases list of base class entries (list of strings) - @param apiFile filename of the file read to get the APIs (string) - @param language programming language of the file of the APIs (string) + @param apis list of api entries + @type list of str + @param bases list of base class entries + @type list of str + @param apiFile filename of the file read to get the APIs + @type str + @param language programming language of the file of the APIs + @type str """ wseps = self.__autoCompletionWordSeparators(language) if wseps is None: @@ -429,7 +440,8 @@ """ Private method to delete all references to an api file. - @param apiFile filename of the raw API file (string) + @param apiFile filename of the raw API file + @type str """ db = QSqlDatabase.database(self.__connectionName) db.transaction() @@ -670,7 +682,7 @@ """ self.__lexer = None - self.__project = e5App().getObject("Project") + self.__project = ericApp().getObject("Project") self.__project.projectOpened.connect(self.__projectOpened) self.__project.newProject.connect(self.__projectOpened) self.__project.projectClosed.connect(self.__projectClosed) @@ -703,7 +715,8 @@ """ Protected method to determine the name of the database file. - @return name of the database file (string) + @return name of the database file + @rtype str """ if self.__language == ApisNameProject: return os.path.join(self.__project.getProjectManagementDir(), @@ -747,7 +760,8 @@ """ Private method to open the API database. - @return flag indicating the database status (boolean) + @return flag indicating the database status + @rtype bool """ db = QSqlDatabase.database(self.__connectionName, False) if not db.isValid(): @@ -808,7 +822,8 @@ """ Public method to get a list of API files loaded into the database. - @return list of API filenames (list of strings) + @return list of API filenames + @rtype list of str """ apiFiles = [] @@ -830,7 +845,8 @@ """ Private method to check, if the database has been prepared. - @return flag indicating the prepared status (boolean) + @return flag indicating the prepared status + @rtype bool """ db = QSqlDatabase.database(self.__connectionName) prepared = len(db.tables()) > 0 @@ -855,16 +871,20 @@ """ Public method to determine the possible completions. - @keyparam start string giving the start of the word to be - completed (string) - @keyparam context string giving the context (e.g. classname) - to be completed (string) - @keyparam followHierarchy flag indicating to follow the hierarchy of - base classes (boolean) + @param start string giving the start of the word to be + completed + @type str + @param context string giving the context (e.g. classname) + to be completed + @type str + @param followHierarchy flag indicating to follow the hierarchy of + base classes + @type bool @return list of dictionaries with possible completions - (key 'completion' contains the completion (string), - key 'context' contains the context (string) and - key 'pictureId' contains the ID of the icon to be shown (string)) + (key 'completion' contains the completion, + key 'context' contains the context and + key 'pictureId' contains the ID of the icon to be shown) + @rtype list of dict """ completions = [] @@ -921,16 +941,21 @@ """ Public method to determine the calltips. - @param acWord function to get calltips for (string) + @param acWord function to get calltips for + @type str @param commas minimum number of commas contained in the calltip - (integer) - @param context string giving the context (e.g. classname) (string) - @param fullContext string giving the full context (string) + @type int + @param context string giving the context (e.g. classname) + @type str + @param fullContext string giving the full context + @type str @param showContext flag indicating to show the calltip context - (boolean) - @keyparam followHierarchy flag indicating to follow the hierarchy of - base classes (boolean) - @return list of calltips (list of string) + @type bool + @param followHierarchy flag indicating to follow the hierarchy of + base classes + @type bool + @return list of calltips + @rtype list of str """ calltips = [] @@ -1004,9 +1029,12 @@ Private method to determine, if the given string contains enough commas. - @param s string to check (string) - @param commas number of commas to check for (integer) - @return flag indicating, that there are enough commas (boolean) + @param s string to check + @type str + @param commas number of commas to check for + @type int + @return flag indicating, that there are enough commas + @rtype bool """ end = s.find(')') @@ -1032,11 +1060,14 @@ """ Private method to get the source files for the project forms. - @keyparam normalized flag indicating a normalized filename is wanted - (boolean) - @return list of project form sources (list of strings) + @param normalized flag indicating a normalized filename is wanted + @type bool + @return list of project form sources + @rtype list of str """ - if self.__project.getProjectLanguage() == "Python3": + if self.__project.getProjectLanguage() in ( + "Python3", "MicroPython", "Cython" + ): sourceExt = ".py" elif self.__project.getProjectLanguage() == "Ruby": sourceExt = ".rb" @@ -1059,7 +1090,8 @@ """ Public method to prepare the APIs if neccessary. - @keyparam rawList list of raw API files (list of strings) + @param rawList list of raw API files + @type list of str """ if self.__inPreparation: return @@ -1075,12 +1107,8 @@ projectPath = self.__project.getProjectPath() projectType = "" else: - try: - apiFiles = Preferences.getEditorAPI( - self.__language, projectType=self.__projectType) - except TypeError: - # older interface - apiFiles = Preferences.getEditorAPI(self.__language) + apiFiles = Preferences.getEditorAPI( + self.__language, projectType=self.__projectType) projectType = self.__projectType self.__worker = DbAPIsWorker(self, self.__language, apiFiles, self._apiDbName(), projectPath, @@ -1117,7 +1145,8 @@ """ Public method to return a reference to our lexer object. - @return reference to the lexer object (QScintilla.Lexers.Lexer) + @return reference to the lexer object + @rtype Lexer """ return self.__lexer @@ -1125,7 +1154,8 @@ """ Public method to get the word separator characters. - @return word separator characters (list of strings) + @return word separator characters + @rtype list of str """ if self.__lexer: return self.__lexer.autoCompletionWordSeparators() @@ -1136,8 +1166,10 @@ Private slot handling the processing signal of the API preparation thread. - @param status preparation status (integer, one of WorkerStatus...) - @param filename name of the file being processed (string) + @param status preparation status (one of WorkerStatus...) + @type int + @param filename name of the file being processed + @type str """ if status == WorkerStatusStarted: self.__inPreparation = True @@ -1165,7 +1197,9 @@ """ Private slot to perform actions after a project has been opened. """ - if self.__project.getProjectLanguage() == "Python3": + if self.__project.getProjectLanguage() in ( + "Python3", "MicroPython", "Cython" + ): self.__discardFirst = ["self", "cls"] else: self.__discardFirst = [] @@ -1183,7 +1217,8 @@ """ Private slot to handle the projectFormCompiled signal. - @param filename name of the form file that was compiled (string) + @param filename name of the form file that was compiled + @type str """ self.__workerQueue.append(filename) self.__processQueue() @@ -1200,7 +1235,8 @@ """ Public slot to handle the editorSaved signal. - @param filename name of the file that was saved (string) + @param filename name of the file that was saved + @type str """ if self.__project.isProjectSource(filename): self.__workerQueue.append(filename) @@ -1216,8 +1252,10 @@ """ Constructor - @param mainWindow reference to the main eric6 window (QMainWindow) - @param parent reference to the parent object (QObject) + @param mainWindow reference to the main eric7 window + @type QMainWindow + @param parent reference to the parent object + @type QObject """ QObject.__init__(self, parent) self.setObjectName("Assistant_APIsManager") @@ -1277,7 +1315,8 @@ """ Private message to show a message in the main windows status bar. - @param msg message to be shown (string) + @param msg message to be shown + @type str """ if msg: self.__mw.statusBar().showMessage(msg, 2000) @@ -1286,9 +1325,12 @@ """ Private slot handling the preparation status signal of an API object. - @param language language of the API (string) - @param status preparation status (integer, one of WorkerStatus...) - @param filename name of the file being processed (string) + @param language language of the API + @type str + @param status preparation status (one of WorkerStatus...) + @type int + @param filename name of the file being processed + @type str """ if language == ApisNameProject: language = self.tr("Project")