Refactor PyLint "inconsistent-return-statements"

This commit is contained in:
Ivan Kravets
2017-12-15 22:16:37 +02:00
parent bff590e207
commit 42fb589369
14 changed files with 48 additions and 24 deletions

View File

@ -198,12 +198,12 @@ class ContentCache(object):
def set(self, key, data, valid): def set(self, key, data, valid):
if not get_setting("enable_cache"): if not get_setting("enable_cache"):
return return False
cache_path = self.get_cache_path(key) cache_path = self.get_cache_path(key)
if isfile(cache_path): if isfile(cache_path):
self.delete(key) self.delete(key)
if not data: if not data:
return return False
if not isdir(self.cache_dir): if not isdir(self.cache_dir):
os.makedirs(self.cache_dir) os.makedirs(self.cache_dir)
tdmap = {"s": 1, "m": 60, "h": 3600, "d": 86400} tdmap = {"s": 1, "m": 60, "h": 3600, "d": 86400}
@ -228,7 +228,7 @@ class ContentCache(object):
def delete(self, keys=None): def delete(self, keys=None):
""" Keys=None, delete expired items """ """ Keys=None, delete expired items """
if not isfile(self._db_path): if not isfile(self._db_path):
return return None
if not keys: if not keys:
keys = [] keys = []
if not isinstance(keys, list): if not isinstance(keys, list):

View File

@ -693,7 +693,7 @@ def GetLibBuilders(env): # pylint: disable=too-many-branches
if lb.name in env.get("LIB_IGNORE", []): if lb.name in env.get("LIB_IGNORE", []):
if verbose: if verbose:
sys.stderr.write("Ignored library %s\n" % lb.path) sys.stderr.write("Ignored library %s\n" % lb.path)
return return None
if compat_mode > 1 and not lb.is_platforms_compatible( if compat_mode > 1 and not lb.is_platforms_compatible(
env['PIOPLATFORM']): env['PIOPLATFORM']):
if verbose: if verbose:

View File

@ -50,7 +50,7 @@ class InoToCPPConverter(object):
def convert(self, nodes): def convert(self, nodes):
contents = self.merge(nodes) contents = self.merge(nodes)
if not contents: if not contents:
return return None
return self.process(contents) return self.process(contents)
def merge(self, nodes): def merge(self, nodes):

View File

@ -72,7 +72,7 @@ def exists(_):
def generate(env): def generate(env):
if system() != "Windows": if system() != "Windows":
return return None
env.Replace(_long_sources_hook=long_sources_hook) env.Replace(_long_sources_hook=long_sources_hook)
env.Replace(_long_incflags_hook=long_incflags_hook) env.Replace(_long_incflags_hook=long_incflags_hook)

View File

@ -42,6 +42,7 @@ def cli(query, installed, json_output): # pylint: disable=R0912
click.secho(platform, bold=True) click.secho(platform, bold=True)
click.echo("-" * terminal_width) click.echo("-" * terminal_width)
print_boards(boards) print_boards(boards)
return True
def print_boards(boards): def print_boards(boards):

View File

