Permalink
Browse files

Making ninja python3 compatible.

Adding docstring to highlighter
  • Loading branch information...
1 parent 5d40e09 commit cc69778fbc5e15f45efd36c7b15c8c3d867f4a0e @diegosarmentero diegosarmentero committed Oct 6, 2012
Showing with 478 additions and 375 deletions.
  1. +0 −10 ninja-ide.py
  2. +13 −0 ninja_ide/__init__.py
  3. +5 −5 ninja_ide/core/cliparser.py
  4. +4 −4 ninja_ide/core/file_manager.py
  5. +15 −12 ninja_ide/core/filesystem_notifications/__init__.py
  6. +1 −1 ninja_ide/core/filesystem_notifications/darwin.py
  7. +25 −17 ninja_ide/core/plugin_manager.py
  8. +1 −1 ninja_ide/core/plugin_services.py
  9. +59 −71 ninja_ide/core/settings.py
  10. +2 −2 ninja_ide/dependencies/pep8mod.py
  11. +23 −18 ninja_ide/dependencies/pyflakes_mod/checker.py
  12. +2 −2 ninja_ide/dependencies/pyflakes_mod/scripts/pyflakes.py
  13. +8 −9 ninja_ide/gui/actions.py
  14. +6 −8 ninja_ide/gui/central_widget.py
  15. +2 −2 ninja_ide/gui/dialogs/about_ninja.py
  16. +12 −7 ninja_ide/gui/dialogs/language_manager.py
  17. +12 −11 ninja_ide/gui/dialogs/plugins_manager.py
  18. +7 −7 ninja_ide/gui/dialogs/preferences.py
  19. +12 −7 ninja_ide/gui/dialogs/themes_manager.py
  20. +10 −5 ninja_ide/gui/editor/editor.py
  21. +11 −3 ninja_ide/gui/editor/errors_checker.py
  22. +42 −2 ninja_ide/gui/editor/highlighter.py
  23. +4 −2 ninja_ide/gui/editor/pep8_checker.py
  24. +2 −2 ninja_ide/gui/explorer/errors_lists.py
  25. +7 −7 ninja_ide/gui/explorer/explorer_container.py
  26. +12 −12 ninja_ide/gui/explorer/tree_projects_widget.py
  27. +37 −22 ninja_ide/gui/ide.py
  28. +7 −6 ninja_ide/gui/main_panel/browser_widget.py
  29. +17 −18 ninja_ide/gui/main_panel/main_container.py
  30. +12 −11 ninja_ide/gui/main_panel/recent_project_item.py
  31. +6 −6 ninja_ide/gui/main_panel/tab_widget.py
  32. +1 −1 ninja_ide/gui/menus/lib/tetrismodel.py
  33. +6 −5 ninja_ide/gui/misc/console_widget.py
  34. +10 −6 ninja_ide/gui/misc/find_in_files.py
  35. +3 −3 ninja_ide/gui/misc/plugin_preferences.py
  36. +3 −2 ninja_ide/gui/misc/run_widget.py
  37. +2 −2 ninja_ide/gui/misc/shortcut_manager.py
  38. +2 −2 ninja_ide/gui/status_bar.py
  39. +1 −2 ninja_ide/gui/updates.py
  40. +1 −1 ninja_ide/resources.py
  41. +2 −2 ninja_ide/tools/completion/analyzer.py
  42. +8 −3 ninja_ide/tools/completion/code_completion.py
  43. +7 −4 ninja_ide/tools/completion/completer.py
  44. +2 −1 ninja_ide/tools/completion/completer_widget.py
  45. +4 −3 ninja_ide/tools/completion/completion_daemon.py
  46. +5 −5 ninja_ide/tools/completion/model.py
  47. +5 −5 ninja_ide/tools/json_manager.py
  48. +36 −34 ninja_ide/tools/locator.py
  49. +3 −3 ninja_ide/tools/ui_tools.py
  50. +1 −1 setup.py
