aboutcode-org / commoncode

A library of common functions shared in many other AboutCode projects
3 stars 11 forks source link

Commoncode fails with Click < 8 #31

Closed pombredanne closed 3 years ago

pombredanne commented 3 years ago

See in #30 by @vznncv:

The pull request #27 adds update_min_steps option usage of click._termui_impl.ProgressBar that is available from click 8.0. But existed setup.cfg contains the following restriction: click >= 6.7, !=7.0. It breaks scancode with click<8 version installation. For example: https://github.com/ARMmbed/mbed-os/pull/14981/checks?check_run_id=3470879205

This pull request updates minimal click version in the setup.cfg according changes in the pull request #27.

pombredanne commented 3 years ago

from https://github.com/nexB/commoncode/pull/30#issuecomment-910172231

The pull request #27 adds update_min_steps option usage of click._termui_impl.ProgressBar that is available from click 8.0. But existed setup.cfg contains the following restriction: click >= 6.7, !=7.0. It breaks scancode with click<8 version installation. For example: https://github.com/ARMmbed/mbed-os/pull/14981/checks?check_run_id=3470879205

This pull request updates minimal click version in the setup.cfg according changes in the pull request #27.

I ran these tests: /scancode-toolkit$ for clk_ver in 8.0.1 7.1.2 7.1.1 7.1 6.7; do pip uninstall -y click; pip install click==$clk_ver; scancode -i samples/ -n3 --json-pp - ; done and commoncode$ for clk_ver in 8.0.1 7.1.2 7.1.1 7.1 6.7; do pip uninstall -y click; pip install click==$clk_ver; pytest -vvs -n3; done

and all pass with this patch:

diff --git a/src/commoncode/cliutils.py b/src/commoncode/cliutils.py
index 4ff8c8e..5a2a3b6 100644
--- a/src/commoncode/cliutils.py
+++ b/src/commoncode/cliutils.py
@@ -267,7 +267,8 @@
             '[%(bar)s]' + ' ' + '%(info)s'
             if bar_template is None else bar_template
         )
-    return progress_class(
+
+    kwargs = dict(
         iterable=iterable,
         length=length,
         fill_char=fill_char,
@@ -281,10 +282,15 @@
         label=label,
         file=file,
         color=color,
-        update_min_steps=update_min_steps,
         width=width,
     )

+    pb = progress_class([])
+    if hasattr(pb, 'update_min_steps'):
+        kwargs['update_min_steps'] = update_min_steps
+
+    return progress_class(**kwargs)
+

 def fixed_width_file_name(path, max_length=25):
     """

The lines

+    pb = progress_class([])
+    if hasattr(pb, 'update_min_steps'): 

... are duck typing at its best... Not super elegant but effective nonetheless!

So with this patch we can accept all currently supported Click versions and not only > 8

pombredanne commented 3 years ago

Fixed and released in 30.0.0