kislyuk / argcomplete

Python and tab completion, better together.
https://kislyuk.github.io/argcomplete/
Apache License 2.0
1.39k stars 129 forks source link

Ensure Python 3.12+ compatibility in check_console_script #448

Closed hroncok closed 9 months ago

hroncok commented 9 months ago

In f4d046c0cec1dab17f65853442b1da7d341e2915 an assumption was made (correct at the time), that only the importlib.metadata backport, importlib_metadata, returns a tuple of entry points.

However, importlib.metadata in Python 3.12+ behaves the same.

This caused a KeyError exception to be thrown on Python 3.12, as reported repeatedly be testers of Fedora Linux 39 in:

https://bugzilla.redhat.com/show_bug.cgi?id=2231593

This change adjusts the conditional used in check_console_script to assume both the backport and Python 3.12+ return a tuple.

While not obvious from the test failures output, this change also fixes the following TestBashGlobal tests failures:

For the reference, the failures looked like this:

FAIL: test_console_script_module (__main__.TestBashGlobal.test_console_script_module)
Test completing a console_script for a module.
----------------------------------------------------------------------
Traceback (most recent call last):
  File ".../argcomplete/test/test.py", line 1376, in test_console_script_module
    self._test_console_script()
  File ".../argcomplete/test/test.py", line 1370, in _test_console_script
    self.assertEqual(self.sh.run_command(command), "arg\r\n")
AssertionError: "usage: test-module [-h] {arg}\r\ntest-mo[66 chars]\r\n" != 'arg\r\n'
+ arg
- usage: test-module [-h] {arg}
- test-module: error: argument arg: invalid choice: 'a' (choose from 'arg')

Fixes https://github.com/kislyuk/argcomplete/issues/440

codecov-commenter commented 9 months ago

Codecov Report

Patch and project coverage have no change.

Comparison is base (a1d0615) 80.30% compared to head (d7e6775) 80.30%.

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## develop #448 +/- ## ======================================== Coverage 80.30% 80.30% ======================================== Files 10 10 Lines 782 782 ======================================== Hits 628 628 Misses 154 154 ``` | [Files Changed](https://app.codecov.io/gh/kislyuk/argcomplete/pull/448?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Andrey+Kislyuk) | Coverage Δ | | |---|---|---| | [argcomplete/\_check\_console\_script.py](https://app.codecov.io/gh/kislyuk/argcomplete/pull/448?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Andrey+Kislyuk#diff-YXJnY29tcGxldGUvX2NoZWNrX2NvbnNvbGVfc2NyaXB0LnB5) | `0.00% <0.00%> (ø)` | |

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

kislyuk commented 9 months ago

Thank you!