Commit bf9e9cf8 by Bjorn Neergaard

refactor: use contextlib.suppress instead of try/except/pass

This reimplements the good changes from #5840.

Co-Authored-By: Kevin Kirsche <kevin.kirsche@one.verizon.com>
parent 7e58d536
from __future__ import annotations
import contextlib
import functools
import glob
import logging
......@@ -556,12 +557,11 @@ def get_pep517_metadata(path: Path) -> PackageInfo:
:param path: Path to package source to build and read metadata for.
"""
info = None
try:
with contextlib.suppress(PackageInfoError):
info = PackageInfo.from_setup_files(path)
if all([info.version, info.name, info.requires_dist]):
return info
except PackageInfoError:
pass
with ephemeral_environment(
flags={"no-pip": False, "no-setuptools": False, "no-wheel": False}
......
from __future__ import annotations
import base64
import contextlib
import hashlib
import itertools
import json
......@@ -279,11 +280,9 @@ class SitePackages:
candidates = self._candidates if not writable_only else self.writable_candidates
if path.is_absolute():
for candidate in candidates:
try:
with contextlib.suppress(ValueError):
path.relative_to(candidate)
return [path]
except ValueError:
pass
site_type = "writable " if writable_only else ""
raise ValueError(
f"{path} is not relative to any discovered {site_type}sites"
......@@ -1334,11 +1333,9 @@ class Env:
def is_path_relative_to_lib(self, path: Path) -> bool:
for lib_path in [self.purelib, self.platlib]:
try:
with contextlib.suppress(ValueError):
path.relative_to(lib_path)
return True
except ValueError:
pass
return False
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment