There was a gap between 1 and 3, which was not ideal. This way, we don't have to deal with the numbers.
57 lines
2.2 KiB
Diff
57 lines
2.2 KiB
Diff
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
|
|
|