public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
* [rpms/python-plugincode] rawhide: Add patch to fix breakage with pluggy 1.7.0
@ 2026-11-03 23:16 Maxwell G
0 siblings, 0 replies; only message in thread
From: Maxwell G @ 2026-11-03 23:16 UTC (permalink / raw)
To: git-commits
A new commit has been pushed.
Repo : rpms/python-plugincode
Branch : rawhide
Commit : b6236d78f44249b7b14f551f1e73fd91e2717806
Author : Maxwell G <maxwell@gtmx.me>
Date : 2026-11-03T16:48:15-06:00
Stats : +392/-1 in 2 file(s)
URL : https://src.fedoraproject.org/rpms/python-plugincode/c/b6236d78f44249b7b14f551f1e73fd91e2717806?branch=rawhide
Log:
Add patch to fix breakage with pluggy 1.7.0
---
diff --git a/0001-Load-ScanCode-plugins-directly-from-entry-points.patch b/0001-Load-ScanCode-plugins-directly-from-entry-points.patch
new file mode 100644
index 0000000..520d43d
--- /dev/null
+++ b/0001-Load-ScanCode-plugins-directly-from-entry-points.patch
@@ -0,0 +1,380 @@
+From 6b517342070f254ba8186cbad453a258a886ea9b Mon Sep 17 00:00:00 2001
+From: Jatin Pandey <jatinjio1212@gmail.com>
+Date: Tue, 3 Nov 2026 19:28:24 +0530
+Subject: [PATCH] Load ScanCode plugins directly from entry points
+
+Fixes #14
+
+AI-assisted: Codex assisted with investigation, implementation and local tests.
+Signed-off-by: Jatin Pandey <jatinjio1212@gmail.com>
+---
+ AUTHORS.rst | 1 +
+ CHANGELOG.rst | 7 ++
+ requirements.txt | 1 -
+ setup.cfg | 2 +-
+ src/plugincode/__init__.py | 44 +++++---
+ src/plugincode/location_provider.py | 22 ++--
+ tests/plugincode/test_entry_points.py | 146 ++++++++++++++++++++++++++
+ 7 files changed, 196 insertions(+), 27 deletions(-)
+ create mode 100644 tests/plugincode/test_entry_points.py
+
+diff --git a/AUTHORS.rst b/AUTHORS.rst
+index 1d899c5..25a692b 100644
+--- a/AUTHORS.rst
++++ b/AUTHORS.rst
+@@ -1,6 +1,7 @@
+ The following organizations or individuals have contributed to this repo:
+
+ - Abhishek Kumar @Abhishek-Dev09
++- Jatin Pandey @satiricalguru
+ - Jono Yang @JonoYang
+ - Jiri Popelka @jpopelka
+ - Philippe Ombredanne @pombredanne
+diff --git a/CHANGELOG.rst b/CHANGELOG.rst
+index 2d8ec53..ba63937 100644
+--- a/CHANGELOG.rst
++++ b/CHANGELOG.rst
+@@ -1,6 +1,13 @@
+ Changelog
+ =============
+
++Next release
++------------
++
++- Replace pluggy with entry-point loading in stage and native-location plugin managers.
++ Preserve legacy marker imports, plugin ordering and the first plugin for each name.
++ https://github.com/aboutcode-org/plugincode/issues/14
++
+ v32.0.0 - 2023-05-02
+ ------------------------
+
+diff --git a/requirements.txt b/requirements.txt
+index 3ca8ceb..b67238c 100644
+--- a/requirements.txt
++++ b/requirements.txt
+@@ -45,7 +45,6 @@ pdfminer.six==20220524
+ pefile==2022.5.30
+ pip-requirements-parser==31.2.0
+ pkginfo2==30.0.0
+-pluggy==1.0.0
+ ply==3.11
+ publicsuffix2==2.20191221
+ pyahocorasick==2.0.0b1
+diff --git a/setup.cfg b/setup.cfg
+index 87de0de..aaffaf3 100644
+--- a/setup.cfg
++++ b/setup.cfg
+@@ -50,7 +50,7 @@ python_requires = >=3.7
+ install_requires =
+ click >= 6.7, !=7.0
+ commoncode >= 31.0.0
+- pluggy >= 0.12.0
++ importlib_metadata >= 3.6; python_version < "3.10"
+
+
+ [options.packages.find]
+diff --git a/src/plugincode/__init__.py b/src/plugincode/__init__.py
+index 9860fbc..08d680c 100644
+--- a/src/plugincode/__init__.py
++++ b/src/plugincode/__init__.py
+@@ -11,9 +11,11 @@ import sys
+
+ import click
+ from click.types import BoolParamType
+-from pluggy import HookimplMarker
+-from pluggy import HookspecMarker
+-from pluggy import PluginManager as PluggyPluginManager
++
++if sys.version_info >= (3, 10):
++ from importlib.metadata import entry_points
++else:
++ from importlib_metadata import entry_points
+
+ from commoncode import cliutils
+
+@@ -36,6 +38,32 @@ if TRACE:
+ return logger.debug(" ".join(isinstance(a, str) and a or repr(a) for a in args))
+
+
++class HookspecMarker:
++ """Compatibility decorator for plugin authors; plugins are called directly."""
++
++ def __init__(self, project_name):
++ self.project_name = project_name
++
++ def __call__(self, function=None, **kwargs):
++ if function is None:
++ return self
++ return function
++
++
++class HookimplMarker(HookspecMarker):
++ """Compatibility decorator for existing plugin implementations."""
++
++
++def _load_entry_points(group):
++ """Yield (name, plugin) pairs, loading only the first entry for each name."""
++ seen = set()
++ for entry in entry_points(group=group):
++ if entry.name in seen:
++ continue
++ seen.add(entry.name)
++ yield entry.name, entry.load()
++
++
+ class PlugincodeError(Exception):
+ """Base exception for plugincode errors"""
+
+@@ -173,13 +201,11 @@ class PluginManager(object):
+ qualified Python module name `module_qname` with plugins loaded from the
+ setuptools `entrypoint` that must subclass `plugin_base_class`.
+ """
+- self.manager = PluggyPluginManager(project_name=stage)
+ self.managers[stage] = self
+
+ self.stage = stage
+ self.entrypoint = entrypoint
+ self.plugin_base_class = plugin_base_class
+- self.manager.add_hookspecs(sys.modules[module_qname])
+
+ # set to True once this manager is initialized by running its setup()
+ self.initialized = False
+@@ -218,17 +244,11 @@ class PluginManager(object):
+ if self.initialized:
+ return
+
+- entrypoint = self.entrypoint
+- try:
+- self.manager.load_setuptools_entrypoints(entrypoint)
+- except ImportError as e:
+- raise e
+ stage = self.stage
+
+ plugin_options = []
+ plugin_classes = []
+- required_plugins = set()
+- for name, plugin_class in self.manager.list_name_plugin():
++ for name, plugin_class in _load_entry_points(self.entrypoint):
+
+ if not issubclass(plugin_class, self.plugin_base_class):
+ qname = "%(stage)s:%(name)s" % locals()
+diff --git a/src/plugincode/location_provider.py b/src/plugincode/location_provider.py
+index d2d0be8..f67ddd8 100644
+--- a/src/plugincode/location_provider.py
++++ b/src/plugincode/location_provider.py
+@@ -7,12 +7,8 @@
+
+ import logging
+ import os
+-import sys
+
+-from pluggy import PluginManager as PluggyPluginManager
+-
+-from plugincode import HookimplMarker
+-from plugincode import HookspecMarker
++from plugincode import HookimplMarker, HookspecMarker, _load_entry_points
+
+ """
+ Support for plugins that provide one or more paths keys typically OS-specific
+@@ -75,10 +71,8 @@ class SimplePluginManager(object):
+ name `module_qname` with plugins loaded from the setuptools `entrypoint`
+ that must subclass `plugin_base_class`.
+ """
+- self.manager = PluggyPluginManager(project_name=project_name)
+ self.entrypoint = entrypoint
+ self.plugin_base_class = plugin_base_class
+- self.manager.add_hookspecs(sys.modules[project_name])
+
+ # set to True once this manager is initialized by running its setup()
+ self.initialized = False
+@@ -99,11 +93,8 @@ class SimplePluginManager(object):
+ if self.initialized:
+ return self.plugin_classes.values()
+
+- entrypoint = self.entrypoint
+- self.manager.load_setuptools_entrypoints(entrypoint)
+-
+ plugin_classes = []
+- for name, plugin_class in self.manager.list_name_plugin():
++ for name, plugin_class in _load_entry_points(self.entrypoint):
+ if not issubclass(plugin_class, self.plugin_base_class):
+ plugin_base_class = self.plugin_base_class
+ raise Exception(
+@@ -120,7 +111,9 @@ class SimplePluginManager(object):
+
+
+ location_provider_plugins = SimplePluginManager(
+- project_name=project_name, entrypoint=entrypoint, plugin_base_class=LocationProviderPlugin
++ project_name=project_name,
++ entrypoint=entrypoint,
++ plugin_base_class=LocationProviderPlugin,
+ )
+
+
+@@ -157,7 +150,10 @@ def get_location(location_key, _cached_locations={}):
+
+ if unknown_locations:
+ msg = "Non-existing locations provided:\n:"
+- msg += "\n".join("key:{}, loc: {}".format(k, l) for k, l in unknown_locations.items())
++ msg += "\n".join(
++ f"key:{key}, loc: {location}"
++ for key, location in unknown_locations.items()
++ )
+ raise ProvidedLocationError(msg)
+
+ return _cached_locations.get(location_key)
+diff --git a/tests/plugincode/test_entry_points.py b/tests/plugincode/test_entry_points.py
+new file mode 100644
+index 0000000..394e27b
+--- /dev/null
++++ b/tests/plugincode/test_entry_points.py
+@@ -0,0 +1,146 @@
++# Copyright (c) nexB Inc. and others. All rights reserved.
++# SPDX-License-Identifier: Apache-2.0
++
++import subprocess
++import sys
++from unittest.mock import Mock
++
++import pytest
++
++import plugincode
++from plugincode import BasePlugin, HookimplMarker, HookspecMarker, PluginManager, PlugincodeError
++from plugincode.location_provider import LocationProviderPlugin, SimplePluginManager
++
++
++def test_all_stages_import_without_pluggy():
++ script = """
++import importlib.abc
++import sys
++class NoPluggy(importlib.abc.MetaPathFinder):
++ def find_spec(self, fullname, *args):
++ if fullname == 'pluggy':
++ raise ImportError('pluggy must not be imported')
++sys.meta_path.insert(0, NoPluggy())
++from plugincode import location_provider, pre_scan, scan, post_scan, output, output_filter
++"""
++ subprocess.run([sys.executable, "-c", script], check=True)
++
++
++@pytest.mark.parametrize("marker_class", [HookspecMarker, HookimplMarker])
++def test_legacy_markers_preserve_classes_and_functions(marker_class):
++ marker = marker_class("test")
++
++ class Plugin:
++ pass
++
++ def function():
++ return 42
++
++ assert marker(Plugin) is Plugin
++ assert marker(tryfirst=True)(Plugin) is Plugin
++ assert marker(function) is function
++ assert marker(specname="legacy")(function) is function
++
++
++@pytest.mark.parametrize("kind", ["stage", "location"])
++def test_entry_points_keep_first_name_and_initialize_once(monkeypatch, kind):
++ base = BasePlugin if kind == "stage" else LocationProviderPlugin
++
++ class Valid(base):
++ pass
++
++ first = Mock(name="first")
++ first.name = "example"
++ first.load.return_value = Valid
++ duplicate = Mock(name="duplicate")
++ duplicate.name = "example"
++ entries = Mock(return_value=[first, duplicate])
++ monkeypatch.setattr(plugincode, "entry_points", entries)
++ if kind == "stage":
++ manager = PluginManager("test", __name__, "test.group", base)
++ else:
++ manager = SimplePluginManager(__name__, "test.group", base)
++ try:
++ manager.setup()
++ manager.setup()
++ assert Valid.name == "example"
++ if kind == "stage":
++ assert manager.plugin_classes == [Valid]
++ assert Valid.stage == "test"
++ else:
++ assert manager.plugin_classes == {"example": Valid}
++ entries.assert_called_once_with(group="test.group")
++ first.load.assert_called_once_with()
++ duplicate.load.assert_not_called()
++ finally:
++ if kind == "stage":
++ PluginManager.managers.pop("test", None)
++
++
++@pytest.mark.parametrize("kind", ["stage", "location"])
++def test_invalid_plugins_are_rejected(monkeypatch, kind):
++ entry = Mock()
++ entry.name = "invalid"
++ entry.load.return_value = object
++ monkeypatch.setattr(plugincode, "entry_points", Mock(return_value=[entry]))
++ if kind == "stage":
++ manager = PluginManager("test", __name__, "test.group", BasePlugin)
++ error = PlugincodeError
++ else:
++ manager = SimplePluginManager(__name__, "test.group", LocationProviderPlugin)
++ error = Exception
++ try:
++ with pytest.raises(error, match="must extend"):
++ manager.setup()
++ assert not manager.initialized
++ finally:
++ if kind == "stage":
++ PluginManager.managers.pop("test", None)
++
++
++def test_stage_plugins_retain_sort_order_and_options(monkeypatch):
++ from commoncode.cliutils import PluggableCommandLineOption
++
++ option = PluggableCommandLineOption(["--example"], is_flag=True)
++
++ class Later(BasePlugin):
++ sort_order = 20
++ options = [option]
++
++ class Earlier(BasePlugin):
++ sort_order = 10
++
++ entries = []
++ for name, cls in [("later", Later), ("earlier", Earlier)]:
++ entry = Mock()
++ entry.name = name
++ entry.load.return_value = cls
++ entries.append(entry)
++ monkeypatch.setattr(plugincode, "entry_points", Mock(return_value=entries))
++ manager = PluginManager("test", __name__, "test.group", BasePlugin)
++ try:
++ classes, options = manager.setup()
++ assert classes == [Earlier, Later]
++ assert options == [option]
++ finally:
++ PluginManager.managers.pop("test", None)
++
++
++@pytest.mark.parametrize("kind", ["stage", "location"])
++def test_entry_point_import_errors_propagate(monkeypatch, kind):
++ entry = Mock()
++ entry.name = "broken"
++ entry.load.side_effect = ImportError("missing plugin dependency")
++ monkeypatch.setattr(plugincode, "entry_points", Mock(return_value=[entry]))
++ manager = (
++ PluginManager("test", __name__, "test.group", BasePlugin)
++ if kind == "stage"
++ else SimplePluginManager(__name__, "test.group", LocationProviderPlugin)
++ )
++ try:
++ with pytest.raises(ImportError, match="missing plugin dependency"):
++ manager.setup()
++ assert not manager.initialized
++ finally:
++ if kind == "stage":
++ PluginManager.managers.pop("test", None)
+--
+2.56.0
+
diff --git a/python-plugincode.spec b/python-plugincode.spec
index 881ad1e..35b457b 100644
--- a/python-plugincode.spec
+++ b/python-plugincode.spec
@@ -6,9 +6,20 @@ Release: %autorelease
Summary: Plugable functionality with plugins used by ScanCode toolkit
License: Apache-2.0
-URL: https://github.com/nexB/plugincode
+URL: https://github.com/aboutcode-org/plugincode
Source: %url/archive/v%{version}/%{pypi_name}-%{version}.tar.gz
+# Backport of https://github.com/aboutcode-org/plugincode/pull/15
+# https://github.com/aboutcode-org/scancode-toolkit/issues/5363
+# https://github.com/aboutcode-org/scancode-toolkit/issues/5367
+# https://github.com/aboutcode-org/plugincode/issues/14
+# NOTE(gotmax23): This is an AI-generated patch that replaces pluggy plugin loading
+# with standard importlib.metadata entrypoint loading.
+# It also creates no-op versions of pluggy's HookspecMarker and HookimplMarker decorators.
+# We should work with plugincode upstream and the other aboutcode-org/*
+# projects to adopt a better long-term solution.
+Patch: 0001-Load-ScanCode-plugins-directly-from-entry-points.patch
+
BuildArch: noarch
BuildRequires: python3-devel
BuildRequires: python3dist(pytest)
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-03 23:16 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-03 23:16 [rpms/python-plugincode] rawhide: Add patch to fix breakage with pluggy 1.7.0 Maxwell G
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox