Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Remi Rampin remram44 authored
40 ninja_ide/gui/dialogs/project_properties_widget.py
@@ -100,6 +100,9 @@ def save_properties(self):
100 100 # FIXME
101 101 self._item.pythonPath = self.projectExecution.txtPythonPath.text()
102 102 self._item.PYTHONPATH = self.projectExecution.PYTHONPATH.toPlainText()
  103 + self._item.additional_builtins = filter(
  104 + lambda e: e, # remove empty names
  105 + self.projectExecution.additional_builtins.text().split(' '))
103 106 self._item.preExecScript = self.projectExecution.txtPreExec.text()
104 107 self._item.postExecScript = self.projectExecution.txtPostExec.text()
105 108 self._item.programParams = self.projectExecution.txtParams.text()
@@ -124,6 +127,7 @@ def save_properties(self):
124 127 project['use-tabs'] = self._item.useTabs
125 128 project['pythonPath'] = self._item.pythonPath # FIXME
126 129 project['PYTHONPATH'] = self._item.PYTHONPATH
  130 + project['additional_builtins'] = self._item.additional_builtins
127 131 project['preExecScript'] = self._item.preExecScript
128 132 project['postExecScript'] = self._item.postExecScript
129 133 project['venv'] = self._item.venv
@@ -244,36 +248,46 @@ def __init__(self, parent):
244 248 self.PYTHONPATH.setToolTip(self.tr("One path per line"))
245 249 grid.addWidget(self.PYTHONPATH, 2, 1)
246 250
  251 + # Additional builtins/globals for pyflakes
  252 + grid.addWidget(QLabel(self.tr("Additional builtins/globals:")), 3, 0)
  253 + self.additional_builtins = QLineEdit()
  254 + self.additional_builtins.setText(
  255 + ' '.join(self._parent._item.additional_builtins))
  256 + self.additional_builtins.setToolTip(self.tr(
  257 + "Space-separated list of symbols that will be considered as "
  258 + "builtin in every file"))
  259 + grid.addWidget(self.additional_builtins, 3, 1)
  260 +
247 261 self.txtPreExec = QLineEdit()
248 262 ui_tools.LineEditButton(self.txtPreExec, self.txtPreExec.clear,
249 263 self.style().standardPixmap(self.style().SP_TrashIcon))
250 264 self.txtPreExec.setReadOnly(True)
251 265 self.txtPreExec.setText(self._parent._item.preExecScript)
252 266 self.btnPreExec = QPushButton(QIcon(resources.IMAGES['open']), '')
253   - grid.addWidget(QLabel(self.tr("Pre-exec Script:")), 3, 0)
254   - grid.addWidget(self.txtPreExec, 3, 1)
255   - grid.addWidget(self.btnPreExec, 3, 2)
  267 + grid.addWidget(QLabel(self.tr("Pre-exec Script:")), 4, 0)
  268 + grid.addWidget(self.txtPreExec, 4, 1)
  269 + grid.addWidget(self.btnPreExec, 4, 2)
256 270 self.txtPostExec = QLineEdit()
257 271 ui_tools.LineEditButton(self.txtPostExec, self.txtPostExec.clear,
258 272 self.style().standardPixmap(self.style().SP_TrashIcon))
259 273 self.txtPostExec.setReadOnly(True)
260 274 self.txtPostExec.setText(self._parent._item.postExecScript)
261 275 self.btnPostExec = QPushButton(QIcon(resources.IMAGES['open']), '')
262   - grid.addWidget(QLabel(self.tr("Post-exec Script:")), 4, 0)
263   - grid.addWidget(self.txtPostExec, 4, 1)
264   - grid.addWidget(self.btnPostExec, 4, 2)
  276 + grid.addWidget(QLabel(self.tr("Post-exec Script:")), 5, 0)
  277 + grid.addWidget(self.txtPostExec, 5, 1)
  278 + grid.addWidget(self.btnPostExec, 5, 2)
265 279
266 280 grid.addItem(QSpacerItem(5, 10, QSizePolicy.Expanding,
267   - QSizePolicy.Expanding), 5, 0)
  281 + QSizePolicy.Expanding), 6, 0)
268 282
269 283 # Properties
270   - grid.addWidget(QLabel(self.tr("Properties:")), 6, 0)
  284 + grid.addWidget(QLabel(self.tr("Properties:")), 7, 0)
