From ae1d7bc8a0c2ef9a56712efcda044c3b1a190c10 Mon Sep 17 00:00:00 2001 From: Frost Ming Date: Mon, 2 Sep 2024 11:50:58 +0800 Subject: [PATCH] fix: show netrc parsing error once Fix #146 Signed-off-by: Frost Ming --- src/unearth/utils.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/unearth/utils.py b/src/unearth/utils.py index dce2ebd..67449c4 100644 --- a/src/unearth/utils.py +++ b/src/unearth/utils.py @@ -287,8 +287,12 @@ def commonprefix(*m: str) -> str: return s1 +_netrc_warned = False + + def get_netrc_auth(url: str) -> tuple[str, str] | None: """Get the auth for the given url from the netrc file.""" + global _netrc_warned try: from netrc import NetrcParseError, netrc except ImportError: @@ -302,7 +306,11 @@ def get_netrc_auth(url: str) -> tuple[str, str] | None: except FileNotFoundError: return None except (NetrcParseError, OSError) as e: - logger.warning("Couldn't parse netrc because of %s: %s", type(e).__name__, e) + if not _netrc_warned: + logger.warning( + "Couldn't parse netrc because of %s: %s", type(e).__name__, e + ) + _netrc_warned = True return None info = authenticator.authenticators(hostname)