Commit 6d4c9fe6 by Kevin Kirsche Committed by GitHub

refactor: use contextlib.suppress instead of except pass (#5840)

* refactor: use contextlib.suppress instead of except pass

* revert: get-poetry.py changes

* fix: import contextlib rather than only suppress
parent 921ce26f
from __future__ import annotations
import contextlib
import functools
import glob
import logging
......@@ -556,12 +557,10 @@ 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
......@@ -13,7 +14,6 @@ import sys
import sysconfig
import warnings
from contextlib import contextmanager
from copy import deepcopy
from pathlib import Path
from subprocess import CalledProcessError
......@@ -279,11 +279,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 +1332,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
......@@ -1737,7 +1733,7 @@ class VirtualEnv(Env):
kwargs["env"] = self.get_temp_environ(environ=kwargs.get("env"))
return super().execute(bin, *args, **kwargs)
@contextmanager
@contextlib.contextmanager
def temp_environ(self) -> Iterator[None]:
environ = dict(os.environ)
try:
......@@ -1871,7 +1867,7 @@ class NullEnv(SystemEnv):
return bin
@contextmanager
@contextlib.contextmanager
def ephemeral_environment(
executable: str | Path | None = None,
flags: dict[str, bool] | None = None,
......@@ -1887,7 +1883,7 @@ def ephemeral_environment(
yield VirtualEnv(venv_dir, venv_dir)
@contextmanager
@contextlib.contextmanager
def build_environment(
poetry: CorePoetry, env: Env | None = None, io: IO | None = None
) -> Iterator[Env]:
......
from __future__ import annotations
import contextlib
import json
import os
import os.path
......@@ -204,12 +205,10 @@ def read_extras():
extra_req_file_path = os.path.join(
extra_requirements_dir, extra_requirements_filename
)
try:
with contextlib.suppress(RuntimeError):
extras[filename_match.group(1)] = read_file(
extra_req_file_path
).splitlines()
except RuntimeError:
pass
return extras
......
......@@ -56,6 +56,7 @@ int main(void) {
"""
import contextlib
import os.path
import platform
import sys
......@@ -81,13 +82,11 @@ if "setuptools.extension" in sys.modules:
sys.modules["distutils.command.build_ext"].Extension = _Extension
with_cython = False
try:
with contextlib.suppress(ImportError):
from Cython.Distutils import build_ext as _build_ext
from Cython.Distutils.extension import Extension as _Extension
with_cython = True
except ImportError:
pass
try:
from wheel.bdist_wheel import bdist_wheel
......
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