Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: PyCQA/flake8
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 5.0.0
Choose a base ref
...
head repository: PyCQA/flake8
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 5.0.1
Choose a head ref
  • 5 commits
  • 6 files changed
  • 2 contributors

Commits on Jul 31, 2022

  1. Remove needless sort in _style_guide_for

    We are always returning the last element so a 'max' operation is sufficient instead of sorting. Note the old code did not handle an empty list so this change doesn't either
    mxr authored Jul 31, 2022
    Copy the full SHA
    b0cad55 View commit details
  2. Merge pull request #1628 from mxr/patch-1

    Remove needless sort in `_style_guide_for`
    asottile authored Jul 31, 2022
    Copy the full SHA
    3f4872a View commit details
  3. 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
    ```
    asottile committed Jul 31, 2022
    Copy the full SHA
    fce93b9 View commit details
  4. Merge pull request #1631 from PyCQA/dupe-sys-path

    prevent duplicate plugin discovery on misconfigured pythons
    asottile authored Jul 31, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    d20bb97 View commit details
  5. Release 5.0.1

    asottile committed Jul 31, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    405cfe0 View commit details
Showing with 42 additions and 5 deletions.
  1. +15 −0 docs/source/release-notes/5.0.1.rst
  2. +1 −0 docs/source/release-notes/index.rst
  3. +1 −1 src/flake8/__init__.py
  4. +7 −0 src/flake8/plugins/finder.py
  5. +1 −4 src/flake8/style_guide.py
  6. +17 −0 tests/unit/plugins/finder_test.py
15 changes: 15 additions & 0 deletions docs/source/release-notes/5.0.1.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
5.0.1 -- 2022-07-31
-------------------

You can view the `5.0.1 milestone`_ on GitHub for more details.

Bugs Fixed
~~~~~~~~~~

- Fix duplicate plugin discovery on misconfigured pythons (See also
:issue:`1627`, :pull:`1631`).


.. all links
.. _5.0.1 milestone:
https://github.com/PyCQA/flake8/milestone/43
1 change: 1 addition & 0 deletions docs/source/release-notes/index.rst
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ with the newest releases first.

.. toctree::
5.0.0
5.0.1

4.x Release Series
==================
2 changes: 1 addition & 1 deletion src/flake8/__init__.py
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@
LOG = logging.getLogger(__name__)
LOG.addHandler(logging.NullHandler())

__version__ = "5.0.0"
__version__ = "5.0.1"
__version_info__ = tuple(int(i) for i in __version__.split(".") if i.isdigit())

_VERBOSITY_TO_LOG_LEVEL = {
7 changes: 7 additions & 0 deletions src/flake8/plugins/finder.py
Original file line number Diff line number Diff line change
@@ -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",
5 changes: 1 addition & 4 deletions src/flake8/style_guide.py
Original file line number Diff line number Diff line change
@@ -254,13 +254,10 @@ def populate_style_guides_with(

def _style_guide_for(self, filename: str) -> "StyleGuide":
"""Find the StyleGuide for the filename in particular."""
guides = sorted(
return max(
(g for g in self.style_guides if g.applies_to(filename)),
key=lambda g: len(g.filename or ""),
)
if len(guides) > 1:
return guides[-1]
return guides[0]

@contextlib.contextmanager
def processing_file(
17 changes: 17 additions & 0 deletions tests/unit/plugins/finder_test.py
Original file line number Diff line number Diff line change
@@ -361,6 +361,23 @@ def test_importlib_plugins(
]


def test_duplicate_dists(flake8_dist):
# some poorly packaged pythons put lib and lib64 on sys.path resulting in
# duplicates from `importlib.metadata.distributions`
with mock.patch.object(
importlib_metadata,
"distributions",
return_value=[
flake8_dist,
flake8_dist,
],
):
ret = list(finder._find_importlib_plugins())

# we should not have duplicates
assert len(ret) == len(set(ret))


def test_find_local_plugins_nothing():
cfg = configparser.RawConfigParser()
assert set(finder._find_local_plugins(cfg)) == set()