Created
June 4, 2024 15:36
-
-
Save jaraco/24a3e2d7dec138d410036a40f8b7ba36 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jaraco.docker main @ pip-run mccabe -- -m mccabe jaraco/docker/__init__.py | |
9:0: 'text_in_file' 1 | |
29:0: 'is_docker' 1 | |
jaraco.docker main @ git diff | |
diff --git a/jaraco/docker/__init__.py b/jaraco/docker/__init__.py | |
index 52bfb1c..1705c44 100644 | |
--- a/jaraco/docker/__init__.py | |
+++ b/jaraco/docker/__init__.py | |
@@ -1,15 +1,11 @@ | |
from __future__ import annotations | |
+import contextlib | |
import itertools | |
import pathlib | |
import re | |
-from jaraco.functools import apply | |
-from jaraco.context import suppress | |
- | |
-@apply(bool) | |
-@suppress(FileNotFoundError) | |
def text_in_file(text: str, filename: pathlib.Path, limit: int | None = None) -> bool: | |
""" | |
>>> text_in_file('anything', pathlib.Path(__file__)) | |
@@ -19,8 +15,10 @@ def text_in_file(text: str, filename: pathlib.Path, limit: int | None = None) -> | |
>>> text_in_file('anything', pathlib.Path('/doesnotexist')) | |
False | |
""" | |
- with filename.open(encoding='utf-8') as lines: | |
- return any(re.search(text, line) for line in itertools.islice(lines, limit)) | |
+ with contextlib.suppress(FileNotFoundError): | |
+ with filename.open(encoding='utf-8') as lines: | |
+ return any(re.search(text, line) for line in itertools.islice(lines, limit)) | |
+ return False | |
dockerenv = pathlib.Path('/.dockerenv') | |
jaraco.docker main @ pip-run mccabe -- -m mccabe jaraco/docker/__init__.py | |
9:0: 'text_in_file' 1 | |
29:0: 'is_docker' 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment