From b9899f1d9add0bc0f8f48f04ba53162899225767 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Sun, 13 Aug 2023 20:04:06 +0200 Subject: [PATCH] Fix KeyError: 'console_scripts' --- ...ompatibility-in-check_console_script.patch | 56 +++++++++++++++++++ python-argcomplete.spec | 11 +++- 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 0003-Ensure-Python-3.7-compatibility-in-check_console_script.patch diff --git a/0003-Ensure-Python-3.7-compatibility-in-check_console_script.patch b/0003-Ensure-Python-3.7-compatibility-in-check_console_script.patch new file mode 100644 index 0000000..d3338ce --- /dev/null +++ b/0003-Ensure-Python-3.7-compatibility-in-check_console_script.patch @@ -0,0 +1,56 @@ +From 999d3b16dd40a3b8b70c3c21a08365da6cfe867b Mon Sep 17 00:00:00 2001 +From: Alex <76689481+flu0r1ne@users.noreply.github.com> +Date: Sun, 4 Jun 2023 20:43:41 -0500 +Subject: [PATCH] Ensure Python 3.7 compatibility in check_console_script + (#436) + +* Ensure Py3.7 compatibility in check_console_script + +The importlib backport, `importlib_metadata`, returns a tuple of +entry points instead of a dictionary keyed by entry group. This inconsistency +caused a KeyError exception to be thrown. To resolve this issue, the script has +been adjusted to maintain compatibility with Python 3.7, as specified in +`setup.py`. +--- + argcomplete/_check_console_script.py | 16 +++++++++++++++- + 1 file changed, 15 insertions(+), 1 deletion(-) + +diff --git a/argcomplete/_check_console_script.py b/argcomplete/_check_console_script.py +index fdfb88f..3f838e4 100644 +--- a/argcomplete/_check_console_script.py ++++ b/argcomplete/_check_console_script.py +@@ -16,8 +16,12 @@ import sys + + try: + from importlib.metadata import entry_points as importlib_entry_points ++ from importlib.metadata import EntryPoint ++ use_entry_points_backport = False + except ImportError: + from importlib_metadata import entry_points as importlib_entry_points ++ from importlib_metadata import EntryPoint ++ use_entry_points_backport = True + + from ._check_module import ArgcompleteMarkerNotFound, find + +@@ -29,7 +33,17 @@ def main(): + # Find the module and function names that correspond to this + # assuming it is actually a console script. + name = os.path.basename(script_path) +- entry_points = [ep for ep in importlib_entry_points()["console_scripts"] if ep.name == name] ++ ++ entry_points = importlib_entry_points() ++ ++ # The importlib_metadata backport returns a tuple of entry point objects ++ # whereas the official library returns a SelectableGroups object ++ if not use_entry_points_backport: ++ entry_points = entry_points["console_scripts"] ++ ++ entry_points = [ep for ep in entry_points \ ++ if ep.name == name and ep.group == "console_scripts" ] ++ + if not entry_points: + raise ArgcompleteMarkerNotFound('no entry point found matching script') + entry_point = entry_points[0] +-- +2.40.1 + diff --git a/python-argcomplete.spec b/python-argcomplete.spec index 8a244ed..cf5934f 100644 --- a/python-argcomplete.spec +++ b/python-argcomplete.spec @@ -8,7 +8,7 @@ Name: python-argcomplete Summary: Bash tab completion for argparse Version: 2.0.0 -Release: 10%{?dist} +Release: 11%{?dist} License: ASL 2.0 URL: https://github.com/kislyuk/argcomplete Source0: %pypi_source argcomplete @@ -22,6 +22,11 @@ Patch1: 0001-Remove-commit-hash-from-Fish-version.patch # Upstream already skips those on MacOS, so we skip them as well Patch2: 0002-Skip-tests-that-fail-on-Python-3.12.patch +# Ensure Python 3.7+ compatibility in check_console_script +# Rebased from https://github.com/kislyuk/argcomplete/commit/f4d046c0ce +# Should fix https://bugzilla.redhat.com/2231593 +Patch3: 0003-Ensure-Python-3.7-compatibility-in-check_console_script.patch + BuildRequires: python3-devel BuildRequires: python3-setuptools @@ -96,6 +101,10 @@ export INPUTRC=$PWD/.inputrc %{_sysconfdir}/bash_completion.d/%{name} %changelog +* Sun Aug 13 2023 Miro HronĨok - 2.0.0-11 +- Fix KeyError: 'console_scripts' +- Fixes: rhbz#2231593 + * Fri Jul 21 2023 Fedora Release Engineering - 2.0.0-10 - Rebuilt for https://fedoraproject.org/wiki/Fedora_39_Mass_Rebuild