Skip to content

Commit

Permalink
updated kivy pep8 and corrected some files
Browse files Browse the repository at this point in the history
  • Loading branch information
andrzej.grymkowski committed May 13, 2015
1 parent 79df729 commit 44ea7c7
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ html:
$(MAKE) -C docs html

style:
$(PYTHON) $(CHECKSCRIPT) $(PLYER_DIR)
$(PYTHON) $(CHECKSCRIPT) .

stylereport:
$(PYTHON) $(CHECKSCRIPT) -html $(PLYER_DIR)
Expand Down
53 changes: 39 additions & 14 deletions plyer/platforms/linux/filechooser.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def _run_command(self, cmd):
self._process = sp.Popen(cmd, stdout=sp.PIPE)
while True:
ret = self._process.poll()
if ret != None:
if ret is not None:
if ret == self.successretcode:
out = self._process.communicate()[0].strip()
self.selection = self._split_output(out)
Expand Down Expand Up @@ -88,7 +88,8 @@ class ZenityFileChooser(SubprocessFileChooser):
successretcode = 0

def _gen_cmdline(self):
cmdline = [which(self.executable), "--file-selection", "--confirm-overwrite"]
cmdline = [which(self.executable),
"--file-selection", "--confirm-overwrite"]
if self.multiple:
cmdline += ["--multiple"]
if self.mode == "save":
Expand All @@ -98,16 +99,20 @@ def _gen_cmdline(self):
if self.path:
cmdline += ["--filename", self.path]
if self.title:
cmdline += ["--name", self.title]
cmdline += ["--name", self.title]
if self.icon:
cmdline += ["--window-icon", self.icon]
for f in self.filters:
if type(f) == str:
cmdline += ["--file-filter", f]
else:
cmdline += ["--file-filter", "{name} | {flt}".format(name=f[0], flt=" ".join(f[1:]))]
cmdline += [
"--file-filter",
"{name} | {flt}".format(name=f[0], flt=" ".join(f[1:]))
]
return cmdline


class KDialogFileChooser(SubprocessFileChooser):
"""A FileChooser implementation using KDialog (on GNU/Linux).
Expand All @@ -132,11 +137,22 @@ def _gen_cmdline(self):
filt += list(f[1:])

if self.mode == "dir":
cmdline += ["--getexistingdirectory", (self.path if self.path else os.path.expanduser("~"))]
cmdline += [
"--getexistingdirectory",
(self.path if self.path else os.path.expanduser("~"))
]
elif self.mode == "save":
cmdline += ["--getopenfilename", (self.path if self.path else os.path.expanduser("~")), " ".join(filt)]
cmdline += [
"--getopenfilename",
(self.path if self.path else os.path.expanduser("~")),
" ".join(filt)
]
else:
cmdline += ["--getopenfilename", (self.path if self.path else os.path.expanduser("~")), " ".join(filt)]
cmdline += [
"--getopenfilename",
(self.path if self.path else os.path.expanduser("~")),
" ".join(filt)
]
if self.multiple:
cmdline += ["--multiple", "--separate-output"]
if self.title:
Expand All @@ -145,6 +161,7 @@ def _gen_cmdline(self):
cmdline += ["--icon", self.icon]
return cmdline


class YADFileChooser(SubprocessFileChooser):
"""A NativeFileChooser implementation using YAD (on GNU/Linux).
Expand All @@ -157,7 +174,8 @@ class YADFileChooser(SubprocessFileChooser):
successretcode = 0

def _gen_cmdline(self):
cmdline = [which(self.executable), "--file-selection", "--confirm-overwrite", "--geometry", "800x600+150+150"]
cmdline = [which(self.executable), "--file-selection",
"--confirm-overwrite", "--geometry", "800x600+150+150"]
if self.multiple:
cmdline += ["--multiple", "--separator", self.separator]
if self.mode == "save":
Expand All @@ -169,19 +187,25 @@ def _gen_cmdline(self):
if self.path:
cmdline += ["--filename", self.path]
if self.title:
cmdline += ["--name", self.title]
cmdline += ["--name", self.title]
if self.icon:
cmdline += ["--window-icon", self.icon]
for f in self.filters:
if type(f) == str:
cmdline += ["--file-filter", f]
else:
cmdline += ["--file-filter", "{name} | {flt}".format(name=f[0], flt=" ".join(f[1:]))]
cmdline += [
"--file-filter",
"{name} | {flt}".format(name=f[0], flt=" ".join(f[1:]))
]
return cmdline