271 285 self.txtParams = QLineEdit()
272 286 self.txtParams.setToolTip(
273 287 self.tr("Separate the params with commas (ie: help, verbose)"))
274 288 self.txtParams.setText(self._parent._item.programParams)
275   - grid.addWidget(QLabel(self.tr("Params (comma separated):")), 7, 0)
276   - grid.addWidget(self.txtParams, 7, 1)
  289 + grid.addWidget(QLabel(self.tr("Params (comma separated):")), 8, 0)
  290 + grid.addWidget(self.txtParams, 8, 1)
277 291 #Widgets for virtualenv properties
278 292 self.txtVenvPath = QLineEdit()
279 293 ui_tools.LineEditButton(self.txtVenvPath, self.txtVenvPath.clear,
@@ -283,9 +297,9 @@ def __init__(self, parent):
283 297 self._dir_completer.setModel(QDirModel(self._dir_completer))
284 298 self.txtVenvPath.setCompleter(self._dir_completer)
285 299 self.btnVenvPath = QPushButton(QIcon(resources.IMAGES['open']), '')
286   - grid.addWidget(QLabel(self.tr("Virtualenv Folder:")), 8, 0)
287   - grid.addWidget(self.txtVenvPath, 8, 1)
288   - grid.addWidget(self.btnVenvPath, 8, 2)
  300 + grid.addWidget(QLabel(self.tr("Virtualenv Folder:")), 9, 0)
  301 + grid.addWidget(self.txtVenvPath, 9, 1)
  302 + grid.addWidget(self.btnVenvPath, 9, 2)
289 303
290 304 self.connect(self.btnBrowse, SIGNAL("clicked()"), self.select_file)
291 305 self.connect(self.btnPythonPath, SIGNAL("clicked()"),
6 ninja_ide/gui/editor/editor.py
@@ -122,7 +122,11 @@ def __init__(self, filename, project, project_obj=None):
122 122 if filename in settings.BOOKMARKS:
123 123 self._sidebarWidget._bookmarks = settings.BOOKMARKS[filename]
124 124 self.pep8 = pep8_checker.Pep8Checker(self)
125   - self.errors = errors_checker.ErrorsChecker(self)
  125 + if project_obj is not None:
  126 + additional_builtins = project_obj.additional_builtins
  127 + else:
  128 + additional_builtins = []
  129 + self.errors = errors_checker.ErrorsChecker(self, additional_builtins)
126 130 self.migration = migration_2to3.MigrationTo3(self)
127 131
128 132 self.textModified = False
6 ninja_ide/gui/editor/errors_checker.py
@@ -39,9 +39,10 @@ class ErrorsChecker(QThread):
39 39 pat_enable_lint = re.compile('(\s)*#lint:enable$')
40 40 pat_ignore_lint = re.compile('(.)+#lint:ok$|(.)+# lint:ok$')
41 41
42   - def __init__(self, editor):
  42 + def __init__(self, editor, additional_builtins=[]):
43 43 super(ErrorsChecker, self).__init__()
44 44 self._editor = editor
  45 + self._builtins = additional_builtins
45 46 self._path = ''
46 47 self._encoding = ''
47 48 self.errorsSummary = {}
@@ -66,7 +67,8 @@ def run(self):
66 67 if self._encoding is not None:
67 68 source = source.encode(self._encoding)
68 69 parseResult = compiler.parse(source)
69   - lint_checker = checker.Checker(parseResult, self._path)
  70 + lint_checker = checker.Checker(parseResult, self._path,
  71 + builtins=self._builtins)
70 72 for m in lint_checker.messages:
71 73 lineno = m.lineno - 1
72 74 if lineno not in self.errorsSummary:
1  ninja_ide/gui/explorer/tree_projects_widget.py
@@ -794,6 +794,7 @@ def __init__(self, parent, _name, path):
794 794 settings.SUPPORTED_EXTENSIONS)
795 795 self.pythonPath = project.get('pythonPath', settings.PYTHON_PATH)
796 796 self.PYTHONPATH = project.get('PYTHONPATH', '')
  797 + self.additional_builtins = project.get('additional_builtins', [])
797 798 self.programParams = project.get('programParams', '')
798 799 self.venv = project.get('venv', '')
799 800 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.