Utilities/__init__.py

changeset 3457
bfc38662e6fc
parent 3451
e9ee3ea73db4
child 3515
1b8381afe38f
--- a/Utilities/__init__.py	Sun Mar 30 17:30:45 2014 +0200
+++ b/Utilities/__init__.py	Mon Mar 31 19:13:22 2014 +0200
@@ -44,11 +44,13 @@
     qVersion, PYQT_VERSION_STR, QCoreApplication, QCryptographicHash
 from PyQt4.Qsci import QSCINTILLA_VERSION_STR, QsciScintilla
 
-from Globals import isWindowsPlatform, isLinuxPlatform, isMacPlatform  # __IGNORE_WARNING__
-from Globals import getConfigDir, setConfigDir  # __IGNORE_WARNING__
-from Globals import getPythonModulesDirectory, getPyQt4ModulesDirectory  # __IGNORE_WARNING__
-from Globals import getQtBinariesPath  # __IGNORE_WARNING__
 # import these methods into the Utilities namespace
+from Globals import isWindowsPlatform, isLinuxPlatform  # __IGNORE_WARNING__
+from Globals import isMacPlatform                       # __IGNORE_WARNING__
+from Globals import getConfigDir, setConfigDir          # __IGNORE_WARNING__
+from Globals import getPythonModulesDirectory           # __IGNORE_WARNING__
+from Globals import getPyQt4ModulesDirectory            # __IGNORE_WARNING__
+from Globals import getQtBinariesPath                   # __IGNORE_WARNING__
 
 from E5Gui.E5Application import e5App
 
@@ -1308,46 +1310,47 @@
         return pyAssignment[editor.getFileType()]
 
     pyVer = 0
-    flags = extractFlags(source)
-    ext = os.path.splitext(filename)[1]
-    py2Ext = Preferences.getPython("PythonExtensions")
-    py3Ext = Preferences.getPython("Python3Extensions")
-    project = e5App().getObject('Project')
-    basename = os.path.basename(filename)
-    
-    if "FileType" in flags:
-        pyVer = pyAssignment.get(flags["FileType"], 0)
-    elif project.isOpen() and project.isProjectFile(filename):
-        language = project.getEditorLexerAssoc(basename)
-        if not language:
-            language = Preferences.getEditorLexerAssoc(basename)
-        if language in ['Python2', 'Python3']:
-            pyVer = pyAssignment[language]
-    
-    if pyVer:
-        # Skip the next tests
-        pass
-    elif (Preferences.getProject("DeterminePyFromProject") and
-          project.isOpen() and
-          project.isProjectFile(filename) and
-          ext in py2Ext + py3Ext):
-                pyVer = pyAssignment.get(project.getProjectLanguage(), 0)
-    elif ext in py2Ext and ext not in py3Ext:
-        pyVer = 2
-    elif ext in py3Ext and ext not in py2Ext:
-        pyVer = 3
-    elif source.startswith("#!"):
-        line0 = source.splitlines()[0]
-        if "python3" in line0:
+    if filename:
+        flags = extractFlags(source)
+        ext = os.path.splitext(filename)[1]
+        py2Ext = Preferences.getPython("PythonExtensions")
+        py3Ext = Preferences.getPython("Python3Extensions")
+        project = e5App().getObject('Project')
+        basename = os.path.basename(filename)
+        
+        if "FileType" in flags:
+            pyVer = pyAssignment.get(flags["FileType"], 0)
+        elif project.isOpen() and project.isProjectFile(filename):
+            language = project.getEditorLexerAssoc(basename)
+            if not language:
+                language = Preferences.getEditorLexerAssoc(basename)
+            if language in ['Python2', 'Python3']:
+                pyVer = pyAssignment[language]
+        
+        if pyVer:
+            # Skip the next tests
+            pass
+        elif (Preferences.getProject("DeterminePyFromProject") and
+              project.isOpen() and
+              project.isProjectFile(filename) and
+              ext in py2Ext + py3Ext):
+                    pyVer = pyAssignment.get(project.getProjectLanguage(), 0)
+        elif ext in py2Ext and ext not in py3Ext:
+            pyVer = 2
+        elif ext in py3Ext and ext not in py2Ext:
             pyVer = 3
-        elif "python" in line0:
-            pyVer = 2
-    
-    if pyVer == 0 and ext in py2Ext + py3Ext:
-        pyVer = sys.version_info[0]
-    
-    if editor and pyVer:
-        editor.filetype = "Python{0}".format(pyVer)
+        elif source.startswith("#!"):
+            line0 = source.splitlines()[0]
+            if "python3" in line0:
+                pyVer = 3
+            elif "python" in line0:
+                pyVer = 2
+        
+        if pyVer == 0 and ext in py2Ext + py3Ext:
+            pyVer = sys.version_info[0]
+        
+        if editor and pyVer:
+            editor.filetype = "Python{0}".format(pyVer)
     
     return pyVer
 

eric ide

mercurial