View
@@ -23,16 +23,6 @@
from __future__ import absolute_import
-###############################################################################
-# SET PYQT API 2
-###############################################################################
-
-import sip
-API_NAMES = ["QDate", "QDateTime", "QString", "QTime", "QUrl", "QTextStream"]
-API_VERSION = 2
-for name in API_NAMES:
- sip.setapi(name, API_VERSION)
-
import ninja_ide
View
@@ -40,6 +40,19 @@
and more enjoyable.
"""
+
+###############################################################################
+# SET PYQT API 2
+###############################################################################
+
+import sip
+API_NAMES = ["QDate", "QDateTime", "QString", "QTime", "QUrl", "QTextStream",
+ "QVariant"]
+API_VERSION = 2
+for name in API_NAMES:
+ sip.setapi(name, API_VERSION)
+
+
###############################################################################
# START
###############################################################################
@@ -39,16 +39,16 @@ def _get_parser():
parser = argparse.ArgumentParser(description=usage, epilog=epilog)
- parser.add_argument('file', metavar='file', type=unicode,
+ parser.add_argument('file', metavar='file', type=str,
nargs='*', help='A file/s to edit', default=[])
- parser.add_argument('-f', '--files', metavar='file', type=unicode,
+ parser.add_argument('-f', '--files', metavar='file', type=str,
nargs='+', help='A file/s to edit', default=[])
parser.add_argument('-l', '--lineno', metavar='lineno', type=int,
nargs='+', help='Line number for the files to open', default=[])
- parser.add_argument('-p', '--project', metavar='project', type=unicode,
+ parser.add_argument('-p', '--project', metavar='project', type=str,
nargs='+', help='A project/s to edit', default=[])
parser.add_argument('--plugin',
- metavar='plugin', type=unicode,
+ metavar='plugin', type=str,
nargs='+', help='A plugin to load', default=[])
parser.add_argument('--loglevel', help="Level to use for logging, "
"one of 'DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'",
@@ -154,7 +154,7 @@ def parse():
log_level = opts.loglevel
log_file = opts.logfile
- except Exception, reason:
+ except Exception as reason:
print("Args couldn't be parsed.")
print(reason)
return (filenames, projects_path, extra_plugins, linenos, log_level,
@@ -116,8 +116,8 @@ def _search_coding_line(txt):
"""Search a pattern like this: # -*- coding: utf-8 -*-."""
coding_pattern = "coding[:=]\s*([-\w.]+)"
pat_coding = re.search(coding_pattern, txt)
- if pat_coding and unicode(pat_coding.groups()[0]) != 'None':
- return unicode(pat_coding.groups()[0])
+ if pat_coding and pat_coding.groups()[0] != 'None':
+ return pat_coding.groups()[0]
return None
@@ -147,8 +147,8 @@ def read_file_content(fileName):
content = f.read()
encoding = get_file_encoding(content)
content.decode(encoding)
- except IOError, reason:
- raise NinjaIOException(unicode(reason))
+ except IOError as reason:
+ raise NinjaIOException(reason)
return content
@@ -19,18 +19,21 @@
import sys
-
-if sys.platform == 'win32':
- from ninja_ide.core.filesystem_notifications import windows
- source = windows
-elif sys.platform == 'darwin':
- from ninja_ide.core.filesystem_notifications import darwin
- source = darwin
-elif sys.platform.startswith("linux"):
- from ninja_ide.core.filesystem_notifications import linux
- source = linux
-else:
- #Aything we do not have a clue how to handle
+try:
+ if sys.platform == 'win32':
+ from ninja_ide.core.filesystem_notifications import windows
+ source = windows
+ elif sys.platform == 'darwin':
+ from ninja_ide.core.filesystem_notifications import darwin
+ source = darwin
+ elif sys.platform.startswith("linux"):
+ from ninja_ide.core.filesystem_notifications import linux
+ source = linux
+ else:
+ #Aything we do not have a clue how to handle
+ from ninja_ide.core.filesystem_notifications import openbsd
+ source = openbsd
+except:
from ninja_ide.core.filesystem_notifications import openbsd
source = openbsd
@@ -69,7 +69,7 @@ def add_watch(self, path):
#self.watching_paths[path] = stream
#if not self.observer.is_alive():
#self.observer.start()
- #except Exception, reason:
+ #except Exception as reason:
#print reason
#logger.debug("Path could not be added: %r" % path)
@@ -15,19 +15,21 @@
# You should have received a copy of the GNU General Public License
# along with NINJA-IDE; If not, see <http://www.gnu.org/licenses/>.
-from __future__ import absolute_import
+from __future__ import unicode_literals
import os
import sys
import copy
-import urllib2
+import json
import zipfile
import traceback
#lint:disable
try:
- import json
+ from urllib.request import urlopen
+ from urllib.error import URLError
except ImportError:
- import simplejson as json
+ from urllib2 import urlopen
+ from urllib2 import URLError
#lint:enable
from ninja_ide import resources
@@ -36,6 +38,12 @@
logger = NinjaLogger('ninja_ide.core.plugin_manager')
REQUIREMENTS = 'requirements.txt'
COMMAND_FOR_PIP_INSTALL = 'pip install -r %s'
+try:
+ # For Python2
+ str = unicode # lint:ok
+except NameError:
+ # We are in Python3
+ pass
class ServiceLocator(object):
@@ -51,7 +59,7 @@ def get_service(self, name):
return self.__services.get(name)
def get_availables_services(self):
- return self.__services.keys()
+ return list(self.__services.keys())
'''
@@ -135,7 +143,7 @@ def __init__(self, plugins_dir, service_locator):
def __create_list(self, obj):
if isinstance(obj, (list, tuple)):
return obj
- elif isinstance(obj, basestring):
+ elif isinstance(obj, str):
return [obj]
def add_plugin_dir(self, plugin_dir):
@@ -156,7 +164,7 @@ def get_active_plugins(self):
'''
Return a list the instances
'''
- return [plugin[0] for plugin in self._active_plugins.values()]
+ return [plugin[0] for plugin in list(self._active_plugins.values())]
def __getitem__(self, plugin_name):
'''
@@ -213,7 +221,7 @@ def __len__(self):
'''
return len(self._found_plugins)
- def __nonzero__(self):
+ def __bool__(self):
'''
Magic method to indicate that any
instance must pass the if conditional
@@ -273,7 +281,7 @@ def _load_module(self, module, klassname, metadata, dir_name):
plugin_instance = klass(self._service_locator, metadata=metadata)
#return the plugin instance
return plugin_instance
- except(ImportError, AttributeError), reason:
+ except(ImportError, AttributeError) as reason:
raise PluginManagerException('Error loading "%s": %s' %
(module, reason))
finally:
@@ -284,7 +292,7 @@ def load(self, plugin_name, dir_name):
global PLUGIN_EXTENSION
if plugin_name in self._active_plugins:
return
- for dir_name, plugin_list in self._plugins_by_dir.iteritems():
+ for dir_name, plugin_list in self._plugins_by_dir.items():
if plugin_name in plugin_list:
ext = PLUGIN_EXTENSION
plugin_filename = os.path.join(dir_name, plugin_name)
@@ -307,7 +315,7 @@ def load(self, plugin_name, dir_name):
#tuple (instance, metadata)
plugin_metadata = (plugin_instance, plugin_structure)
self._active_plugins[plugin_name] = plugin_metadata
- except (PluginManagerException, Exception), reason:
+ except (PluginManagerException, Exception) as reason:
logger.error("Not instanciated (%s): %s", plugin_name,
reason)
#remove the plugin because has errors
@@ -321,7 +329,7 @@ def load(self, plugin_name, dir_name):
plugin_name)
def load_all(self):
- for dir, pl in self._plugins_by_dir.iteritems():
+ for dir, pl in self._plugins_by_dir.items():
#Copy the list because may be we REMOVE item while iterate!
found_plugins_aux = copy.copy(pl)
for plugin_name in found_plugins_aux:
@@ -339,7 +347,7 @@ def unload(self, plugin_name):
#call a special method *finish* in the plugin!
plugin_object.finish()
del self._active_plugins[plugin_name]
- except Exception, reason:
+ except Exception as reason:
logger.error("Finishing plugin (%s): %s", plugin_name, reason)
else:
logger.info("Successfuly finished (%s)", plugin_name)
@@ -375,10 +383,10 @@ def _availables_plugins(url):
Return the availables plugins from an url in NINJA-IDE web page
"""
try:
- descriptor = urllib2.urlopen(url)
+ descriptor = urlopen(url)
plugins = json.load(descriptor)
return plugins
- except urllib2.URLError:
+ except URLError:
return {}
@@ -426,7 +434,7 @@ def download_plugin(file_):
plugins_installed_before = set(__get_all_plugin_descriptors())
#download the plugin
fileName = os.path.join(resources.PLUGINS, os.path.basename(file_))
- content = urllib2.urlopen(file_)
+ content = urlopen(file_)
f = open(fileName, 'wb')
f.write(content.read())
f.close()
@@ -527,7 +535,7 @@ def uninstall_plugin(plug):
for root, dirs, files in os.walk(pluginDir):
pluginFiles = [os.path.join(root, f) for f in files]
#remove all files
- map(os.remove, pluginFiles)
+ list(map(os.remove, pluginFiles))
#collect subfolders
folders += [os.path.join(root, d) for d in dirs]
folders.reverse()
@@ -257,7 +257,7 @@ def _fileSaved(self, fileName):
"""
Signal emitted after save a file
"""
- fileName = unicode(fileName.split(":")[-1]).strip()
+ fileName = fileName.split(":")[-1].strip()
self.fileSaved.emit(fileName)
def _currentTabChanged(self, fileName):
Oops, something went wrong.

0 comments on commit cc69778

Please sign in to comment.