@ -30,10 +30,8 @@ def cli():
@cli.command("list", short_help="List devices") @cli.command("list", short_help="List devices")
@click.option("--json-output", is_flag=True) @click.option("--json-output", is_flag=True)
def device_list(json_output): def device_list(json_output):
if json_output: if json_output:
click.echo(json.dumps(util.get_serialports())) return click.echo(json.dumps(util.get_serialports()))
return
for item in util.get_serialports(): for item in util.get_serialports():
click.secho(item['port'], fg="cyan") click.secho(item['port'], fg="cyan")
@ -42,6 +40,8 @@ def device_list(json_output):
click.echo("Description: %s" % item['description']) click.echo("Description: %s" % item['description'])
click.echo("") click.echo("")
return True
@cli.command("monitor", short_help="Monitor device (Serial)") @cli.command("monitor", short_help="Monitor device (Serial)")
@click.option("--port", "-p", help="Port, a number or a device name") @click.option("--port", "-p", help="Port, a number or a device name")
@ -154,7 +154,7 @@ def device_monitor(**kwargs): # pylint: disable=too-many-branches
def get_project_options(project_dir, environment): def get_project_options(project_dir, environment):
config = util.load_project_config(project_dir) config = util.load_project_config(project_dir)
if not config.sections(): if not config.sections():
return return None
known_envs = [s[4:] for s in config.sections() if s.startswith("env:")] known_envs = [s[4:] for s in config.sections() if s.startswith("env:")]
if environment: if environment:
@ -163,7 +163,7 @@ def get_project_options(project_dir, environment):
raise exception.UnknownEnvNames(environment, ", ".join(known_envs)) raise exception.UnknownEnvNames(environment, ", ".join(known_envs))
if not known_envs: if not known_envs:
return return None
if config.has_option("platformio", "env_default"): if config.has_option("platformio", "env_default"):
env_default = config.get("platformio", env_default = config.get("platformio",

View File

@ -143,6 +143,8 @@ def lib_update(lm, libraries, only_check, json_output):
for library in libraries: for library in libraries:
lm.update(library, only_check=only_check) lm.update(library, only_check=only_check)
return True
def print_lib_item(item): def print_lib_item(item):
click.secho(item['name'], fg="cyan") click.secho(item['name'], fg="cyan")
@ -265,11 +267,13 @@ def lib_list(lm, json_output):
return click.echo(json.dumps(items)) return click.echo(json.dumps(items))
if not items: if not items:
return return None
for item in sorted(items, key=lambda i: i['name']): for item in sorted(items, key=lambda i: i['name']):
print_lib_item(item) print_lib_item(item)
return True
@util.memoized @util.memoized
def get_builtin_libs(storage_names=None): def get_builtin_libs(storage_names=None):
@ -308,6 +312,8 @@ def lib_builtin(storage, json_output):
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) print_lib_item(item)
return True
@cli.command("show", short_help="Show detailed info about a library") @cli.command("show", short_help="Show detailed info about a library")
@click.argument("library", metavar="[LIBRARY]") @click.argument("library", metavar="[LIBRARY]")
@ -381,6 +387,8 @@ def lib_show(library, json_output):
for row in rows: for row in rows:
click.echo(row) click.echo(row)
return True
@cli.command("register", short_help="Register a new library") @cli.command("register", short_help="Register a new library")
@click.argument("config_url") @click.argument("config_url")
@ -468,3 +476,5 @@ def lib_stats(json_output):
for item in result.get(key, []): for item in result.get(key, []):
_print_lib_item(item) _print_lib_item(item)
click.echo() click.echo()
return True

View File

@ -257,7 +257,7 @@ def platform_show(platform, json_output): # pylint: disable=too-many-branches
click.echo("Frameworks: %s" % ", ".join(data['frameworks'])) click.echo("Frameworks: %s" % ", ".join(data['frameworks']))
if not data['packages']: if not data['packages']:
return return None
if not isinstance(data['packages'][0], dict): if not isinstance(data['packages'][0], dict):
click.echo("Packages: %s" % ", ".join(data['packages'])) click.echo("Packages: %s" % ", ".join(data['packages']))
@ -287,6 +287,8 @@ def platform_show(platform, json_output): # pylint: disable=too-many-branches
click.echo("------") click.echo("------")
print_boards(data['boards']) print_boards(data['boards'])
return True
@cli.command("install", short_help="Install new development platform") @cli.command("install", short_help="Install new development platform")
@click.argument("platforms", nargs=-1, required=True, metavar="[PLATFORM...]") @click.argument("platforms", nargs=-1, required=True, metavar="[PLATFORM...]")
@ -375,3 +377,5 @@ def platform_update(platforms, only_packages, only_check, json_output):
pm.update( pm.update(
platform, only_packages=only_packages, only_check=only_check) platform, only_packages=only_packages, only_check=only_check)
click.echo() click.echo()
return True

View File

@ -93,6 +93,8 @@ WARNING! Don't use `sudo` for the rest PlatformIO commands.
raise exception.UpgradeError("\n".join( raise exception.UpgradeError("\n".join(
[str(cmd), r['out'], r['err']])) [str(cmd), r['out'], r['err']]))
return True
def get_latest_version(): def get_latest_version():
try: try:

View File

@ -42,7 +42,12 @@ class CorePackageManager(PackageManager):
("" if sys.version_info < (2, 7, 9) else "s") ("" if sys.version_info < (2, 7, 9) else "s")
]) ])
def install(self, name, requirements=None, *args, **kwargs): def install( # pylint: disable=keyword-arg-before-vararg
self,
name,
requirements=None,
*args,
**kwargs):
PackageManager.install(self, name, requirements, *args, **kwargs) PackageManager.install(self, name, requirements, *args, **kwargs)
self.cleanup_packages() self.cleanup_packages()
return self.get_package_dir(name, requirements) return self.get_package_dir(name, requirements)
@ -126,3 +131,5 @@ def pioplus_call(args, **kwargs):
if code != 0: if code != 0:
raise exception.ReturnErrorCode(1) raise exception.ReturnErrorCode(1)
return True