CHOOSERS = {"gnome": ZenityFileChooser,
"kde": KDialogFileChooser,
"yad": YADFileChooser}
CHOOSERS = {
"gnome": ZenityFileChooser,
"kde": KDialogFileChooser,
"yad": YADFileChooser
}


class LinuxFileChooser(FileChooser):
"""FileChooser implementation for GNu/Linux. Accepts one additional
Expand All @@ -193,7 +217,8 @@ class LinuxFileChooser(FileChooser):
"""

desktop = None
if str(os.environ.get("XDG_CURRENT_DESKTOP")).lower() == "kde" and which("kdialog"):
if str(os.environ.get("XDG_CURRENT_DESKTOP")).lower() == "kde" \
and which("kdialog"):
desktop = "kde"
elif which("yad"):
desktop = "yad"
Expand Down
2 changes: 1 addition & 1 deletion plyer/platforms/win/filechooser.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def run(self):
args = {}

if self.path:
atgs["InitialDir"] = os.path.dirname(self.path)
args["InitialDir"] = os.path.dirname(self.path)
args["File"] = os.path.splitext(os.path.dirname(self.path))[0]
args["DefExt"] = os.path.splitext(os.path.dirname(self.path))[1]
args["Title"] = self.title if self.title else "Pick a file..."
Expand Down
29 changes: 27 additions & 2 deletions plyer/tools/pep8checker/pep8.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ def blank_lines(logical_line, blank_lines, indent_level, line_number)
from fnmatch import fnmatch
try:
from ConfigParser import RawConfigParser
from io import TextIOWrapper
except ImportError:
from configparser import RawConfigParser
from io import TextIOWrapper

DEFAULT_EXCLUDE = '.svn,CVS,.bzr,.hg,.git'
DEFAULT_IGNORE = 'E24'
Expand Down Expand Up @@ -1328,6 +1328,26 @@ def check_all(self, expected=None, line_offset=0):
pos = 'l.%s' % token[3][0]
print(('l.%s\t%s\t%s\t%r' %
(token[2][0], pos, tokenize.tok_name[token[0]], text)))
if token_type == tokenize.COMMENT or token_type == tokenize.STRING:
for sre in re.finditer(r"[:.;,] ?[A-Za-z]", text):
pos = sre.span()[0]
part = text[:pos]
line = token[2][0] + part.count('\n')
offset = 0 if part.count('\n') > 0 else token[2][1]
col = offset + pos - part.rfind('\n') + 1
if sre.group(0)[0] == '.':
self.report_error(line, col,
'E289 Too many spaces after period. Use only one.',
check=None)
elif sre.group(0)[0] == ',':
self.report_error(line, col,
'E288 Too many spaces after comma. Use only one.',
check=None)
else:
self.report_error(line, col,
'E287 Too many spaces after punctuation. '
'Use only one.',
check=None)
if token_type == tokenize.OP:
if text in '([{':
parens += 1
Expand All @@ -1352,6 +1372,11 @@ def check_all(self, expected=None, line_offset=0):
if COMMENT_WITH_NL:
# The comment also ends a physical line
self.tokens = []
if self.blank_lines > 1:
self.report_error(token[2][0],0,
'E389 File ends in multiple blank lines',
check=None)

return self.report.get_file_results()


Expand Down Expand Up @@ -1479,7 +1504,7 @@ def error(self, line_number, offset, text, check):
line = self.lines[line_number - 1]
print((line.rstrip()))
print((' ' * offset + '^'))
if self._show_pep8:
if self._show_pep8 and check is not None:
print((check.__doc__.lstrip('\n').rstrip()))
return code

Expand Down
7 changes: 5 additions & 2 deletions plyer/tools/pep8checker/pep8kivy.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ def check(fn):
return checker.check_all()

errors = 0
exclude_dirs = ['/pep8', '/doc']
exclude_files = []
exclude_dirs = ['/lib', '/coverage', '/pep8', '/doc']
exclude_files = ['kivy/gesture.py', 'osx/build.py', 'win32/build.py',
'kivy/tools/stub-gl-debug.py',
'kivy/modules/webdebugger.py',
'kivy/modules/_webdebugger.py']
for target in targets:
if isdir(target):
if htmlmode:
Expand Down

0 comments on commit 44ea7c7

Please sign in to comment.