Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refactored the autocomplete plugin. Created a pyplete, a generic

module to autocompletion in python
  • Loading branch information...
commit f8e0ab5e9b9cd6035bec30adc5c8be7d76aba5b5 1 parent 6b7990d
@goinnn authored
View
332 kate_plugins/pyte_plugins/autocomplete/autocomplete.py
@@ -1,62 +1,23 @@
-import compiler
-import glob
-import os
-import pkgutil
-import re
import sys
import kate
-from compiler import parse
-
from PyKDE4.ktexteditor import KTextEditor
from PyQt4 import QtCore
-from pysmell.codefinder import CodeFinder
from autopate import AbstractCodeCompletionModel
+from pyte_plugins.autocomplete.pyplete import PyPlete
+from pyte_plugins.autocomplete.utils import (from_first_module, import_complete,
+ from_other_modules, from_complete)
-global modules_path
global python_path
global windowInterface
global codecompletationmodel
-modules_path = {}
+global pyplete
python_path = []
PYSMELL_PREFIX = '__package____module__.'
-_spaces = "(?:\ |\t|\n)*"
-# " from"
-_from = "%sfrom" % _spaces
-# " import"
-_import = "%simport" % _spaces
-_first_module = "(?P<firstmodule>\w+)"
-_other_module = "(?:[.](?P<othermodule>[\w.]+)?)?"
-_import_module = "(?:\w+,(?:\ |\t|\n)*)*(?P<importmodule>\w+)"
-
-# " from "
-_from_begin = "%s%s" % (_from, _spaces)
-# " from os"
-_from_first_module = "%s%s" % (_from_begin, _first_module)
-# " from os.path"
-_from_other_modules = "%s%s" % (_from_first_module, _other_module)
-# " from os.path import"
-_from_import = "%s%s%s" % (_from_other_modules, _spaces, _import)
-# " from os.path import join"
-_from_complete = "%s%s%s?" % (_from_import, _spaces, _import_module)
-
-# " import"
-_import_begin = "%s" % _import
-# " import os"
-_import_complete = "%s%s%s?" % (_import_begin, _spaces, _import_module)
-
-from_first_module = re.compile(_from_first_module + "?$")
-from_other_modules = re.compile(_from_other_modules + "$")
-from_import = re.compile(_from_import + "$")
-from_complete = re.compile(_from_complete + "$")
-
-import_begin = re.compile(_import_begin + "$")
-import_complete = re.compile(_import_complete + "?$")
-
class PythonCodeCompletionModel(AbstractCodeCompletionModel):
@@ -64,24 +25,39 @@ class PythonCodeCompletionModel(AbstractCodeCompletionModel):
OPERATORS = ["=", " ", "[", "]", "(", ")", "{", "}", ":", ">", "<",
"+", "-", "*", "/", "%", " and ", " or ", ","]
+ @classmethod
+ def getPythonPath(cls):
+ global python_path
+ if python_path:
+ return python_path
+ python_path = sys.path
+ try:
+ from pyte_plugins.autocomplete import autocomplete_path
+ doc = kate.activeDocument()
+ view = doc.activeView()
+ python_path = autocomplete_path.path(doc, view) + python_path
+ sys.path = python_path
+ except ImportError:
+ pass
+ return python_path
+
def completionInvoked(self, view, word, invocationType):
line = super(PythonCodeCompletionModel, self).completionInvoked(view,
- word,
- invocationType)
+ word, invocationType)
is_auto = False
line_rough = line
if 'from' in line or 'import' in line:
is_auto = self.autoCompleteImport(view, word, line)
- line = self.get_expression_last_expression(line)
+ line = self.getLastExpression(line)
if not is_auto and line:
- is_auto = self.autoCompleteDynamic(view, word, line)
+ is_auto = self.autoCompleteLine(view, word, line)
if not is_auto and line and line_rough and not self.SEPARATOR in line_rough:
- is_auto = self.autoCompleteInThisFile(view, word, line)
+ is_auto = self.autoCompleteFile(view, word, line)
def executeCompletionItem(self, doc, word, row):
raw, col = word.start().position()
line = unicode(doc.line(raw))
- line = self.parse_line(line)
+ line = self.parseLine(line)
t = self.resultList[row].get('type', None)
args = self.resultList[row].get('args', None).strip()
text = self.resultList[row].get('text', None)
@@ -95,19 +71,18 @@ def executeCompletionItem(self, doc, word, row):
return
return super(PythonCodeCompletionModel, self).executeCompletionItem(doc, word, row)
- def parse_line(self, line):
- line = super(PythonCodeCompletionModel, self).parse_line(line)
+ def parseLine(self, line):
+ line = super(PythonCodeCompletionModel, self).parseLine(line)
if "'" in line or '"' in line:
return line
if ";" in line:
- return self.parse_line(line.split(";")[-1])
+ return self.parseLine(line.split(";")[-1])
return line
def autoCompleteImport(self, view, word, line):
mfb = from_first_module.match(line) or import_complete.match(line)
if mfb:
- self.resultList = self.getTopLevelModules()
- return True
+ return pyplete.get_importables_top_level(self.resultList)
mfom = from_other_modules.match(line)
if mfom:
module, submodules = mfom.groups()
@@ -115,10 +90,8 @@ def autoCompleteImport(self, view, word, line):
submodules = []
else:
submodules = submodules.split(self.SEPARATOR)[:-1]
- self.resultList = self.getSubmodules(module,
- submodules,
- attributes=False)
- return True
+ return pyplete.get_importables_rest_level(self.resultList, module,
+ submodules, into_module=False)
mfc = from_complete.match(line)
if mfc:
module, submodules, import_module = mfc.groups()
@@ -126,191 +99,40 @@ def autoCompleteImport(self, view, word, line):
submodules = submodules.split(self.SEPARATOR)
else:
submodules = []
- self.resultList = self.getSubmodules(module,
- submodules,
- attributes=True)
- return True
+ return pyplete.get_importables_rest_level(self.resultList, module,
+ submodules, into_module=True)
return False
- def autoCompleteDynamic(self, view, word, line):
+ def autoCompleteLine(self, view, word, line):
try:
last_dot = line.rindex(self.SEPARATOR)
line = line[:last_dot]
except ValueError:
pass
- text = self._parse_text(view, word, line)
- return self.getDynamic(text, line)
-
- def autoCompleteInThisFile(self, view, word, line):
- text = self._parse_text(view, word, line)
- return self.getTextInfo(text, self.resultList)
-
- def _parse_text(self, view, word, line):
- doc = view.document()
- text_list = unicode(doc.text()).split("\n")
- raw, column = word.start().position()
- line = text_list[raw]
- if ";" in line and not "'" in line and not '"' in line:
- text_list[raw] = ';'.join(text_list[raw].split(";")[:-1])
- else:
- del text_list[raw]
- text = '\n'.join(text_list)
- line = line.strip()
- return text
-
- @classmethod
- def getTopLevelModules(cls):
- # http://code.google.com/p/djangode/source/browse/trunk/djangode/data/codemodel/codemodel.py#57
- modules = []
- pythonpath = cls.getPythonPath()
- for directory in pythonpath:
- for filename in glob.glob(directory + os.sep + "*"):
- module_name = None
- if filename.endswith(".py"):
- module_name = filename.split(os.sep)[-1][:-3]
- icon = 'module'
- elif os.path.isdir(filename) and os.path.exists(filename + os.sep + "__init__.py"):
- module_name = filename.split(os.sep)[-1]
- icon = 'package'
- if not module_name:
- continue
- module = cls.createItemAutoComplete(module_name, icon)
- if module and not module in modules:
- modules.append(module)
- modules_path[module_name] = [filename]
- return modules
-
- def getSubmodules(self, module_name, submodules=None,
- attributes=True):
- module_dir = modules_path[module_name][0]
- submodules = [submodule for submodule in submodules if submodule]
- if submodules:
- submodules = os.sep.join(submodules)
- module_dir = "%s%s%s" % (module_dir, os.sep, submodules)
- modules = []
- for loader, module_name, is_pkg in pkgutil.walk_packages([module_dir]):
- icon = is_pkg and 'package' or 'module'
- module = self.createItemAutoComplete(module_name, icon)
- modules.append(module)
- if attributes:
- att_dir = os.sep.join(module_dir.split(os.sep)[:-1])
- att_module = module_dir.split(os.sep)[-1].replace('.py', '').replace('.pyc', '')
- importer = pkgutil.get_importer(att_dir)
- module = importer.find_module(att_module)
- if module:
- self.getTextInfo(module.get_source(), modules)
- return sorted(modules)
+ text = self._parseText(view, word, line)
+ return self.getImportablesFromLine(self.resultList, text, line)
- def getModuleSmart(self, module_name, submodules, submodules_undone=None):
- module_dir = modules_path[module_name][0]
- submodules_undone = submodules_undone or []
- submodules_str = os.sep.join(submodules)
- if submodules_str:
- module_dir = "%s%s%s" % (module_dir, os.sep, submodules_str)
- att_dir = os.sep.join(module_dir.split(os.sep)[:-1])
- att_module = module_dir.split(os.sep)[-1].replace('.py', '').replace('.pyc', '')
- importer = pkgutil.get_importer(att_dir)
- module = importer.find_module(att_module)
- if module:
- return (module, submodules_undone)
- elif submodules:
- submodules_undone.append(submodules[-1])
- return self.getModuleSmart(module_name, submodules[:-1], submodules_undone)
- return (None, submodules_undone)
+ def autoCompleteFile(self, view, word, line):
+ text = self._parseText(view, word, line)
+ return self.getImportablesFromText(self.resultList, text)
- def getDynamic(self, text, code_line, text_info=True):
+ def getImportablesFromLine(self, list_autocomplete, text,
+ code_line, text_info=True):
try:
- code = parse(text)
- code_walk = compiler.walk(code, CodeFinder())
- code_line_split = code_line.split(self.SEPARATOR)
- prefix = code_line_split[0]
- prfx_code_line = '%s%s' % (PYSMELL_PREFIX, prefix)
- if prfx_code_line in code_walk.modules['CONSTANTS']:
- return False
- elif code_walk.modules['CLASSES'].get(prfx_code_line, None) and not code_line_split[1:]:
- class_smell = code_walk.modules['CLASSES'].get(prfx_code_line)
- self.treatment_pysmell_into_cls(class_smell, self.resultList)
- return True
- elif prfx_code_line in [name for name, args, desc in code_walk.modules['FUNCTIONS']]:
- index_func = [f[0] for f in code_walk.modules['FUNCTIONS']].index(prfx_code_line)
- func_smell = code_walk.modules['FUNCTIONS'][index_func]
- self.resultList.append(self.treatment_pysmell_into_func(func_smell))
- return True
- elif code_walk.modules['POINTERS'].get(prfx_code_line, None):
- module_path = code_walk.modules['POINTERS'].get(prfx_code_line, None)
- module = module_path.split(self.SEPARATOR)[0]
- submodules = module_path.split(self.SEPARATOR)[1:]
- submodules.extend(code_line_split[1:])
- module_done, submodules_undone = self.getModuleSmart(module, submodules)
- if not submodules_undone:
- autocompletion_submodules = self.getSubmodules(module, submodules, True)
- for autocompletion_submodule in autocompletion_submodules:
- if autocompletion_submodule not in self.resultList:
- self.resultList.append(autocompletion_submodule)
- submodules_undone.reverse()
- line = self.SEPARATOR.join(submodules_undone)
- text = module_done.get_source()
- if line:
- return self.getDynamic(text, line)
- if text_info:
- return self.getTextInfo(text, self.resultList)
+ return pyplete.get_importables_from_line(list_autocomplete, text,
+ code_line, text_info)
except SyntaxError, e:
- self.treatment_exception(e)
+ self.treatmentException(e)
return False
- @classmethod
- def getPythonPath(cls):
- global python_path
- if python_path:
- return python_path
- python_path = sys.path
- try:
- from pyte_plugins.autocomplete import autocomplete_path
- doc = kate.activeDocument()
- view = doc.activeView()
- python_path = autocomplete_path.path(doc, view) + python_path
- sys.path = python_path
- except ImportError:
- pass
- return python_path
-
- def getTextInfo(self, text, list_autocomplete, line=None):
+ def getImportablesFromText(self, list_autocomplete, text, line=None):
try:
- code = parse(text)
- code_walk = compiler.walk(code, CodeFinder())
- modules = code_walk.modules
- constans = modules['CONSTANTS']
- for constant in constans:
- item = self.treatment_pysmell_const(constant)
- if not item in list_autocomplete:
- list_autocomplete.append(item)
-
- functions = modules['FUNCTIONS']
- for func in functions:
- item = self.treatment_pysmell_func(func)
- if not item in list_autocomplete:
- list_autocomplete.append(item)
-
- classes = modules['CLASSES']
- for cls in classes.items():
- item = self.treatment_pysmell_cls(cls)
- if not item in list_autocomplete:
- list_autocomplete.append(item)
-
- is_auto = len(list_autocomplete) > 0
- if not is_auto and line:
- line = "%s%s" % (PYSMELL_PREFIX, line.strip())
- for pointer in modules['POINTERS'].keys():
- if pointer.startswith(line):
- is_auto = is_auto or self.getDynamic(text,
- pointer.replace(PYSMELL_PREFIX, ''),
- text_info=False)
- return is_auto
+ return pyplete.get_importables_from_text(list_autocomplete, text, line)
except SyntaxError, e:
- self.treatment_exception(e)
+ self.treatmentException(e)
return False
- def treatment_exception(self, e):
+ def treatmentException(self, e):
if self.invocationType == KTextEditor.CodeCompletionModel.AutomaticInvocation:
return
f = e.filename or ''
@@ -323,48 +145,20 @@ def treatment_exception(self, e):
message = '%s\n * text: %s' % (message, text)
if line:
message = '%s\n * line: %s' % (message, line)
- kate.gui.popup(message,
- 2, icon='dialog-warning', minTextWidth=200)
-
- def treatment_pysmell_const(self, constant):
- constant = constant.replace(PYSMELL_PREFIX, '')
- return self.createItemAutoComplete(constant, 'constant')
-
- def treatment_pysmell_func(self, func):
- func_name, args, description = func
- func_name = func_name.replace(PYSMELL_PREFIX, '')
- args = ', '.join(args)
- args = ' (%s)' % args
- return self.createItemAutoComplete(func_name,
- 'function', args, description)
+ kate.gui.popup(message, 2, icon='dialog-warning', minTextWidth=200)
- def treatment_pysmell_into_func(self, func):
- return self.treatment_pysmell_func(func)
-
- def treatment_pysmell_cls(self, cls):
- cls_name, info = cls
- cls_name = cls_name.replace(PYSMELL_PREFIX, '')
- args_constructor = info.get('constructor', None)
- args_constructor = ', '.join(args_constructor)
- args_constructor = ' (%s)' % args_constructor
- description = info.get('docstring', None)
- return self.createItemAutoComplete(cls_name,
- 'class', args_constructor,
- description)
-
- def treatment_pysmell_into_cls(self, cls, resultList):
- for m in cls['methods']:
- item = self.treatment_pysmell_func(m)
- if not item in resultList:
- resultList.append(item)
- for m in cls['constructor']:
- item = self.treatment_pysmell_func(m)
- if not item in resultList:
- resultList.append(item)
- for m in cls['properties']:
- item = self.treatment_pysmell_const(m)
- if not item in resultList:
- resultList.append(item)
+ def _parseText(self, view, word, line):
+ doc = view.document()
+ text_list = unicode(doc.text()).split("\n")
+ raw, column = word.start().position()
+ line = text_list[raw]
+ if ";" in line and not "'" in line and not '"' in line:
+ text_list[raw] = ';'.join(text_list[raw].split(";")[:-1])
+ else:
+ del text_list[raw]
+ text = '\n'.join(text_list)
+ line = line.strip()
+ return text
def createSignalAutocompleteDocument(view, *args, **kwargs):
@@ -375,7 +169,9 @@ def createSignalAutocompleteDocument(view, *args, **kwargs):
#http://code.google.com/p/lilykde/source/browse/trunk/frescobaldi/python/frescobaldi_app/mainapp.py#1391
#http://api.kde.org/4.0-api/kdelibs-apidocs/kate/html/katecompletionmodel_8cpp_source.html
#https://svn.reviewboard.kde.org/r/1640/diff/?expand=1
- PythonCodeCompletionModel.getTopLevelModules()
+ global pyplete
+ pyplete = PyPlete(PythonCodeCompletionModel.createItemAutoComplete,
+ PythonCodeCompletionModel.getPythonPath())
cci = view.codeCompletionInterface()
cci.registerCompletionModel(codecompletationmodel)
View
190 kate_plugins/pyte_plugins/autocomplete/pyplete.py
@@ -0,0 +1,190 @@
+import compiler
+import glob
+import os
+import pkgutil
+import sys
+
+from pysmell.codefinder import CodeFinder
+
+PYSMELL_PREFIX = '__package____module__.'
+
+
+class PyPlete(object):
+
+ def __init__(self, func_info=None, pythonpath=None, separator='.', *args, **kwargs):
+ super(PyPlete, self).__init__(*args, **kwargs)
+ if func_info:
+ self.func_info = func_info
+ if pythonpath:
+ self.pythonpath = pythonpath
+ else:
+ self.pythonpath = sys.path
+ self.separator = separator
+ self.get_importables_top_level([])
+
+ def func_info(self, name, icon):
+ return (name, icon)
+
+ def get_importables_top_level(self, list_autocomplete, use_cache=True):
+ # http://code.google.com/p/djangode/source/browse/trunk/djangode/data/codemodel/codemodel.py#57
+ if use_cache and getattr(self, 'importables_top_level', None):
+ list_autocomplete.extend(self.importables_top_level)
+ return bool(len(list_autocomplete))
+ self.importables_top_level = []
+ self.importables_path = {}
+ for directory in self.pythonpath:
+ for filename in glob.glob(directory + os.sep + "*"):
+ name = None
+ if filename.endswith(".py"):
+ name = filename.split(os.sep)[-1][:-3]
+ icon = 'module'
+ elif os.path.isdir(filename) and os.path.exists(filename + os.sep + "__init__.py"):
+ name = filename.split(os.sep)[-1]
+ icon = 'package'
+ if not name:
+ continue
+ importable = self.func_info(name, icon)
+ if importable and not importable in self.importables_top_level:
+ self.importables_top_level.append(importable)
+ self.importables_path[name] = [filename]
+ list_autocomplete.extend(self.importables_top_level)
+ return list_autocomplete and bool(len(list_autocomplete))
+
+ def get_importables_rest_level(self, list_autocomplete, imp_name, subimportables=None, into_module=True):
+ imp_path = self.importables_path[imp_name][0]
+ subimportables = [subimportable for subimportable in subimportables if subimportable]
+ if subimportables:
+ subimportables = os.sep.join(subimportables)
+ imp_path = "%s%s%s" % (imp_path, os.sep, subimportables)
+ for loader, imp_name, is_pkg in pkgutil.walk_packages([imp_path]):
+ icon = is_pkg and 'package' or 'module'
+ importable = self.func_info(imp_name, icon)
+ list_autocomplete.append(importable)
+ if into_module:
+ into_dir = os.sep.join(imp_path.split(os.sep)[:-1])
+ into_module = imp_path.split(os.sep)[-1].replace('.py', '').replace('.pyc', '')
+ importer = pkgutil.get_importer(into_dir)
+ imp = importer.find_module(into_module)
+ if imp:
+ self.get_importables_from_text(list_autocomplete, imp.get_source())
+ return list_autocomplete and bool(len(list_autocomplete))
+
+ def get_importables_from_text(self, list_autocomplete, text, line=None):
+ code = compiler.parse(text)
+ code_walk = compiler.walk(code, CodeFinder())
+ modules = code_walk.modules
+ treatment_dict = {'CONSTANTS': self.treatment_pysmell_const,
+ 'FUNCTIONS': self.treatment_pysmell_func,
+ 'CLASSES': self.treatment_pysmell_cls}
+ for key, func in treatment_dict.items():
+ pysmell_items = modules[key]
+ if isinstance(pysmell_items, dict):
+ pysmell_items = pysmell_items.items()
+ for pysmell_item in pysmell_items:
+ item = func(pysmell_item)
+ if not item in list_autocomplete:
+ list_autocomplete.append(item)
+
+ is_auto = len(list_autocomplete) > 0
+ if not is_auto and line:
+ line = "%s%s" % (PYSMELL_PREFIX, line.strip())
+ for pointer in modules['POINTERS'].keys():
+ if pointer.startswith(line):
+ is_auto = is_auto or self.get_importables_from_line(list_autocomplete,
+ text, pointer.replace(PYSMELL_PREFIX, ''),
+ text_info=False)
+ return is_auto
+
+ def get_importables_from_line(self, list_autocomplete, text, code_line, text_info=True):
+ code = compiler.parse(text)
+ code_walk = compiler.walk(code, CodeFinder())
+ code_line_split = code_line.split(self.separator)
+ prefix = code_line_split[0]
+ prfx_code_line = '%s%s' % (PYSMELL_PREFIX, prefix)
+ if prfx_code_line in code_walk.modules['CONSTANTS']:
+ return False
+ elif code_walk.modules['CLASSES'].get(prfx_code_line, None) and not code_line_split[1:]:
+ class_smell = code_walk.modules['CLASSES'].get(prfx_code_line)
+ self.treatment_pysmell_into_cls(class_smell, list_autocomplete)
+ return True
+ elif prfx_code_line in [name for name, args, desc in code_walk.modules['FUNCTIONS']]:
+ index_func = [f[0] for f in code_walk.modules['FUNCTIONS']].index(prfx_code_line)
+ func_smell = code_walk.modules['FUNCTIONS'][index_func]
+ list_autocomplete.append(self.treatment_pysmell_into_func(func_smell))
+ return True
+ elif code_walk.modules['POINTERS'].get(prfx_code_line, None):
+ module_path = code_walk.modules['POINTERS'].get(prfx_code_line, None)
+ module = module_path.split(self.separator)[0]
+ submodules = module_path.split(self.separator)[1:]
+ submodules.extend(code_line_split[1:])
+ module_done, submodules_undone = self.get_module_from_path(module, submodules)
+ if not submodules_undone:
+ autocompletion_submodules = self.get_importables_rest_level(list_autocomplete, module, submodules, True)
+ for autocompletion_submodule in autocompletion_submodules:
+ if autocompletion_submodule not in list_autocomplete:
+ list_autocomplete.append(autocompletion_submodule)
+ submodules_undone.reverse()
+ line = self.separator.join(submodules_undone)
+ text = module_done.get_source()
+ if line:
+ return self.get_importables_from_line(list_autocomplete, text, line)
+ if text_info:
+ return self.get_importables_from_text(list_autocomplete, text, list_autocomplete)
+ return False
+
+ def get_module_from_path(self, module_name, submodules, submodules_undone=None):
+ module_dir = self.importables_path[module_name][0]
+ submodules_undone = submodules_undone or []
+ submodules_str = os.sep.join(submodules)
+ if submodules_str:
+ module_dir = "%s%s%s" % (module_dir, os.sep, submodules_str)
+ att_dir = os.sep.join(module_dir.split(os.sep)[:-1])
+ att_module = module_dir.split(os.sep)[-1].replace('.py', '').replace('.pyc', '')
+ importer = pkgutil.get_importer(att_dir)
+ module = importer.find_module(att_module)
+ if module:
+ return (module, submodules_undone)
+ elif submodules:
+ submodules_undone.append(submodules[-1])
+ return self.get_module_from_path(module_name, submodules[:-1], submodules_undone)
+ return (None, submodules_undone)
+
+ def treatment_pysmell_const(self, constant):
+ constant = constant.replace(PYSMELL_PREFIX, '')
+ return self.func_info(constant, 'constant')
+
+ def treatment_pysmell_func(self, func):
+ func_name, args, description = func
+ func_name = func_name.replace(PYSMELL_PREFIX, '')
+ args = ', '.join(args)
+ args = ' (%s)' % args
+ return self.func_info(func_name,
+ 'function', args, description)
+
+ def treatment_pysmell_into_func(self, func):
+ return self.treatment_pysmell_func(func)
+
+ def treatment_pysmell_cls(self, cls):
+ cls_name, info = cls
+ cls_name = cls_name.replace(PYSMELL_PREFIX, '')
+ args_constructor = info.get('constructor', None)
+ args_constructor = ', '.join(args_constructor)
+ args_constructor = ' (%s)' % args_constructor
+ description = info.get('docstring', None)
+ return self.func_info(cls_name,
+ 'class', args_constructor,
+ description)
+
+ def treatment_pysmell_into_cls(self, cls, list_autocomplete):
+ for m in cls['methods']:
+ item = self.treatment_pysmell_func(m)
+ if not item in list_autocomplete:
+ list_autocomplete.append(item)
+ for m in cls['constructor']:
+ item = self.treatment_pysmell_func(m)
+ if not item in list_autocomplete:
+ list_autocomplete.append(item)
+ for m in cls['properties']:
+ item = self.treatment_pysmell_const(m)
+ if not item in list_autocomplete:
+ list_autocomplete.append(item)
View
35 kate_plugins/pyte_plugins/autocomplete/utils.py
@@ -0,0 +1,35 @@
+import re
+
+
+_spaces = "(?:\ |\t|\n)*"
+# " from"
+_from = "%sfrom" % _spaces
+# " import"
+_import = "%simport" % _spaces
+_first_module = "(?P<firstmodule>\w+)"
+_other_module = "(?:[.](?P<othermodule>[\w.]+)?)?"
+_import_module = "(?:\w+,(?:\ |\t|\n)*)*(?P<importmodule>\w+)"
+
+# " from "
+_from_begin = "%s%s" % (_from, _spaces)
+# " from os"
+_from_first_module = "%s%s" % (_from_begin, _first_module)
+# " from os.path"
+_from_other_modules = "%s%s" % (_from_first_module, _other_module)
+# " from os.path import"
+_from_import = "%s%s%s" % (_from_other_modules, _spaces, _import)
+# " from os.path import join"
+_from_complete = "%s%s%s?" % (_from_import, _spaces, _import_module)
+
+# " import"
+_import_begin = "%s" % _import
+# " import os"
+_import_complete = "%s%s%s?" % (_import_begin, _spaces, _import_module)
+
+from_first_module = re.compile(_from_first_module + "?$")
+from_other_modules = re.compile(_from_other_modules + "$")
+from_import = re.compile(_from_import + "$")
+from_complete = re.compile(_from_complete + "$")
+
+import_begin = re.compile(_import_begin + "$")
+import_complete = re.compile(_import_complete + "?$")
Please sign in to comment.
Something went wrong with that request. Please try again.