View File

@ -256,10 +256,10 @@ class LibraryManager(BasePkgManager):
except exception.InternetIsOffline as e: except exception.InternetIsOffline as e:
if not silent: if not silent:
click.secho(str(e), fg="yellow") click.secho(str(e), fg="yellow")
return return None
if not pkg_dir: if not pkg_dir:
return return None
manifest = self.load_manifest(pkg_dir) manifest = self.load_manifest(pkg_dir)
if "dependencies" not in manifest: if "dependencies" not in manifest:

View File

@ -384,7 +384,7 @@ class PkgInstallerMixin(object):
finally: finally:
if isdir(tmp_dir): if isdir(tmp_dir):
util.rmtree_(tmp_dir) util.rmtree_(tmp_dir)
return return None
def _update_src_manifest(self, data, src_dir): def _update_src_manifest(self, data, src_dir):
if not isdir(src_dir): if not isdir(src_dir):
@ -603,18 +603,17 @@ class BasePkgManager(PkgRepoMixin, PkgInstallerMixin):
requirements=None, requirements=None,
silent=False, silent=False,
trigger_event=True): trigger_event=True):
name, requirements, url = self.parse_pkg_uri(name, requirements)
package_dir = self.get_package_dir(name, requirements, url)
# avoid circle dependencies # avoid circle dependencies
if not self.INSTALL_HISTORY: if not self.INSTALL_HISTORY:
self.INSTALL_HISTORY = [] self.INSTALL_HISTORY = []
history_key = "%s-%s" % (name, requirements) if requirements else name history_key = "%s-%s" % (name, requirements) if requirements else name
if history_key in self.INSTALL_HISTORY: if history_key in self.INSTALL_HISTORY:
return return package_dir
self.INSTALL_HISTORY.append(history_key) self.INSTALL_HISTORY.append(history_key)
name, requirements, url = self.parse_pkg_uri(name, requirements)
package_dir = self.get_package_dir(name, requirements, url)
if not package_dir or not silent: if not package_dir or not silent:
msg = "Installing " + click.style(name, fg="cyan") msg = "Installing " + click.style(name, fg="cyan")
if requirements: if requirements:
@ -714,7 +713,7 @@ class BasePkgManager(PkgRepoMixin, PkgInstallerMixin):
nl=False) nl=False)
if not util.internet_on(): if not util.internet_on():
click.echo("[%s]" % (click.style("Off-line", fg="yellow"))) click.echo("[%s]" % (click.style("Off-line", fg="yellow")))
return return None
latest = self.outdated(pkg_dir, requirements) latest = self.outdated(pkg_dir, requirements)
if latest: if latest:
@ -725,7 +724,7 @@ class BasePkgManager(PkgRepoMixin, PkgInstallerMixin):
click.echo("[%s]" % (click.style("Fixed", fg="yellow"))) click.echo("[%s]" % (click.style("Fixed", fg="yellow")))
if only_check or not latest: if only_check or not latest:
return return True
if "__src_url" in manifest: if "__src_url" in manifest:
vcs = VCSClientFactory.newClient(pkg_dir, manifest['__src_url']) vcs = VCSClientFactory.newClient(pkg_dir, manifest['__src_url'])

View File

@ -672,7 +672,7 @@ class PlatformBoardConfig(object):
def get_debug_data(self): def get_debug_data(self):
if not self._manifest.get("debug", {}).get("tools"): if not self._manifest.get("debug", {}).get("tools"):
return return None
tools = {} tools = {}
for name, options in self._manifest['debug']['tools'].items(): for name, options in self._manifest['debug']['tools'].items():
tools[name] = {} tools[name] = {}

View File

@ -407,3 +407,4 @@ def resend_backuped_reports():
# clean # clean
tm['backup'] = [] tm['backup'] = []
app.set_state_item("telemetry", tm) app.set_state_item("telemetry", tm)
return True