Skip to content

Commit

Permalink
Adopt flake8 rules, found some obscure bits and at least 1 bug
Browse files Browse the repository at this point in the history
  • Loading branch information
almarklein committed Jun 22, 2017
1 parent 2c5ac0b commit 79f98a9
Show file tree
Hide file tree
Showing 82 changed files with 221 additions and 445 deletions.
2 changes: 1 addition & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import sys, os
import sys, os # noqa

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
Expand Down
10 changes: 5 additions & 5 deletions freezeScript.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@

import sys, os, stat, shutil, struct
import subprocess
import cx_Freeze
from cx_Freeze import Executable, Freezer, setup
from cx_Freeze import Executable, Freezer, setup # noqa

# Define app name and such
name = "pyzo"
Expand Down Expand Up @@ -395,7 +394,8 @@ def copydir_smart(path1, path2):
shutil.copy(baseDir+'Info.plist',contentsDir+'Info.plist')

#Copy the qt_menu.nib directory (TODO: is this the place to look for it?)
potential_dirs = ['/opt/local/libexec/qt4/Library/Frameworks/QtGui.framework/Versions/4/Resources/', '/opt/local/Library/Frameworks/QtGui.framework/Versions/4/Resources/']
potential_dirs = ['/opt/local/libexec/qt4/Library/Frameworks/QtGui.framework/Versions/4/Resources/',
'/opt/local/Library/Frameworks/QtGui.framework/Versions/4/Resources/']
for d in potential_dirs:
if os.path.isdir(d + 'qt_menu.nib'):
shutil.copytree(d + 'qt_menu.nib', resourcesDir+'qt_menu.nib')
Expand All @@ -410,7 +410,7 @@ def copydir_smart(path1, path2):
# Create the dmg
if createDmg:
if os.spawnlp(os.P_WAIT,'hdiutil','hdiutil','create','-fs','HFSX',
'-format','UDZO',dmgFile, '-imagekey', 'zlib-level=9',
'-srcfolder',appDir,'-volname', 'pyzo')!=0:
'-format','UDZO',dmgFile, '-imagekey', 'zlib-level=9',
'-srcfolder',appDir,'-volname', 'pyzo')!=0:
raise OSError('creation of the dmg failed')

10 changes: 5 additions & 5 deletions pyzo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
'fonts/linux_fonts.conf')

# Import yoton as an absolute package
from pyzo import yotonloader
from pyzo import yotonloader # noqa
from pyzo.util import paths

# If there already is an instance of Pyzo, and the user is trying an
Expand All @@ -87,7 +87,7 @@
from pyzo.util.qt import QtCore, QtGui, QtWidgets

# Import language/translation tools
from pyzo.util._locale import translate, setLanguage
from pyzo.util._locale import translate, setLanguage # noqa

# Set environ to let kernel know some stats about us
os.environ['PYZO_PREFIX'] = sys.prefix
Expand All @@ -112,7 +112,7 @@ def event(self, event):
return QtWidgets.QApplication.event(self, event)

if not sys.platform.startswith('darwin'):
MyApp = QtWidgets.QApplication
MyApp = QtWidgets.QApplication # noqa

## Install excepthook
# In PyQt5 exceptions in Python will cuase an abort
Expand Down Expand Up @@ -236,7 +236,7 @@ def start():
"""

# Do some imports
from pyzo.core import pyzoLogging # to start logging asap
from pyzo.core import pyzoLogging # noqa - to start logging asap
from pyzo.core.main import MainWindow

# Apply users' preferences w.r.t. date representation etc
Expand All @@ -261,7 +261,7 @@ def start():
appLocale = setLanguage(config.settings.language)

# Create main window, using the selected locale
frame = MainWindow(None, appLocale)
MainWindow(None, appLocale)

# Enter the main loop
QtWidgets.qApp.exec_()
Expand Down
2 changes: 1 addition & 1 deletion pyzo/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

# Imports that are maybe not used in Pyzo, but are/can be in the tools.
# Import them now, so they are available in the frozen app.
import shutil
import shutil # noqa


if hasattr(sys, 'frozen') and sys.frozen:
Expand Down
1 change: 1 addition & 0 deletions pyzo/codeeditor/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
# flake8: noqa
# Copyright (C) 2013, the codeeditor development team
#
# Pyzo is distributed under the terms of the (new) BSD License.
Expand Down
2 changes: 1 addition & 1 deletion pyzo/codeeditor/_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

os.chdir('..')
sys.path.insert(0,'.')
from codeeditor import *
from codeeditor import CodeEditor



Expand Down
10 changes: 4 additions & 6 deletions pyzo/codeeditor/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,14 @@ def __init__(self, *args, extensionParam1 = 1, extensionParam2 = 3, **kwds):
"""

