From a7eff64294b94cbb029c49cc72eabd0f04fa04a4 Mon Sep 17 00:00:00 2001 From: Tobi-wan Kenobi Date: Sun, 4 Dec 2016 08:02:40 +0100 Subject: [PATCH] [lint] Add tool to run pylint on all files pylint all *.py files and fix the errors reported so far. --- bumblebee/config.py | 37 +++++++++++++++++++++++++------------ runlint.sh | 3 +++ tests/test_config.py | 19 ++++++++++--------- 3 files changed, 38 insertions(+), 21 deletions(-) create mode 100755 runlint.sh diff --git a/bumblebee/config.py b/bumblebee/config.py index 17e679d..58e3ca2 100644 --- a/bumblebee/config.py +++ b/bumblebee/config.py @@ -1,22 +1,35 @@ +"""Configuration handling + +This module provides configuration information (loaded modules, +module parameters, etc.) to all other components +""" + import argparse MODULE_HELP = "" +def create_parser(): + """Create the argument parser""" + parser = argparse.ArgumentParser(description="display system data in the i3bar") + parser.add_argument("-m", "--modules", nargs="+", default=[], + help=MODULE_HELP) + return parser + class Config(object): - def __init__(self, args = []): - parser = self._create_parser() - self._args = parser.parse_args(args) + """Top-level configuration class + + Parses commandline arguments and provides non-module + specific configuration information. + """ + def __init__(self, args=None): + parser = create_parser() + self._args = parser.parse_args(args if args else []) def modules(self): - return list(map(lambda x: { + """Return a list of all activated modules""" + return [{ "module": x.split(":")[0], - "name": x if not ":" in x else x.split(":")[1] - }, self._args.modules)) - - def _create_parser(self): - parser = argparse.ArgumentParser(description="display system data in the i3bar") - parser.add_argument("-m", "--modules", nargs="+", default = [], - help = MODULE_HELP) - return parser + "name": x if not ":" in x else x.split(":")[1], + } for x in self._args.modules] # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/runlint.sh b/runlint.sh new file mode 100755 index 0000000..0d35fb5 --- /dev/null +++ b/runlint.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +find . -name "*.py"|xargs pylint diff --git a/tests/test_config.py b/tests/test_config.py index aa860f6..c87b51a 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -1,3 +1,4 @@ +# pylint: disable=C0103,C0111 import unittest from bumblebee.config import Config @@ -5,24 +6,24 @@ from bumblebee.config import Config class TestConfig(unittest.TestCase): def setUp(self): self.defaultConfig = Config() - self.someSimpleModules = [ "foo", "bar", "baz" ] - self.someAliasModules = [ "foo:a", "bar:b", "baz:c" ] + self.someSimpleModules = ["foo", "bar", "baz"] + self.someAliasModules = ["foo:a", "bar:b", "baz:c"] def test_no_modules_by_default(self): self.assertEquals(self.defaultConfig.modules(), []) def test_load_simple_modules(self): - cfg = Config([ "-m" ] + self.someSimpleModules) - self.assertEquals(cfg.modules(), list(map(lambda x: { + cfg = Config(["-m"] + self.someSimpleModules) + self.assertEquals(cfg.modules(), [{ "name": x, "module": x - }, self.someSimpleModules))) + } for x in self.someSimpleModules]) def test_load_alias_modules(self): - cfg = Config([ "-m" ] + self.someAliasModules) - self.assertEquals(cfg.modules(), list(map(lambda x: { + cfg = Config(["-m"] + self.someAliasModules) + self.assertEquals(cfg.modules(), [{ "module": x.split(":")[0], - "name": x.split(":")[1] - }, self.someAliasModules))) + "name": x.split(":")[1], + } for x in self.someAliasModules]) # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4