mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-05 12:36:54 +00:00
prevent duplicate plugin discovery on misconfigured pythons
for example, `venv`-virtualenvs on fedora have both `lib` and `lib64` on `sys.path` despite them being the same. this causes `importlib.metadata.distributions` to double-discover. ```console $ docker run --rm -t fedora:latest bash -c 'dnf install -qq -y python3 >& /dev/null && python3 -m venv venv && venv/bin/pip -qq install cfgv && venv/bin/python - <<< "from importlib.metadata import distributions; print(len([d for d in distributions() if d.name == '"'"'cfgv'"'"']))"' 2 ```
This commit is contained in:
parent
3f4872a4d8
commit
fce93b952a
2 changed files with 24 additions and 0 deletions
|
|
@ -179,6 +179,8 @@ def _flake8_plugins(
|
|||
|
||||
|
||||
def _find_importlib_plugins() -> Generator[Plugin, None, None]:
|
||||
# some misconfigured pythons (RHEL) have things on `sys.path` twice
|
||||
seen = set()
|
||||
for dist in importlib_metadata.distributions():
|
||||
# assigned to prevent continual reparsing
|
||||
eps = dist.entry_points
|
||||
|
|
@ -190,6 +192,11 @@ def _find_importlib_plugins() -> Generator[Plugin, None, None]:
|
|||
# assigned to prevent continual reparsing
|
||||
meta = dist.metadata
|
||||
|
||||
if meta["name"] in seen:
|
||||
continue
|
||||
else:
|
||||
seen.add(meta["name"])
|
||||
|
||||
if meta["name"] in BANNED_PLUGINS:
|
||||
LOG.warning(
|
||||
"%s plugin is obsolete in flake8>=%s",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue