Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure Python 3.12+ compatibility in check_console_script #448

Merged
merged 1 commit into from
Sep 16, 2023

Conversation

hroncok
Copy link
Contributor

@hroncok hroncok commented Sep 14, 2023

In f4d046c 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:

  • test_console_script_module
  • test_console_script_module_wheel
  • test_console_script_package
  • test_console_script_package_wheel

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 #440

In f4d046c 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:

 - test_console_script_module
 - test_console_script_module_wheel
 - test_console_script_package
 - test_console_script_package_wheel

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 kislyuk#440
@codecov-commenter
Copy link

codecov-commenter commented Sep 14, 2023

Codecov Report

Patch and project coverage have no change.

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

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

Additional details and impacted files
@@           Coverage Diff            @@
##           develop     #448   +/-   ##
========================================
  Coverage    80.30%   80.30%           
========================================
  Files           10       10           
  Lines          782      782           
========================================
  Hits           628      628           
  Misses         154      154           
Files Changed Coverage Δ
argcomplete/_check_console_script.py 0.00% <0.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@kislyuk kislyuk merged commit 59f4f9d into kislyuk:develop Sep 16, 2023
22 checks passed
@kislyuk
Copy link
Owner

kislyuk commented Sep 16, 2023

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Test failures with Python 3.12.0b2
3 participants