Skip to content

Commit 3ef363c

Browse files
committed
Also support click 7.1.+ #31
This ensures that we work with all supported click versions and that this is tested Reference: aboutcode-org/scancode-toolkit#2713 Reference: #31 Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
1 parent a5218d7 commit 3ef363c

3 files changed

Lines changed: 56 additions & 2 deletions

File tree

azure-pipelines.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,20 @@ jobs:
6363
all: tmp\Scripts\pytest -n 2 -vvs
6464

6565

66+
################################################################################
67+
# Test using many version of Click to work around regressions in API
68+
################################################################################
69+
70+
71+
- template: etc/ci/azure-posix.yml
72+
parameters:
73+
job_name: ubuntu20_test_all_supported_click_versions
74+
image_name: ubuntu-20.04
75+
python_versions: ['3.6', '3.7', '3.8', '3.9']
76+
test_suites:
77+
click_versions: for clk_ver in 8.0.1 7.1.2 7.1.1 7.1 6.7; do pip install click==$clk_ver; tmp/bin/pytest -vvs tests/test_cliutils_progressbar.py; done
78+
79+
6680
################################################################################
6781
# Test using a plain pip install to get the latest of all wheels
6882
################################################################################

src/commoncode/cliutils.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,8 @@ def progressmanager(
267267
'[%(bar)s]' + ' ' + '%(info)s'
268268
if bar_template is None else bar_template
269269
)
270-
return progress_class(
270+
271+
kwargs = dict(
271272
iterable=iterable,
272273
length=length,
273274
fill_char=fill_char,
@@ -281,10 +282,21 @@ def progressmanager(
281282
label=label,
282283
file=file,
283284
color=color,
284-
update_min_steps=update_min_steps,
285285
width=width,
286286
)
287287

288+
# Check if we have an "update_min_steps" argument that was introduced in
289+
# Click 8. See https://github.com/pallets/click/pull/1698
290+
# Note that we use this argument on Click 8 in order to fix a regression
291+
# that this same PR introduced by Click and tracked originally at
292+
# https://github.com/nexB/scancode-toolkit/issues/2583
293+
# Here we create a dummy progress_class and then for the attribute presence.
294+
pb = progress_class([])
295+
if hasattr(pb, 'update_min_steps'):
296+
kwargs['update_min_steps'] = update_min_steps
297+
298+
return progress_class(**kwargs)
299+
288300

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

tests/test_cliutils_progressbar.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#
2+
# Copyright (c) nexB Inc. and others. All rights reserved.
3+
# SPDX-License-Identifier: Apache-2.0
4+
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
5+
# See https://github.com/nexB/commoncode for support or download.
6+
# See https://aboutcode.org for more information about nexB OSS projects.
7+
#
8+
9+
import os
10+
11+
from commoncode.testcase import FileDrivenTesting
12+
from commoncode.cliutils import progressmanager
13+
14+
class TestProgressBar(FileDrivenTesting):
15+
16+
test_data_dir = os.path.join(os.path.dirname(__file__), 'data')
17+
18+
def test_progressmanager_works(self):
19+
iterable = range(10)
20+
with progressmanager(iterable) as it:
21+
for _ in it:
22+
pass
23+
24+
def test_progressmanager_verbose(self):
25+
iterable = range(10)
26+
with progressmanager(iterable, verbose=True) as it:
27+
for _ in it:
28+
pass

0 commit comments

Comments
 (0)