From 3f9c7f0f9bd595fd167f3b7e8c70a9c7d4e4b279 Mon Sep 17 00:00:00 2001 From: Harrison Wright Date: Fri, 3 Mar 2023 13:47:03 -0600 Subject: [PATCH 1/8] Use github actions for test matrix (#11) * try github actions out * try click version matrix * Python 3.4+ * 3.8+ * add 3.7 * try 3.4 on 20.04 * 3.6 * try a different matrix * why wont this run * test actions again * add more versions * 8.1.4 is not relased yet * add more versions * iterate... * Add a py2 version * add more versions * update readme * Fix click-version typo --- .github/workflows/build.yaml | 48 ++++++++++++++++++++++++++++++++++++ README.md | 4 ++- 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/build.yaml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..08136d2 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,48 @@ +name: build and test + +on: [push] + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + matrix: + + python-version: [ + # "3.6", # TODO: Error: The version '3.6' with architecture 'x64' was not found for Ubuntu 22.04. + "3.7", + "3.8", + "3.9", + "3.10", + "3.11" + ] + click-version: [ + "5.1", + "6.7", + "7.0", + "7.1.2", + "8.0.4", + "8.1.3", + ] + exclude: + # click 8.1 drops support for py36 + - python-version: "3.6" + click-version: "8.1.3" + + + steps: + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + - name: Install package + run: | + python -m pip install --upgrade pip + pip install click==${{ matrix.click-version }} + python setup.py install + - name: Verify click version + run: pip freeze click + - name: Run tests + run: python -m unittest discover -v diff --git a/README.md b/README.md index 20c1775..1007cf9 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,9 @@ Installation pip install click-command-tree ``` -Tested against Python 3.4, 3.5, and 3.6 and click >= 5.0 +This is tested against Python versions 3.7 - 3.11 and (latest major release) click versions +5.x, 6.x, 7.x, 7.1.x, 8.0.x, and 8.1.x. + Example ------- From 27db7d4eb72d66e12b3909df4f29fb3b2c6d6dff Mon Sep 17 00:00:00 2001 From: Harrison Wright Date: Fri, 3 Mar 2023 13:50:43 -0600 Subject: [PATCH 2/8] Add correct output to README --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 1007cf9..2f627b2 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,5 @@ root ├── command-group │ └── nested-command ├── standard-command -└── tree - +└── tree - show the command tree of your CLI ``` From 428723464e174c3d264bebf487fd7456a9794f64 Mon Sep 17 00:00:00 2001 From: Harrison Wright Date: Mon, 6 Mar 2023 12:20:22 -0600 Subject: [PATCH 3/8] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 2f627b2..c6cd9b6 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,8 @@ click-command-tree `click-command-tree` is a [click](https://github.com/pallets/click) plugin to show the command tree of your CLI +[![build and test](https://github.com/whwright/click-command-tree/actions/workflows/build.yaml/badge.svg)](https://github.com/whwright/click-command-tree/actions/workflows/build.yaml) + Installation ------------ From a1fb8fc62a765233cfa851664b16dc82c334635d Mon Sep 17 00:00:00 2001 From: Harrison Wright Date: Mon, 6 Mar 2023 12:31:45 -0600 Subject: [PATCH 4/8] remove badge --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index c6cd9b6..2f627b2 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,6 @@ click-command-tree `click-command-tree` is a [click](https://github.com/pallets/click) plugin to show the command tree of your CLI -[![build and test](https://github.com/whwright/click-command-tree/actions/workflows/build.yaml/badge.svg)](https://github.com/whwright/click-command-tree/actions/workflows/build.yaml) - Installation ------------ From 1aa7610e57cdbdb6b00755a09ea89667fb216cf5 Mon Sep 17 00:00:00 2001 From: Harrison Wright Date: Sun, 24 Mar 2024 20:36:16 -0500 Subject: [PATCH 5/8] update test matrix (#13) * try new test matrix * install setuptools --- .github/workflows/build.yaml | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 08136d2..36b32d8 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -10,12 +10,11 @@ jobs: matrix: python-version: [ - # "3.6", # TODO: Error: The version '3.6' with architecture 'x64' was not found for Ubuntu 22.04. - "3.7", "3.8", "3.9", "3.10", - "3.11" + "3.11", + "3.12", ] click-version: [ "5.1", @@ -23,13 +22,8 @@ jobs: "7.0", "7.1.2", "8.0.4", - "8.1.3", + "8.1.7", ] - exclude: - # click 8.1 drops support for py36 - - python-version: "3.6" - click-version: "8.1.3" - steps: - uses: actions/checkout@v3 @@ -39,7 +33,7 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install package run: | - python -m pip install --upgrade pip + python -m pip install --upgrade pip setuptools pip install click==${{ matrix.click-version }} python setup.py install - name: Verify click version From 7f99e3421d32d8319eddabcf12fa09c686a966c6 Mon Sep 17 00:00:00 2001 From: Harrison Wright Date: Sun, 24 Mar 2024 20:38:00 -0500 Subject: [PATCH 6/8] Update readme and remove old script --- README.md | 2 +- test-versions.sh | 25 ------------------------- 2 files changed, 1 insertion(+), 26 deletions(-) delete mode 100755 test-versions.sh diff --git a/README.md b/README.md index 2f627b2..a1d5291 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Installation pip install click-command-tree ``` -This is tested against Python versions 3.7 - 3.11 and (latest major release) click versions +This is tested against Python versions 3.8 - 3.12 and (latest major release) click versions 5.x, 6.x, 7.x, 7.1.x, 8.0.x, and 8.1.x. diff --git a/test-versions.sh b/test-versions.sh deleted file mode 100755 index 0d3cebf..0000000 --- a/test-versions.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env bash - -set -o errexit - -finish() { - rm -rf testvenv* -} -trap finish EXIT - -pythons=("python3.4" "python3.5" "python3.6") -versions=("5.0" "5.1" "6.0" "6.1" "6.2" "6.3" "6.4" "6.5" "6.6" "6.7" "7.0") - -for python in ${pythons[@]}; do - for version in ${versions[@]}; do - version=$(echo ${version} | remove-quotes) - echo "trying ${python} ${version}" - - venv="testvenv-${python}-${version}" - virtualenv -p $(which ${python}) "${venv}" > /dev/null - "${venv}/bin/pip" install "click==${version}" > /dev/null - "${venv}/bin/python" -m unittest discover -v - done -done - -finish From 8af0531f484622498fac17befcb57dfec98fdb51 Mon Sep 17 00:00:00 2001 From: Harrison Wright Date: Sun, 24 Mar 2024 20:54:07 -0500 Subject: [PATCH 7/8] feat: strip and truncate doc strings (#14) * feat: strip and truncate doc strings * cleanup --- click_command_tree.py | 22 +++++++++++++++++++++- tests.py | 20 ++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/click_command_tree.py b/click_command_tree.py index b09e1a5..36151d2 100644 --- a/click_command_tree.py +++ b/click_command_tree.py @@ -45,7 +45,7 @@ def _print_tree(command, depth=0, is_last_item=False, is_last_parent=False): tree_item = '└── ' if is_last_item else '├── ' line = prefix * (depth - 1) + tree_item + command.name - doc = command.command.__doc__ + doc = _get_truncated_docstring(command.command) if doc: line += ' - {}'.format(doc) @@ -56,3 +56,23 @@ def _print_tree(command, depth=0, is_last_item=False, is_last_parent=False): depth=(depth + 1), is_last_item=(i == (len(command.children) - 1)), is_last_parent=is_last_item) + + +def _get_truncated_docstring(command): + doc = command.__doc__ + + if not doc: + return None + + lines = doc.split("\n") + if not lines: + return None + + for line in lines: + line = line.strip() + if not line: + continue + + return line[:80] + ' ...' if len(line) > 80 else line + + return None diff --git a/tests.py b/tests.py index 93e1cff..4eb2e2f 100644 --- a/tests.py +++ b/tests.py @@ -191,6 +191,26 @@ def command_three(): root ├── command-one └── command-three +"""[1:] + + self._assert_correct_output(root, expected_output) + + def test_long_docstring(self): + @click.group(name='root') + def root(): + pass + + @root.command(name='command') + def command(): + """ + this is a really long multi line doc string this is a really long multi line doc string + this is a really long multi line doc string this is a really long multi line doc string + """ + pass + + expected_output = """ +root +└── command - this is a really long multi line doc string this is a really long multi line doc ... """[1:] self._assert_correct_output(root, expected_output) From 55de0baad204be5363baff2d992bc7a4ddc4ce59 Mon Sep 17 00:00:00 2001 From: Harrison Wright Date: Sun, 24 Mar 2024 21:00:00 -0500 Subject: [PATCH 8/8] version 1.2.0 --- click_command_tree.py | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/click_command_tree.py b/click_command_tree.py index 36151d2..2357d45 100644 --- a/click_command_tree.py +++ b/click_command_tree.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- import click -__version__ = '1.1.0' +__version__ = '1.2.0' @click.command(name='tree') diff --git a/setup.py b/setup.py index 4e93004..d2b6f07 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ setup( name='click-command-tree', - version='1.1.1', + version='1.2.0', description='click plugin to show the command tree of your CLI', long_description=README, long_description_content_type='text/markdown',