diff --git a/platformio/__main__.py b/platformio/__main__.py index 72502afa8d..3dd8324407 100644 --- a/platformio/__main__.py +++ b/platformio/__main__.py @@ -37,16 +37,16 @@ def list_commands(self, ctx): cmds.sort() return cmds - def get_command(self, ctx, name): + def get_command(self, ctx, cmd_name): mod = None try: - mod = __import__("platformio.commands." + name, None, None, + mod = __import__("platformio.commands." + cmd_name, None, None, ["cli"]) except ImportError: try: - return self._handle_obsolate_command(name) + return self._handle_obsolate_command(cmd_name) except AttributeError: - raise click.UsageError('No such command "%s"' % name, ctx) + raise click.UsageError('No such command "%s"' % cmd_name, ctx) return mod.cli @staticmethod diff --git a/platformio/app.py b/platformio/app.py index e6cbc0b21f..79fa9c0184 100644 --- a/platformio/app.py +++ b/platformio/app.py @@ -156,7 +156,7 @@ def __enter__(self): found = True if isfile(path): remove(path) - if not len(listdir(dirname(path))): + if not listdir(dirname(path)): util.rmtree_(dirname(path)) if found and self._lock_dbindex(): @@ -228,7 +228,7 @@ def set(self, key, data, valid): if not isdir(dirname(cache_path)): os.makedirs(dirname(cache_path)) with open(cache_path, "wb") as fp: - if isinstance(data, dict) or isinstance(data, list): + if isinstance(data, (dict, list)): json.dump(data, fp) else: fp.write(str(data)) diff --git a/platformio/builder/tools/piomisc.py b/platformio/builder/tools/piomisc.py index 6dc3296ae0..ba6f496e73 100644 --- a/platformio/builder/tools/piomisc.py +++ b/platformio/builder/tools/piomisc.py @@ -252,8 +252,7 @@ def _lookup_in_ldpath(script): def VerboseAction(_, act, actstr): if int(ARGUMENTS.get("PIOVERBOSE", 0)): return act - else: - return Action(act, actstr) + return Action(act, actstr) def PioClean(env, clean_dir): diff --git a/platformio/builder/tools/platformio.py b/platformio/builder/tools/platformio.py index fe67fb651b..8b09e24841 100644 --- a/platformio/builder/tools/platformio.py +++ b/platformio/builder/tools/platformio.py @@ -186,7 +186,7 @@ def _append_build_item(items, item, src_dir): src_dir = env.subst(src_dir) src_filter = src_filter or SRC_FILTER_DEFAULT - if isinstance(src_filter, list) or isinstance(src_filter, tuple): + if isinstance(src_filter, (list, tuple)): src_filter = " ".join(src_filter) matches = set() diff --git a/platformio/commands/lib.py b/platformio/commands/lib.py index 068c96b501..4598415763 100644 --- a/platformio/commands/lib.py +++ b/platformio/commands/lib.py @@ -295,14 +295,14 @@ def lib_builtin(storage, json_output): if json_output: return click.echo(json.dumps(items)) - for storage in items: - if not storage['items']: + for storage_ in items: + if not storage_['items']: continue - click.secho(storage['name'], fg="green") - click.echo("*" * len(storage['name'])) + click.secho(storage_['name'], fg="green") + click.echo("*" * len(storage_['name'])) click.echo() - for item in sorted(storage['items'], key=lambda i: i['name']): + for item in sorted(storage_['items'], key=lambda i: i['name']): print_lib_item(item) diff --git a/platformio/exception.py b/platformio/exception.py index 0f0530b6ed..346156c736 100644 --- a/platformio/exception.py +++ b/platformio/exception.py @@ -20,8 +20,7 @@ class PlatformioException(Exception): def __str__(self): # pragma: no cover if self.MESSAGE: return self.MESSAGE.format(*self.args) - else: - return Exception.__str__(self) + return Exception.__str__(self) class ReturnErrorCode(PlatformioException): diff --git a/platformio/managers/package.py b/platformio/managers/package.py index 6adb753e6c..efae480338 100644 --- a/platformio/managers/package.py +++ b/platformio/managers/package.py @@ -69,8 +69,7 @@ def next(self): if self.package in manifest: return manifest[self.package] - else: - return self.next() + return self.next() class PkgRepoMixin(object): diff --git a/platformio/managers/platform.py b/platformio/managers/platform.py index 99a38d86b3..ccd89b157a 100644 --- a/platformio/managers/platform.py +++ b/platformio/managers/platform.py @@ -63,7 +63,7 @@ def install(self, skip_default_package=False, trigger_event=True, silent=False, - **_): # pylint: disable=too-many-arguments + **_): # pylint: disable=too-many-arguments, arguments-differ platform_dir = BasePkgManager.install( self, name, requirements, silent=silent) p = PlatformFactory.newPlatform(platform_dir) @@ -305,9 +305,7 @@ def get_package_dir(self, name): version = self.packages[name].get("version", "") if self.is_valid_requirements(version): return self.pm.get_package_dir(name, version) - else: - return self.pm.get_package_dir(*self._parse_pkg_input(name, - version)) + return self.pm.get_package_dir(*self._parse_pkg_input(name, version)) def get_package_version(self, name): pkg_dir = self.get_package_dir(name) diff --git a/platformio/util.py b/platformio/util.py index 4d34583025..2f260bb53a 100644 --- a/platformio/util.py +++ b/platformio/util.py @@ -46,7 +46,7 @@ class ProjectConfig(ConfigParser): VARTPL_RE = re.compile(r"\$\{([^\.\}]+)\.([^\}]+)\}") - def items(self, section, **_): + def items(self, section, **_): # pylint: disable=arguments-differ items = [] for option in ConfigParser.options(self, section): items.append((option, self.get(section, option))) @@ -130,10 +130,9 @@ def __call__(self, *args): return self.func(*args) if args in self.cache: return self.cache[args] - else: - value = self.func(*args) - self.cache[args] = value - return value + value = self.func(*args) + self.cache[args] = value + return value def __repr__(self): '''Return the function's docstring.''' diff --git a/tox.ini b/tox.ini index 0c09accef3..406d179c24 100644 --- a/tox.ini +++ b/tox.ini @@ -21,10 +21,9 @@ usedevelop = True deps = isort flake8 - yapf + yapf<0.16 pylint pytest - show commands = python --version [testenv:docs]