Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adds an "additional builtins" setting

This uses the 'builtins' parameter for pyflakes' Checker to allow
the user to add custom symbols that will be considered builtin/global in
every file. This is useful for projects that add symbols to the builtin
module, such as projects using gettext.install().
  • Loading branch information...
commit 8c6f253c6879371d4a6e0610e4ab46f256bbf82b 1 parent 1e4589a
@remram44 remram44 authored
View
40 ninja_ide/gui/dialogs/project_properties_widget.py
@@ -100,6 +100,9 @@ def save_properties(self):
# FIXME
self._item.pythonPath = self.projectExecution.txtPythonPath.text()
self._item.PYTHONPATH = self.projectExecution.PYTHONPATH.toPlainText()
+ self._item.additional_builtins = filter(
+ lambda e: e, # remove empty names
+ self.projectExecution.additional_builtins.text().split(' '))
self._item.preExecScript = self.projectExecution.txtPreExec.text()
self._item.postExecScript = self.projectExecution.txtPostExec.text()
self._item.programParams = self.projectExecution.txtParams.text()
@@ -124,6 +127,7 @@ def save_properties(self):
project['use-tabs'] = self._item.useTabs
project['pythonPath'] = self._item.pythonPath # FIXME
project['PYTHONPATH'] = self._item.PYTHONPATH
+ project['additional_builtins'] = self._item.additional_builtins
project['preExecScript'] = self._item.preExecScript
project['postExecScript'] = self._item.postExecScript
project['venv'] = self._item.venv
@@ -244,36 +248,46 @@ def __init__(self, parent):
self.PYTHONPATH.setToolTip(self.tr("One path per line"))
grid.addWidget(self.PYTHONPATH, 2, 1)
+ # Additional builtins/globals for pyflakes
+ grid.addWidget(QLabel(self.tr("Additional builtins/globals:")), 3, 0)
+ self.additional_builtins = QLineEdit()
+ self.additional_builtins.setText(
+ ' '.join(self._parent._item.additional_builtins))
+ self.additional_builtins.setToolTip(self.tr(
+ "Space-separated list of symbols that will be considered as "
+ "builtin in every file"))
+ grid.addWidget(self.additional_builtins, 3, 1)
+
self.txtPreExec = QLineEdit()
ui_tools.LineEditButton(self.txtPreExec, self.txtPreExec.clear,
self.style().standardPixmap(self.style().SP_TrashIcon))
self.txtPreExec.setReadOnly(True)
self.txtPreExec.setText(self._parent._item.preExecScript)
self.btnPreExec = QPushButton(QIcon(resources.IMAGES['open']), '')
- grid.addWidget(QLabel(self.tr("Pre-exec Script:")), 3, 0)
- grid.addWidget(self.txtPreExec, 3, 1)
- grid.addWidget(self.btnPreExec, 3, 2)
+ grid.addWidget(QLabel(self.tr("Pre-exec Script:")), 4, 0)
+ grid.addWidget(self.txtPreExec, 4, 1)
+ grid.addWidget(self.btnPreExec, 4, 2)
self.txtPostExec = QLineEdit()
ui_tools.LineEditButton(self.txtPostExec, self.txtPostExec.clear,
self.style().standardPixmap(self.style().SP_TrashIcon))
self.txtPostExec.setReadOnly(True)
self.txtPostExec.setText(self._parent._item.postExecScript)
self.btnPostExec = QPushButton(QIcon(resources.IMAGES['open']), '')
- grid.addWidget(QLabel(self.tr("Post-exec Script:")), 4, 0)
- grid.addWidget(self.txtPostExec, 4, 1)
- grid.addWidget(self.btnPostExec, 4, 2)
+ grid.addWidget(QLabel(self.tr("Post-exec Script:")), 5, 0)
+ grid.addWidget(self.txtPostExec, 5, 1)
+ grid.addWidget(self.btnPostExec, 5, 2)
grid.addItem(QSpacerItem(5, 10, QSizePolicy.Expanding,
- QSizePolicy.Expanding), 5, 0)
+ QSizePolicy.Expanding), 6, 0)
# Properties
- grid.addWidget(QLabel(self.tr("Properties:")), 6, 0)
+ grid.addWidget(QLabel(self.tr("Properties:")), 7, 0)
self.txtParams = QLineEdit()
self.txtParams.setToolTip(
self.tr("Separate the params with commas (ie: help, verbose)"))
self.txtParams.setText(self._parent._item.programParams)
- grid.addWidget(QLabel(self.tr("Params (comma separated):")), 7, 0)
- grid.addWidget(self.txtParams, 7, 1)
+ grid.addWidget(QLabel(self.tr("Params (comma separated):")), 8, 0)
+ grid.addWidget(self.txtParams, 8, 1)
#Widgets for virtualenv properties
self.txtVenvPath = QLineEdit()
ui_tools.LineEditButton(self.txtVenvPath, self.txtVenvPath.clear,
@@ -283,9 +297,9 @@ def __init__(self, parent):
self._dir_completer.setModel(QDirModel(self._dir_completer))
self.txtVenvPath.setCompleter(self._dir_completer)
self.btnVenvPath = QPushButton(QIcon(resources.IMAGES['open']), '')
- grid.addWidget(QLabel(self.tr("Virtualenv Folder:")), 8, 0)
- grid.addWidget(self.txtVenvPath, 8, 1)
- grid.addWidget(self.btnVenvPath, 8, 2)
+ grid.addWidget(QLabel(self.tr("Virtualenv Folder:")), 9, 0)
+ grid.addWidget(self.txtVenvPath, 9, 1)
+ grid.addWidget(self.btnVenvPath, 9, 2)
self.connect(self.btnBrowse, SIGNAL("clicked()"), self.select_file)
self.connect(self.btnPythonPath, SIGNAL("clicked()"),
View
6 ninja_ide/gui/editor/editor.py
@@ -122,7 +122,11 @@ def __init__(self, filename, project, project_obj=None):
if filename in settings.BOOKMARKS:
self._sidebarWidget._bookmarks = settings.BOOKMARKS[filename]
self.pep8 = pep8_checker.Pep8Checker(self)
- self.errors = errors_checker.ErrorsChecker(self)
+ if project_obj is not None:
+ additional_builtins = project_obj.additional_builtins
+ else:
+ additional_builtins = []
+ self.errors = errors_checker.ErrorsChecker(self, additional_builtins)
self.migration = migration_2to3.MigrationTo3(self)
self.textModified = False
View
6 ninja_ide/gui/editor/errors_checker.py
@@ -39,9 +39,10 @@ class ErrorsChecker(QThread):
pat_enable_lint = re.compile('(\s)*#lint:enable$')
pat_ignore_lint = re.compile('(.)+#lint:ok$|(.)+# lint:ok$')
- def __init__(self, editor):
+ def __init__(self, editor, additional_builtins=[]):
super(ErrorsChecker, self).__init__()
self._editor = editor
+ self._builtins = additional_builtins
self._path = ''
self._encoding = ''
self.errorsSummary = {}
@@ -66,7 +67,8 @@ def run(self):
if self._encoding is not None:
source = source.encode(self._encoding)
parseResult = compiler.parse(source)
- lint_checker = checker.Checker(parseResult, self._path)
+ lint_checker = checker.Checker(parseResult, self._path,
+ builtins=self._builtins)
for m in lint_checker.messages:
lineno = m.lineno - 1
if lineno not in self.errorsSummary:
View
1  ninja_ide/gui/explorer/tree_projects_widget.py
@@ -794,6 +794,7 @@ def __init__(self, parent, _name, path):
settings.SUPPORTED_EXTENSIONS)
self.pythonPath = project.get('pythonPath', settings.PYTHON_PATH)
self.PYTHONPATH = project.get('PYTHONPATH', '')
+ self.additional_builtins = project.get('additional_builtins', [])
self.programParams = project.get('programParams', '')
self.venv = project.get('venv', '')
self.related_projects = project.get('relatedProjects', [])

0 comments on commit 8c6f253

Please sign in to comment.
Something went wrong with that request. Please try again.