Skip to content

Commit cf23e0f

Browse files
authored
Use shutil.get_terminal_size (#558)
* Use shutil.get_terminal_size click.termui.get_terminal_size is no more. Resolves #529 * Add a test for the get_terminal_size import dance * Fix branch names in workflow * Add scheduled builds and 2 more Python versions * Switch import order around to avoid warning
1 parent 6aa31e8 commit cf23e0f

File tree

7 files changed

+34
-10
lines changed

7 files changed

+34
-10
lines changed

.github/workflows/tests.yaml

+5-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ name: "CI for v1"
33

44
on:
55
push:
6-
branches: ["master"]
6+
branches: ["v1"]
77
pull_request:
8-
branches: ["master"]
8+
branches: ["v1"]
9+
schedule:
10+
- cron: '0 0 * * 0'
911
workflow_dispatch:
1012

1113
jobs:
@@ -16,7 +18,7 @@ jobs:
1618
strategy:
1719
fail-fast: false
1820
matrix:
19-
python-version: ["2.7", "3.6", "3.7"]
21+
python-version: ["2.7", "3.6", "3.7", "3.8", "3.9"]
2022

2123
steps:
2224
- uses: "actions/checkout@v2"

CHANGES.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Changes.txt
22

3-
Next (TBD)
3+
1.4.10 (2022-05-18)
44

5+
- Fix: restore compatibility with click versions >= 8.1.0.
56
- Fix: handle FeedSource array in analytics API.
67

78
1.4.9 (2021-12-07)

planet/api/__version__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '1.4.9'
1+
__version__ = '1.4.10'

planet/scripts/util.py

+16-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@
3030
from planet import api
3131
from planet.api import filters
3232

33+
# get_terminal_size was removed from click.termui in click 8.1.0.
34+
# Previously, click delegated to shutil.get_terminal_size for Python
35+
# versions >= 3.3. This import dance allows us to *not* pin the Python
36+
# Client's click dependency for any version of Python.
37+
try:
38+
from shutil import get_terminal_size
39+
except ImportError:
40+
from click.termui import get_terminal_size
41+
3342

3443
def _split(value):
3544
'''return input split on any whitespace or comma'''
@@ -314,7 +323,7 @@ def _do_output(self):
314323
#
315324
# scrolling log output
316325
# ...
317-
width, height = click.termui.get_terminal_size()
326+
width, height = get_terminal_size()
318327
wrapper = textwrap.TextWrapper(width=width)
319328
self._stats['elapsed'] = '%d' % (time.time() - self._start)
320329
stats = ['%s: %s' % (k, v) for k, v in sorted(self._stats.items())]
@@ -337,7 +346,12 @@ def _do_output(self):
337346

338347
def downloader_output(dl, disable_ansi=False):
339348
thread = threading.current_thread()
340-
# do fancy output if we can or not explicitly disabled
349+
# Do fancy output if we can or not explicitly disabled.
350+
# Attention: the click project deprecated a method in its termui
351+
# module in 8.0.0 and removed it in 8.1.0. If support for v1 of the
352+
# Python client continues, we should keep an eye on termui's WIN
353+
# attribute, which looks like an incidental part of click's API
354+
# (it's not imported into click/__init__.py).
341355
if sys.stdout.isatty() and not disable_ansi and not termui.WIN:
342356
return AnsiOutput(thread, dl)
343357
# work around for lack of nice output for downloader on windows:

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
install_requires=[
7575
'click',
7676
'requests',
77-
'requests_futures == 0.9.7',
77+
'requests_futures',
7878
'pywin32 >= 1.0;platform_system=="Windows"'
7979
],
8080
extras_require={

tests/test_cli.py

+7
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,10 @@ def test_api_key_flag():
136136
run_cli(['-k', 'shazbot', 'help'])
137137
assert 'api_key' in cli.client_params
138138
assert cli.client_params['api_key'] == 'shazbot'
139+
140+
141+
def test_get_terminal_size():
142+
"""Check compatibility of get_terminal_size (see gh-529)."""
143+
columns, rows = util.get_terminal_size()
144+
assert isinstance(columns, int)
145+
assert isinstance(rows, int)

tox.ini

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tox]
2-
envlist = py27, py36, py37
2+
envlist = py27, py36
33

44
[gh-actions]
55
python =
@@ -14,4 +14,4 @@ python =
1414
deps = pytest
1515
commands =
1616
python -m pip install -e .[dev]
17-
python -m pytest -v -rxXs --doctest-modules --cov planet --cov-report term-missing planet tests
17+
python -Werror -m pytest -v -rxXs --doctest-modules --cov planet --cov-report term-missing planet tests

0 commit comments

Comments
 (0)