import sys
from .qt import QtGui,QtCore, QtWidgets
Qt = QtCore.Qt

from .misc import DEFAULT_OPTION_NAME, DEFAULT_OPTION_NONE, ce_option
from .misc import callLater, ustr
from .manager import Manager
from .highlighter import Highlighter
from .style import StyleFormat, StyleElementDescription
from .style import StyleElementDescription


class CodeEditorBase(QtWidgets.QPlainTextEdit):
Expand Down Expand Up @@ -184,22 +183,21 @@ def __init__(self,*args, **kwds):
base3 = "#fdf6e3"
yellow = "#b58900"
orange = "#cb4b16"
red = "#dc322f"
red = "#dc322f" # noqa
magenta = "#d33682"
violet = "#6c71c4"
blue = "#268bd2"
cyan = "#2aa198"
green = "#859900"
green = "#859900" # noqa

if True: # Light vs dark
#back1, back2, back3 = base3, base2, base1 # real solarised
back1, back2, back3 = "#fff", base2, base1 # crispier
fore1, fore2, fore3, fore4 = base00, base01, base02, base03
else:
back1, back2, back3 = base03, base02, base01
fore1, fore2, fore3, fore4 = base0, base1, base2, base3
fore1, fore2, fore3, fore4 = base0, base1, base2, base3 # noqa

test_numbers = 90 + 0000 + 1
# todo: proper testing of syntax style

# Define style using "Solarized" colors
Expand Down
23 changes: 5 additions & 18 deletions pyzo/codeeditor/extensions/appearance.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ def _findMatchingBracket(self, char, cursor):
else:
raise ValueError('invalid bracket character: ' + char)

other_char = self._matchingBrackets[char]
stacked_paren = [(char, cursor.position())] # using a Python list as a stack
# stack not empty because the _ParenIterator will not give back
# the parenthesis we're matching
Expand Down Expand Up @@ -363,8 +362,9 @@ def paintEvent(self, event):
self._highlightSingleChar(painter, self._cursorAt(doc, match_res.offending), width, 'editor.highlightMisMatchingBracket')

painter.end()
except _ParenNotFound : # is raised when current parenthesis is not
#found in its line token list, meaning it is in a string literal
except _ParenNotFound:
# is raised when current parenthesis is not
# found in its line token list, meaning it is in a string literal
pass

super(HighlightMatchingBracket, self).paintEvent(event)
Expand Down Expand Up @@ -571,9 +571,7 @@ def paintEvent(self,event):
painter.begin(self.viewport())

margin = self.document().documentMargin()
w = self.viewport().width()



def paintCodeFolders(cursor):
y = self.cursorRect(cursor).top()
h = self.cursorRect(cursor).height()
Expand Down Expand Up @@ -778,7 +776,6 @@ def paintEvent(self, event):
return

# Get doc and viewport
doc = editor.document()
viewport = editor.viewport()

# Get format and margin
Expand Down Expand Up @@ -990,7 +987,6 @@ def mousePressEvent(self, event):
def mouseMoveEvent(self, event):
y = self._getY(event.pos())
editor = self.parent()
cursor = editor.textCursor()
c1 = editor.cursorForPosition(QtCore.QPoint(0,y))
self._virtualBreakpoint = c1.blockNumber() + 1
self.update()
Expand All @@ -1002,22 +998,17 @@ def leaveEvent(self, event):
def _toggleBreakPoint(self, y):
# Get breakpoint corresponding to pressed pos
editor = self.parent()
cursor = editor.textCursor()
c1 = editor.cursorForPosition(QtCore.QPoint(0,y))
linenr = c1.blockNumber() + 1
# Toggle
bps = self.parent().toggleBreakpoint(linenr)
self.parent().toggleBreakpoint(linenr)

def paintEvent(self, event):
editor = self.parent()

if not editor.showBreakPoints():
return

# Get doc and viewport
doc = editor.document()
viewport = editor.viewport()

# Get format and margin
format = editor.getStyleElementFormat('editor.breakpoints')
margin = 1
Expand All @@ -1031,10 +1022,6 @@ def paintEvent(self, event):
# Get which part to paint. Just do all to avoid glitches
y1, y2 = 0, editor.height()

# Get offset
tmp = self.mapToGlobal(QtCore.QPoint(0,0))
offset = viewport.mapFromGlobal(tmp).y()

#Draw the background
painter.fillRect(QtCore.QRect(0, y1, w, y2), format.back)

Expand Down
2 changes: 1 addition & 1 deletion pyzo/codeeditor/extensions/autocompletion.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def completionIndex(data):

# apply the best match
bestMatchRow = completions[0][0]
self.__completer.popup().setCurrentIndex(model.index(bestMatchRow,0));
self.__completer.popup().setCurrentIndex(model.index(bestMatchRow,0))

return True

Expand Down
2 changes: 1 addition & 1 deletion pyzo/codeeditor/extensions/calltip.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Pyzo is distributed under the terms of the (new) BSD License.
# The full license can be found in 'license.txt'.

from ..qt import QtCore, QtGui, QtWidgets
from ..qt import QtCore, QtGui, QtWidgets # noqa
Qt = QtCore.Qt

class Calltip(object):
Expand Down
2 changes: 0 additions & 2 deletions pyzo/codeeditor/highlighter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
"""

import time

from .qt import QtGui, QtCore
Qt = QtCore.Qt

Expand Down
2 changes: 1 addition & 1 deletion pyzo/codeeditor/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import os, sys

from .qt import QtGui, QtCore, QtWidgets
from .qt import QtGui, QtCore, QtWidgets # noqa
Qt = QtCore.Qt

from . import parsers
Expand Down
4 changes: 2 additions & 2 deletions pyzo/codeeditor/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
"""

import sys
from .qt import QtGui, QtCore, QtWidgets
from .qt import QtGui, QtCore, QtWidgets # noqa


# Set Python version and get some names
PYTHON_VERSION = sys.version_info[0]
if PYTHON_VERSION < 3:
ustr = unicode
ustr = unicode # noqa
bstr = str
from Queue import Queue, Empty
else:
Expand Down
17 changes: 8 additions & 9 deletions pyzo/codeeditor/parsers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,14 @@
"""

# Normal imports
import os, sys
#import zipfile
import sys

from . import tokens

if sys.version_info[0] >= 3:
text_type = str
else:
text_type = unicode
text_type = unicode # noqa


class BlockState(object):
Expand Down Expand Up @@ -141,7 +140,7 @@ def getStyleElementDescriptions(cls):
"""
descriptions = {}
for token in self.getUsedTokens():
for token in cls.getUsedTokens(cls):
descriptions[token.description.key] = token.description

return list(descriptions.values())
Expand Down Expand Up @@ -198,8 +197,8 @@ def _isTodoItem(self, text):
#
# In summary: it takes a lot of trouble, which can be avoided by just
# listing all parsers here.
from . import ( python_parser,
cython_parser,
c_parser,
)
from . import ( python_parser, # noqa
cython_parser, # noqa
c_parser, # noqa
)

4 changes: 2 additions & 2 deletions pyzo/codeeditor/parsers/c_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# The full license can be found in 'license.txt'.

import re
from . import tokens, Parser, BlockState, text_type
from . import Parser, BlockState, text_type
from .tokens import ALPHANUM

from .tokens import (Token, CommentToken, StringToken,
Expand Down Expand Up @@ -186,7 +186,7 @@ def _findNextToken(self, line, pos):
if identifier in self._keywords:
tokens.append( KeywordToken(*tokenArgs) )
elif identifier[0] in '0123456789':
identifierState = 0
# identifierState = 0
tokens.append( NumberToken(*tokenArgs) )
else:
tokens.append( IdentifierToken(*tokenArgs) )
Expand Down
15 changes: 1 addition & 14 deletions pyzo/codeeditor/parsers/cython_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,8 @@
# Pyzo is distributed under the terms of the (new) BSD License.
# The full license can be found in 'license.txt'.

import re
from . import tokens, Parser, BlockState
from .tokens import ALPHANUM


# Import tokens in module namespace
from .tokens import (CommentToken, StringToken,
UnterminatedStringToken, IdentifierToken, NonIdentifierToken,
KeywordToken, NumberToken, FunctionNameToken, ClassNameToken,
TodoCommentToken)

from .python_parser import ( PythonParser,
MultilineStringToken,
CellCommentToken,
pythonKeywords)
from .python_parser import PythonParser, pythonKeywords

# Set keywords
cythonExtraKeywords = set(['cdef', 'cpdef', 'ctypedef', 'cimport',
Expand Down
Loading

0 comments on commit 79f98a9

Please sign in to comment.