Merge pull request #3911 from anki-code/wsl_speed

Added warning about huge amount of files in PATH directories
This commit is contained in:
Anthony Scopatz 2020-10-21 14:03:09 -05:00 committed by GitHub
commit d4ff96ab25
Failed to generate hash of commit
3 changed files with 41 additions and 0 deletions

23
news/path_warn.rst Normal file
View file

@ -0,0 +1,23 @@
**Added:**
* Added warning about huge amount of commands in CommandsCache.
**Changed:**
* <news item>
**Deprecated:**
* <news item>
**Removed:**
* <news item>
**Fixed:**
* <news item>
**Security:**
* <news item>

View file

@ -7,6 +7,7 @@ and returns whether or not the process can be run in the background (returns
True) or must be run the foreground (returns False). True) or must be run the foreground (returns False).
""" """
import os import os
import sys
import time import time
import builtins import builtins
import argparse import argparse
@ -106,6 +107,16 @@ class CommandsCache(cabc.Mapping):
for cmd in executables_in(path): for cmd in executables_in(path):
key = cmd.upper() if ON_WINDOWS else cmd key = cmd.upper() if ON_WINDOWS else cmd
allcmds[key] = (os.path.join(path, cmd), alss.get(key, None)) allcmds[key] = (os.path.join(path, cmd), alss.get(key, None))
warn_cnt = builtins.__xonsh__.env.get("COMMANDS_CACHE_SIZE_WARNING")
if warn_cnt:
cnt = len(allcmds)
if cnt > warn_cnt:
print(
f"Warning! Found {cnt:,} executable files in the PATH directories!",
file=sys.stderr,
)
for cmd in alss: for cmd in alss:
if cmd not in allcmds: if cmd not in allcmds:
key = cmd.upper() if ON_WINDOWS else cmd key = cmd.upper() if ON_WINDOWS else cmd

View file

@ -1725,6 +1725,13 @@ def DEFAULT_VARS():
"or None / the empty string if traceback logging is not desired. " "or None / the empty string if traceback logging is not desired. "
"Logging to a file is not enabled by default.", "Logging to a file is not enabled by default.",
), ),
"COMMANDS_CACHE_SIZE_WARNING": Var(
is_int,
int,
str,
10000,
"Number of files on the PATH above which a warning is shown.",
),
} }
if hasattr(locale, "LC_MESSAGES"): if hasattr(locale, "LC_MESSAGES"):