Fix PyLint: Consider explicitly re-raising

This commit is contained in:
Ivan Kravets committed 2022-07-02 18:37:57 +03:00
1 parent f01cd7570c
commit 19d518fc4c
45 files changed
+136 -138

No files matched your search

+1 -1
View File
@@ -67,7 +67,7 @@ def package_exec_cmd(obj, package, call, args):
if force_click_stream:
click.echo(result.stdout.decode().strip(), err=result.returncode != 0)
except Exception as exc:
raise UserSideException(exc)
raise UserSideException(exc) from exc
if result and result.returncode != 0:
raise ReturnErrorCode(result.returncode)
+2 -2
View File
@@ -39,7 +39,7 @@ def package_pack_cmd(package, output):
ManifestSchema().load_manifest(
ManifestParserFactory.new_from_archive(archive_path).as_dict()
)
except ManifestValidationError as e:
except ManifestValidationError as exc:
os.remove(archive_path)
raise e
raise exc
click.secho('Wrote a tarball to "%s"' % archive_path, fg="green")
+2 -2
View File
@@ -36,8 +36,8 @@ def validate_datetime(ctx, param, value): # pylint: disable=unused-argument
return value
try:
datetime.strptime(value, "%Y-%m-%d %H:%M:%S")
except ValueError as e:
raise click.BadParameter(e)
except ValueError as exc:
raise click.BadParameter(exc)
return value
+2 -2
View File
@@ -72,10 +72,10 @@ class LockFile(object):
msvcrt.locking( # pylint: disable=used-before-assignment
self._fp.fileno(), msvcrt.LK_NBLCK, 1
)
except (BlockingIOError, IOError):
except (BlockingIOError, IOError) as exc:
self._fp.close()
self._fp = None
raise LockFileExists
raise LockFileExists from exc
return True
def _unlock(self):
+2 -2
View File
@@ -70,7 +70,7 @@ class PackageManagerDownloadMixin(object):
fd = FileDownloader(url)
fd.set_destination(tmp_path)
fd.start(with_progress=with_progress, silent=silent)
except IOError as e:
except IOError as exc:
raise_error = not with_progress
if with_progress:
try:
@@ -86,7 +86,7 @@ class PackageManagerDownloadMixin(object):
fg="red",
)
)
raise e
raise exc
if checksum:
fd.verify(checksum)
os.close(tmp_fd)
+2 -2
View File
@@ -36,9 +36,9 @@ class PackageManagerInstallMixin(object):
try:
with FileUnpacker(src) as fu:
return fu.unpack(dst, with_progress=with_progress)
except IOError as e:
except IOError as exc:
if not with_progress:
raise e
raise exc
with FileUnpacker(src) as fu:
return fu.unpack(dst, with_progress=False)
+2 -2
View File
@@ -56,9 +56,9 @@ class PackageManagerRegistryMixin(object):
),
checksum or pkgfile["checksum"]["sha256"],
)
except Exception as e: # pylint: disable=broad-except
except Exception as exc: # pylint: disable=broad-except
self.log.warning(
click.style("Warning! Package Mirror: %s" % e, fg="yellow")
click.style("Warning! Package Mirror: %s" % exc, fg="yellow")
)
self.log.warning(
click.style("Looking for another mirror...", fg="yellow")
+2 -2
View File
@@ -187,9 +187,9 @@ class BasePackageManager( # pylint: disable=too-many-public-methods,too-many-in
result = ManifestParserFactory.new_from_file(item).as_dict()
self.memcache_set(cache_key, result)
return result
except ManifestException as e:
except ManifestException as exc:
if not PlatformioCLI.in_silence():
self.log.warning(click.style(str(e), fg="yellow"))
self.log.warning(click.style(str(exc), fg="yellow"))
raise MissingPackageManifestError(", ".join(self.manifest_names))
@staticmethod
+1 -1
View File
@@ -156,7 +156,7 @@ def build_contrib_pysite_package(target_dir, with_metadata=True):
raise UserSideException(
"\n\nPlease ensure that the next packages are installed:\n\n"
"sudo apt install python3-dev libffi-dev libssl-dev\n"
)
) from exc
raise exc
# build manifests
+2 -2
View File
@@ -53,9 +53,9 @@ class PlatformPackageManager(BasePackageManager): # pylint: disable=too-many-an
# set logging level for underlying tool manager
p.pm.set_log_level(self.log.getEffectiveLevel())
p.ensure_engine_compatible()
except IncompatiblePlatform as e:
except IncompatiblePlatform as exc:
super().uninstall(pkg, skip_dependencies=True)
raise e
raise exc
if project_env:
p.configure_project_packages(project_env, project_targets)
if not skip_dependencies:
+5 -5
View File
@@ -61,9 +61,9 @@ class ManifestParserFactory(object):
try:
with io.open(path, encoding=encoding) as fp:
return fp.read()
except UnicodeDecodeError as e:
last_err = e
raise last_err # pylint: disable=raising-bad-type
except UnicodeDecodeError as exc:
last_err = exc
raise last_err
@classmethod
def new_from_file(cls, path, remote_url=False):
@@ -145,8 +145,8 @@ class BaseManifestParser(object):
self.package_dir = package_dir
try:
self._data = self.parse(contents)
except Exception as e:
raise ManifestParserError("Could not parse manifest -> %s" % e)
except Exception as exc:
raise ManifestParserError("Could not parse manifest -> %s" % exc) from exc
self._data = self.normalize_repository(self._data)
self._data = self.parse_examples(self._data)
+4 -4
View File
@@ -243,17 +243,17 @@ class ManifestSchema(BaseSchema):
if "Invalid leading zero" in str(exc):
raise exc
semantic_version.Version.coerce(value)
except (AssertionError, ValueError):
except (AssertionError, ValueError) as exc:
raise ValidationError(
"Invalid semantic versioning format, see https://semver.org/"
)
) from exc
@validates("license")
def validate_license(self, value):
try:
spdx = self.load_spdx_licenses()
except requests.exceptions.RequestException:
raise ValidationError("Could not load SPDX licenses for validation")
except requests.exceptions.RequestException as exc:
raise ValidationError("Could not load SPDX licenses for validation") from exc
known_ids = set(item.get("licenseId") for item in spdx.get("licenses", []))
if value in known_ids:
return True
+8 -8
View File
@@ -51,8 +51,8 @@ class VCSClientFactory(object):
)
assert isinstance(obj, VCSClientBase)
return obj
except (KeyError, AssertionError):
raise VCSBaseException("VCS: Unknown repository type %s" % remote_url)
except (KeyError, AssertionError) as exc:
raise VCSBaseException("VCS: Unknown repository type %s" % remote_url) from exc
class VCSClientBase(object):
@@ -73,10 +73,10 @@ class VCSClientBase(object):
self.get_cmd_output(["--version"])
else:
assert self.run_cmd(["--version"])
except (AssertionError, OSError, PlatformioException):
except (AssertionError, OSError, PlatformioException) as exc:
raise UserSideException(
"VCS: `%s` client is not installed in your system" % self.command
)
) from exc
return True
@property
@@ -108,8 +108,8 @@ class VCSClientBase(object):
try:
subprocess.check_call(args, **kwargs)
return True
except subprocess.CalledProcessError as e:
raise VCSBaseException("VCS: Could not process command %s" % e.cmd)
except subprocess.CalledProcessError as exc:
raise VCSBaseException("VCS: Could not process command %s" % exc.cmd) from exc
def get_cmd_output(self, args, **kwargs):
args = [self.command] + args
@@ -152,10 +152,10 @@ class GitClient(VCSClientBase):
def check_client(self):
try:
return VCSClientBase.check_client(self)
except UserSideException:
except UserSideException as exc:
raise UserSideException(
"Please install Git client from https://git-scm.com/downloads"
)
) from exc
def get_branches(self):
output = self.get_cmd_output(["branch"])