Skip to content

Commit be967a2

Browse files
authored
fix: show netrc parsing error once (#147)
1 parent e4b6386 commit be967a2

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/unearth/utils.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,12 @@ def commonprefix(*m: str) -> str:
287287
return s1
288288

289289

290+
_netrc_warned = False
291+
292+
290293
def get_netrc_auth(url: str) -> tuple[str, str] | None:
291294
"""Get the auth for the given url from the netrc file."""
295+
global _netrc_warned
292296
try:
293297
from netrc import NetrcParseError, netrc
294298
except ImportError:
@@ -302,7 +306,11 @@ def get_netrc_auth(url: str) -> tuple[str, str] | None:
302306
except FileNotFoundError:
303307
return None
304308
except (NetrcParseError, OSError) as e:
305-
logger.warning("Couldn't parse netrc because of %s: %s", type(e).__name__, e)
309+
if not _netrc_warned:
310+
logger.warning(
311+
"Couldn't parse netrc because of %s: %s", type(e).__name__, e
312+
)
313+
_netrc_warned = True
306314
return None
307315
info = authenticator.authenticators(hostname)
308316

0 commit comments

Comments
 (0)