diff -r bedbe458d792 -r 0665c4d509c9 eric6/Project/Project.py --- a/eric6/Project/Project.py Tue Sep 24 19:08:10 2019 +0200 +++ b/eric6/Project/Project.py Tue Sep 24 19:44:17 2019 +0200 @@ -16,11 +16,14 @@ import copy import zipfile -from PyQt5.QtCore import pyqtSlot, QFile, QFileInfo, pyqtSignal, \ - QCryptographicHash, QIODevice, QByteArray, QObject, Qt, QProcess +from PyQt5.QtCore import ( + pyqtSlot, QFile, QFileInfo, pyqtSignal, QCryptographicHash, QIODevice, + QByteArray, QObject, Qt, QProcess +) from PyQt5.QtGui import QCursor, QKeySequence -from PyQt5.QtWidgets import QLineEdit, QToolBar, QDialog, QInputDialog, \ - QApplication, QMenu, QAction +from PyQt5.QtWidgets import ( + QLineEdit, QToolBar, QDialog, QInputDialog, QApplication, QMenu, QAction +) from PyQt5.Qsci import QsciScintilla from E5Gui.E5Application import e5App @@ -338,8 +341,10 @@ @return flag indicating presence of the project type (boolean) """ if progLanguage: - return progLanguage in self.__projectProgLanguages and \ + return ( + progLanguage in self.__projectProgLanguages and type_ in self.__projectProgLanguages[progLanguage] + ) else: return type_ in self.__projectTypes @@ -398,8 +403,9 @@ self.__projectTypes[type_] = description self.__fileTypeCallbacks[type_] = fileTypeCallback self.__lexerAssociationCallbacks[type_] = lexerAssociationCallback - self.__binaryTranslationsCallbacks[type_] = \ + self.__binaryTranslationsCallbacks[type_] = ( binaryTranslationsCallback + ) if progLanguages: for progLanguage in progLanguages: self.__projectProgLanguages[progLanguage].append(type_) @@ -533,10 +539,12 @@ @param key key of the data entry to get (string). @return a copy of the requested data or None """ - if category in ["PROJECTTYPESPECIFICDATA", "CHECKERSPARMS", - "PACKAGERSPARMS", "DOCUMENTATIONPARMS", - "OTHERTOOLSPARMS"] and \ - key in self.pdata[category]: + if ( + category in ["PROJECTTYPESPECIFICDATA", "CHECKERSPARMS", + "PACKAGERSPARMS", "DOCUMENTATIONPARMS", + "OTHERTOOLSPARMS"] and + key in self.pdata[category] + ): return copy.deepcopy(self.pdata[category][key]) else: return None @@ -634,8 +642,7 @@ try: if self.__fileTypeCallbacks[ self.pdata["PROJECTTYPE"]] is not None: - ftypes = \ - self.__fileTypeCallbacks[self.pdata["PROJECTTYPE"]]() + ftypes = self.__fileTypeCallbacks[self.pdata["PROJECTTYPE"]]() self.pdata["FILETYPES"].update(ftypes) except KeyError: pass @@ -659,8 +666,7 @@ try: if self.__fileTypeCallbacks[ self.pdata["PROJECTTYPE"]] is not None: - ftypes = \ - self.__fileTypeCallbacks[self.pdata["PROJECTTYPE"]]() + ftypes = self.__fileTypeCallbacks[self.pdata["PROJECTTYPE"]]() for pattern, ftype in list(ftypes.items()): if pattern not in self.pdata["FILETYPES"]: self.pdata["FILETYPES"][pattern] = ftype @@ -812,8 +818,8 @@ if res: if self.pdata["TRANSLATIONPATTERN"]: - self.translationsRoot = \ - self.pdata["TRANSLATIONPATTERN"].split("%language%")[0] + self.translationsRoot = self.pdata["TRANSLATIONPATTERN"].split( + "%language%")[0] elif self.pdata["MAINSCRIPT"]: self.translationsRoot = os.path.splitext( self.pdata["MAINSCRIPT"])[0] @@ -837,12 +843,14 @@ self.__checkFilesExist("OTHERS") # get the names of subdirectories the files are stored in - for fn in self.pdata["SOURCES"] + \ - self.pdata["FORMS"] + \ - self.pdata["INTERFACES"] + \ - self.pdata["PROTOCOLS"] + \ - self.pdata["RESOURCES"] + \ - self.pdata["TRANSLATIONS"]: + for fn in ( + self.pdata["SOURCES"] + + self.pdata["FORMS"] + + self.pdata["INTERFACES"] + + self.pdata["PROTOCOLS"] + + self.pdata["RESOURCES"] + + self.pdata["TRANSLATIONS"] + ): dn = os.path.dirname(fn) if dn not in self.subdirs: self.subdirs.append(dn) @@ -876,10 +884,9 @@ @return flag indicating success """ if self.vcs is not None: - self.pdata["VCSOPTIONS"] = \ - copy.deepcopy(self.vcs.vcsGetOptions()) - self.pdata["VCSOTHERDATA"] = \ - copy.deepcopy(self.vcs.vcsGetOtherData()) + self.pdata["VCSOPTIONS"] = copy.deepcopy(self.vcs.vcsGetOptions()) + self.pdata["VCSOTHERDATA"] = copy.deepcopy( + self.vcs.vcsGetOtherData()) if not self.pdata["HASH"]: hashStr = str(QCryptographicHash.hash( @@ -1311,8 +1318,10 @@ @return value of the property """ if key == "INTERPRETER": - return e5App().getObject("VirtualEnvManager")\ + return ( + e5App().getObject("VirtualEnvManager") .getVirtualenvInterpreter(self.debugProperties["VIRTUALENV"]) + ) else: return self.debugProperties[key] @@ -1392,11 +1401,12 @@ dlg = AddLanguageDialog(self.parent()) if dlg.exec_() == QDialog.Accepted: lang = dlg.getSelectedLanguage() - if self.pdata["PROJECTTYPE"] in \ - ["Qt4", "Qt4C", "PyQt5", "PyQt5C", "E6Plugin", - "PySide", "PySideC", "PySide2", "PySide2C"]: - langFile = self.pdata["TRANSLATIONPATTERN"]\ - .replace("%language%", lang) + if self.pdata["PROJECTTYPE"] in [ + "Qt4", "Qt4C", "PyQt5", "PyQt5C", "E6Plugin", + "PySide", "PySideC", "PySide2", "PySide2C" + ]: + langFile = self.pdata["TRANSLATIONPATTERN"].replace( + "%language%", lang) self.appendFile(langFile) self.projectLanguageAddedByCode.emit(lang) @@ -1428,13 +1438,17 @@ for langFile in self.pdata["TRANSLATIONS"][:]: qmFile = self.__binaryTranslationFile(langFile) if qmFile: - if qmFile not in self.pdata["TRANSLATIONS"] and \ - os.path.exists(os.path.join(self.ppath, qmFile)): + if ( + qmFile not in self.pdata["TRANSLATIONS"] and + os.path.exists(os.path.join(self.ppath, qmFile)) + ): self.appendFile(qmFile) if tbPath: qmFile = os.path.join(tbPath, os.path.basename(qmFile)) - if qmFile not in self.pdata["TRANSLATIONS"] and \ - os.path.exists(os.path.join(self.ppath, qmFile)): + if ( + qmFile not in self.pdata["TRANSLATIONS"] and + os.path.exists(os.path.join(self.ppath, qmFile)) + ): self.appendFile(qmFile) def removeLanguageFile(self, langFile): @@ -1570,8 +1584,8 @@ if newfn not in self.pdata["INTERFACES"]: self.pdata["INTERFACES"].append(newfn) self.projectInterfaceAdded.emit(newfn) - updateModel and \ - self.__model.addNewItem("INTERFACES", newfn) + (updateModel and + self.__model.addNewItem("INTERFACES", newfn)) dirty = True else: updateModel and self.repopulateItem(newfn) @@ -1579,8 +1593,8 @@ if newfn not in self.pdata["PROTOCOLS"]: self.pdata["PROTOCOLS"].append(newfn) self.projectProtocolAdded.emit(newfn) - updateModel and \ - self.__model.addNewItem("PROTOCOLS", newfn) + (updateModel and + self.__model.addNewItem("PROTOCOLS", newfn)) dirty = True else: updateModel and self.repopulateItem(newfn) @@ -1706,8 +1720,10 @@ " any files belonging to the selected category.</p>")) return - if not Utilities.samepath(target, source) and \ - not os.path.isdir(target): + if ( + not Utilities.samepath(target, source) and + not os.path.isdir(target) + ): try: os.makedirs(target) except IOError as why: @@ -1977,13 +1993,15 @@ """Reason: {1}</p>""").format(oldfn, str(msg))) return False - if fn in self.pdata["SOURCES"] or \ - fn in self.pdata["FORMS"] or \ - fn in self.pdata["TRANSLATIONS"] or \ - fn in self.pdata["INTERFACES"] or \ - fn in self.pdata["PROTOCOLS"] or \ - fn in self.pdata["RESOURCES"] or \ - fn in self.pdata["OTHERS"]: + if ( + fn in self.pdata["SOURCES"] or + fn in self.pdata["FORMS"] or + fn in self.pdata["TRANSLATIONS"] or + fn in self.pdata["INTERFACES"] or + fn in self.pdata["PROTOCOLS"] or + fn in self.pdata["RESOURCES"] or + fn in self.pdata["OTHERS"] + ): self.renameFileInPdata(oldfn, newfn, isSourceFile) return True @@ -2261,12 +2279,14 @@ @return flag indicating, if the project contains the file (boolean) """ fn = self.getRelativePath(fn) - if fn in self.pdata["SOURCES"] or \ - fn in self.pdata["FORMS"] or \ - fn in self.pdata["INTERFACES"] or \ - fn in self.pdata["PROTOCOLS"] or \ - fn in self.pdata["RESOURCES"] or \ - fn in self.pdata["OTHERS"]: + if ( + fn in self.pdata["SOURCES"] or + fn in self.pdata["FORMS"] or + fn in self.pdata["INTERFACES"] or + fn in self.pdata["PROTOCOLS"] or + fn in self.pdata["RESOURCES"] or + fn in self.pdata["OTHERS"] + ): return True else: return False @@ -2347,8 +2367,9 @@ # create an empty __init__.py file to make it a Python package # (only for Python and Python3) - if self.pdata["PROGLANGUAGE"] in \ - ["Python", "Python2", "Python3", "MicroPython"]: + if self.pdata["PROGLANGUAGE"] in [ + "Python", "Python2", "Python3", "MicroPython" + ]: fn = os.path.join(self.ppath, "__init__.py") f = open(fn, "w", encoding="utf-8") f.close() @@ -2460,8 +2481,9 @@ addAllToVcs = res # create an empty __init__.py file to make it a Python package # if none exists (only for Python and Python3) - if self.pdata["PROGLANGUAGE"] in \ - ["Python", "Python2", "Python3", "MicroPython"]: + if self.pdata["PROGLANGUAGE"] in [ + "Python", "Python2", "Python3", "MicroPython" + ]: fn = os.path.join(self.ppath, "__init__.py") if not os.path.exists(fn): f = open(fn, "w", encoding="utf-8") @@ -2511,8 +2533,9 @@ else: vcores = False if vcores: - from VCS.CommandOptionsDialog import \ + from VCS.CommandOptionsDialog import ( VcsCommandOptionsDialog + ) codlg = VcsCommandOptionsDialog(self.vcs) if codlg.exec_() == QDialog.Accepted: self.vcs.vcsSetOptions(codlg.getOptions()) @@ -2534,10 +2557,15 @@ break # put the project under VCS control - if self.vcs is None and self.vcsSoftwareAvailable() and \ - self.vcsRequested: - vcsSystemsDict = e5App().getObject("PluginManager")\ + if ( + self.vcs is None and + self.vcsSoftwareAvailable() and + self.vcsRequested + ): + vcsSystemsDict = ( + e5App().getObject("PluginManager") .getPluginDisplayStrings("version_control") + ) vcsSystemsDisplay = [self.tr("None")] keys = sorted(vcsSystemsDict.keys()) for key in keys: @@ -2579,8 +2607,9 @@ else: vcores = False if vcores: - from VCS.CommandOptionsDialog import \ + from VCS.CommandOptionsDialog import ( VcsCommandOptionsDialog + ) codlg = VcsCommandOptionsDialog(self.vcs) if codlg.exec_() == QDialog.Accepted: self.vcs.vcsSetOptions(codlg.getOptions()) @@ -2641,8 +2670,10 @@ if tslist: if '_' in os.path.basename(tslist[0]): # the first entry determines the mainscript name - mainscriptname = os.path.splitext(mainscript)[0] or \ + mainscriptname = ( + os.path.splitext(mainscript)[0] or os.path.basename(tslist[0]).split('_')[0] + ) self.pdata["TRANSLATIONPATTERN"] = os.path.join( os.path.dirname(tslist[0]), "{0}_%language%{1}".format( @@ -2662,10 +2693,10 @@ if pattern: self.pdata["TRANSLATIONPATTERN"] = pattern if self.pdata["TRANSLATIONPATTERN"]: - self.pdata["TRANSLATIONPATTERN"] = \ - self.getRelativePath(self.pdata["TRANSLATIONPATTERN"]) - pattern = self.pdata["TRANSLATIONPATTERN"]\ - .replace("%language%", "*") + self.pdata["TRANSLATIONPATTERN"] = self.getRelativePath( + self.pdata["TRANSLATIONPATTERN"]) + pattern = self.pdata["TRANSLATIONPATTERN"].replace( + "%language%", "*") for ts in tslist: if fnmatch.fnmatch(ts, pattern): self.pdata["TRANSLATIONS"].append(ts) @@ -2674,16 +2705,17 @@ tpd = os.path.join(self.ppath, self.pdata["TRANSLATIONSBINPATH"]) pattern = os.path.basename( - self.pdata["TRANSLATIONPATTERN"])\ - .replace("%language%", "*") + self.pdata["TRANSLATIONPATTERN"]).replace( + "%language%", "*") pattern = self.__binaryTranslationFile(pattern) qmlist = Utilities.direntries(tpd, True, pattern) for qm in qmlist: self.pdata["TRANSLATIONS"].append(qm) self.projectLanguageAdded.emit(qm) if not self.pdata["MAINSCRIPT"] and bool(mainscriptname): - if self.pdata["PROGLANGUAGE"] in \ - ["Python", "Python2", "Python3", "MicroPython"]: + if self.pdata["PROGLANGUAGE"] in [ + "Python", "Python2", "Python3", "MicroPython" + ]: self.pdata["MAINSCRIPT"] = '{0}.py'.format(mainscriptname) elif self.pdata["PROGLANGUAGE"] == "Ruby": self.pdata["MAINSCRIPT"] = '{0}.rb'.format(mainscriptname) @@ -2774,12 +2806,14 @@ if dlg.exec_() == QDialog.Accepted: dlg.storeData() - if (self.pdata["VCS"] and - self.pdata["VCS"] != vcsSystem) or \ - (self.pudata["VCSOVERRIDE"] and - self.pudata["VCSOVERRIDE"] != vcsSystemOverride) or \ - (vcsSystemOverride is not None and - not self.pudata["VCSOVERRIDE"]): + if ( + (self.pdata["VCS"] and + self.pdata["VCS"] != vcsSystem) or + (self.pudata["VCSOVERRIDE"] and + self.pudata["VCSOVERRIDE"] != vcsSystemOverride) or + (vcsSystemOverride is not None and + not self.pudata["VCSOVERRIDE"]) + ): # stop the VCS monitor thread and shutdown VCS if self.vcs is not None: self.vcs.stopStatusMonitor() @@ -2916,14 +2950,16 @@ if self.vcs is None and self.isDirty() == oldState: # check, if project is version controlled pluginManager = e5App().getObject("PluginManager") - for indicator, vcsData in \ - pluginManager.getVcsSystemIndicators().items(): + for indicator, vcsData in ( + pluginManager.getVcsSystemIndicators().items() + ): if os.path.exists( os.path.join(self.ppath, indicator)): if len(vcsData) > 1: vcsList = [] - for _vcsSystemStr, vcsSystemDisplay in \ - vcsData: + for _vcsSystemStr, vcsSystemDisplay in ( + vcsData + ): vcsList.append(vcsSystemDisplay) QApplication.restoreOverrideCursor() res, vcs_ok = QInputDialog.getItem( @@ -2937,8 +2973,9 @@ QCursor(Qt.WaitCursor)) QApplication.processEvents() if vcs_ok: - for vcsSystemStr, vcsSystemDisplay in \ - vcsData: + for vcsSystemStr, vcsSystemDisplay in ( + vcsData + ): if res == vcsSystemDisplay: vcsSystem = vcsSystemStr break @@ -2951,9 +2988,11 @@ self.pdata["VCS"] = vcsSystem self.vcs = self.initVCS() self.setDirty(True) - if self.vcs is not None and \ + if ( + self.vcs is not None and (self.vcs.vcsRegisteredState(self.ppath) != - self.vcs.canBeCommitted): + self.vcs.canBeCommitted) + ): self.pdata["VCS"] = 'None' self.vcs = self.initVCS() self.closeAct.setEnabled(True) @@ -3000,8 +3039,8 @@ self.ui.taskViewer.setProjectOpen(True) # rescan project tasks if Preferences.getProject("TasksProjectRescanOnOpen"): - e5App().getObject("TaskViewer")\ - .regenerateProjectTasks(quiet=True) + e5App().getObject("TaskViewer" + ).regenerateProjectTasks(quiet=True) if restoreSession: # open the main script @@ -3069,8 +3108,10 @@ if self.ppath: defaultPath = self.ppath else: - defaultPath = Preferences.getMultiProject("Workspace") or \ + defaultPath = ( + Preferences.getMultiProject("Workspace") or Utilities.getHomeDir() + ) fn, selectedFilter = E5FileDialog.getSaveFileNameAndFilter( self.parent(), self.tr("Save project as"), @@ -3174,9 +3215,11 @@ self.__writeSession(quiet=True) # save the project debugger properties file being quiet about error - if Preferences.getProject("AutoSaveDbgProperties") and \ - self.isDebugPropertiesLoaded() and \ - not noSave and self.debugPropertiesChanged: + if ( + Preferences.getProject("AutoSaveDbgProperties") and + self.isDebugPropertiesLoaded() and + not noSave and self.debugPropertiesChanged + ): self.__writeDebugProperties(True) vm = e5App().getObject("ViewManager") @@ -3491,9 +3534,11 @@ if self.ppath: if path == self.ppath: return True - elif Utilities.normcasepath(Utilities.toNativeSeparators(path))\ - .startswith(Utilities.normcasepath( - Utilities.toNativeSeparators(self.ppath + "/"))): + elif ( + Utilities.normcasepath(Utilities.toNativeSeparators(path)) + .startswith(Utilities.normcasepath( + Utilities.toNativeSeparators(self.ppath + "/"))) + ): return True else: return False @@ -4574,8 +4619,10 @@ except OSError: newSources = [] if self.pdata["TRANSLATIONPATTERN"]: - pattern = self.pdata["TRANSLATIONPATTERN"]\ + pattern = ( + self.pdata["TRANSLATIONPATTERN"] .replace("%language%", "*") + ) else: pattern = "*.ts" binpattern = self.__binaryTranslationFile(pattern) @@ -4583,9 +4630,11 @@ # ignore hidden files and directories if ns.startswith('.'): continue - if Utilities.isWindowsPlatform() and \ - os.path.isdir(os.path.join(curpath, ns)) and \ - ns.startswith('_'): + if ( + Utilities.isWindowsPlatform() and + os.path.isdir(os.path.join(curpath, ns)) and + ns.startswith('_') + ): # dot net hack continue @@ -4614,25 +4663,32 @@ filetype = self.pdata["FILETYPES"][pattern] break - if (filetype == "SOURCES" and - fn not in self.pdata["SOURCES"]) or \ - (filetype == "FORMS" and - fn not in self.pdata["FORMS"]) or \ - (filetype == "INTERFACES" and - fn not in self.pdata["INTERFACES"]) or \ - (filetype == "PROTOCOLS" and - fn not in self.pdata["PROTOCOLS"]) or \ - (filetype == "RESOURCES" and - fn not in self.pdata["RESOURCES"]) or \ - (filetype == "OTHERS" and fn not in self.pdata["OTHERS"]): + if ( + (filetype == "SOURCES" and + fn not in self.pdata["SOURCES"]) or + (filetype == "FORMS" and + fn not in self.pdata["FORMS"]) or + (filetype == "INTERFACES" and + fn not in self.pdata["INTERFACES"]) or + (filetype == "PROTOCOLS" and + fn not in self.pdata["PROTOCOLS"]) or + (filetype == "RESOURCES" and + fn not in self.pdata["RESOURCES"]) or + (filetype == "OTHERS" and + fn not in self.pdata["OTHERS"]) + ): if autoInclude and AI: self.appendFile(ns) else: newFiles.append(ns) - elif filetype == "TRANSLATIONS" and \ - fn not in self.pdata["TRANSLATIONS"]: - if fnmatch.fnmatch(ns, pattern) or \ - fnmatch.fnmatch(ns, binpattern): + elif ( + filetype == "TRANSLATIONS" and + fn not in self.pdata["TRANSLATIONS"] + ): + if ( + fnmatch.fnmatch(ns, pattern) or + fnmatch.fnmatch(ns, binpattern) + ): if autoInclude and AI: self.appendFile(ns) else: @@ -4757,8 +4813,10 @@ forProject = False if forProject and self.pdata["VCS"] and self.pdata["VCS"] != 'None': - if self.pudata["VCSOVERRIDE"] and \ - not nooverride: + if ( + self.pudata["VCSOVERRIDE"] and + not nooverride + ): vcsSystem = self.pudata["VCSOVERRIDE"] override = True @@ -4855,8 +4913,10 @@ @return flag indicating availability of VCS software (boolean) """ - vcsSystemsDict = e5App().getObject("PluginManager")\ + vcsSystemsDict = ( + e5App().getObject("PluginManager") .getPluginDisplayStrings("version_control") + ) return len(vcsSystemsDict) != 0 def __vcsStatusChanged(self): @@ -5378,10 +5438,11 @@ self.__createZipDirEntries( os.path.split(name)[0], archiveFile) if snapshot and name == self.pdata["MAINSCRIPT"]: - snapshotSource, version = \ + snapshotSource, version = ( self.__createSnapshotSource( os.path.join(self.ppath, self.pdata["MAINSCRIPT"])) + ) archiveFile.writestr(name, snapshotSource) else: archiveFile.write(os.path.join(self.ppath, name), @@ -5483,8 +5544,8 @@ if sourcelines[lineno].startswith("version = "): # found the line to modify datestr = time.strftime("%Y%m%d") - lineend = sourcelines[lineno]\ - .replace(sourcelines[lineno].rstrip(), "") + lineend = sourcelines[lineno].replace( + sourcelines[lineno].rstrip(), "") sversion = "{0}-snapshot-{1}".format( sourcelines[lineno].replace("version = ", "") .strip()[1:-1], @@ -5521,8 +5582,10 @@ for sourceline in sourcelines: if sourceline.startswith("version = "): - version = sourceline.replace("version = ", "").strip()\ + version = ( + sourceline.replace("version = ", "").strip() .replace('"', "").replace("'", "") + ) break return version @@ -5584,8 +5647,10 @@ through a menu action) @type bool """ - if not self.pdata["MAKEPARAMS"]["MakeEnabled"] or \ - self.__makeProcess is not None: + if ( + not self.pdata["MAKEPARAMS"]["MakeEnabled"] or + self.__makeProcess is not None + ): return if self.pdata["MAKEPARAMS"]["MakeExecutable"]: @@ -5677,8 +5742,8 @@ if self.pdata["MAKEPARAMS"]["MakeTarget"]: message = self.tr( """<p>There are changes that require the configured""" - """ make target <b>{0}</b> to be rebuilt.</p>""")\ - .format(self.pdata["MAKEPARAMS"]["MakeTarget"]) + """ make target <b>{0}</b> to be rebuilt.</p>""" + ).format(self.pdata["MAKEPARAMS"]["MakeTarget"]) else: message = self.tr( """<p>There are changes that require the default""" @@ -5771,8 +5836,9 @@ @return flag indicating default parameter set @rtype bool """ - return self.pdata["RCCPARAMS"] == \ - self.getDefaultRccCompilerParameters() + return ( + self.pdata["RCCPARAMS"] == self.getDefaultRccCompilerParameters() + ) def getDefaultRccCompilerParameters(self): """