From e8a2909173f96eb8916e892457aed1fc46a132e5 Mon Sep 17 00:00:00 2001 From: mkinney Date: Mon, 7 Mar 2022 21:25:42 -0800 Subject: [PATCH 1/5] Merge pull request #294 from mkinney/bug_when_ports_not_sorted fix when ports are not sorted --- examples/show_ports.py | 6 ++++++ meshtastic/tests/test_util.py | 19 +++++++++++++++++++ meshtastic/util.py | 1 + 3 files changed, 26 insertions(+) create mode 100644 examples/show_ports.py diff --git a/examples/show_ports.py b/examples/show_ports.py new file mode 100644 index 0000000..30c9cd9 --- /dev/null +++ b/examples/show_ports.py @@ -0,0 +1,6 @@ +"""Simple program to show serial ports. +""" + +from meshtastic.util import findPorts + +print(findPorts()) diff --git a/meshtastic/tests/test_util.py b/meshtastic/tests/test_util.py index 548efee..b04fd92 100644 --- a/meshtastic/tests/test_util.py +++ b/meshtastic/tests/test_util.py @@ -264,6 +264,22 @@ def test_findPorts_when_duplicate_found_and_duplicate_option_used(patch_comports patch_comports.assert_called() +@pytest.mark.unitslow +@patch('serial.tools.list_ports.comports') +def test_findPorts_when_duplicate_found_and_duplicate_option_used_ports_reversed(patch_comports): + """Test findPorts()""" + class TempPort: + """ temp class for port""" + def __init__(self, device=None, vid=None): + self.device = device + self.vid = vid + fake1 = TempPort('/dev/cu.usbserial-1430', vid='fake1') + fake2 = TempPort('/dev/cu.wchusbserial1430', vid='fake2') + patch_comports.return_value = [fake2, fake1] + assert findPorts(eliminate_duplicates=True) == ['/dev/cu.wchusbserial1430'] + patch_comports.assert_called() + + @pytest.mark.unitslow @patch('serial.tools.list_ports.comports') def test_findPorts_when_duplicate_found_and_duplicate_option_not_used(patch_comports): @@ -315,8 +331,11 @@ def test_eliminate_duplicate_port(): assert eliminate_duplicate_port(['/dev/fake', '/dev/fake1']) == ['/dev/fake', '/dev/fake1'] assert eliminate_duplicate_port(['/dev/fake', '/dev/fake1', '/dev/fake2']) == ['/dev/fake', '/dev/fake1', '/dev/fake2'] assert eliminate_duplicate_port(['/dev/cu.usbserial-1430', '/dev/cu.wchusbserial1430']) == ['/dev/cu.wchusbserial1430'] + assert eliminate_duplicate_port(['/dev/cu.wchusbserial1430', '/dev/cu.usbserial-1430']) == ['/dev/cu.wchusbserial1430'] assert eliminate_duplicate_port(['/dev/cu.SLAB_USBtoUART', '/dev/cu.usbserial-0001']) == ['/dev/cu.usbserial-0001'] + assert eliminate_duplicate_port(['/dev/cu.usbserial-0001', '/dev/cu.SLAB_USBtoUART']) == ['/dev/cu.usbserial-0001'] assert eliminate_duplicate_port(['/dev/cu.usbmodem11301', '/dev/cu.wchusbserial11301']) == ['/dev/cu.wchusbserial11301'] + assert eliminate_duplicate_port(['/dev/cu.wchusbserial11301', '/dev/cu.usbmodem11301']) == ['/dev/cu.wchusbserial11301'] @patch('platform.version', return_value='10.0.22000.194') @patch('platform.release', return_value='10') diff --git a/meshtastic/util.py b/meshtastic/util.py index 1931621..79cf36f 100644 --- a/meshtastic/util.py +++ b/meshtastic/util.py @@ -401,6 +401,7 @@ def eliminate_duplicate_port(ports): if len(ports) != 2: new_ports = ports else: + ports.sort() if 'usbserial' in ports[0] and 'wchusbserial' in ports[1]: first = ports[0].replace("usbserial-", "") second = ports[1].replace("wchusbserial", "") From 5590dbeb6f2859414ff6fdf773722b2153b1413c Mon Sep 17 00:00:00 2001 From: Mike Kinney Date: Mon, 7 Mar 2022 21:44:11 -0800 Subject: [PATCH 2/5] do not checkout the code again --- .github/workflows/release.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 77b0dd5..0b890e2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -45,9 +45,6 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Checkout - uses: actions/checkout@v2 - - name: Set up Python 3.9 uses: actions/setup-python@v2 with: From e6999ba5ad9f276e39f39eac736e1ccc63f90092 Mon Sep 17 00:00:00 2001 From: Mike Kinney Date: Mon, 7 Mar 2022 21:59:46 -0800 Subject: [PATCH 3/5] keep sha ref and use it for subsequent checkouts --- .github/workflows/release.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0b890e2..f9b5880 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -8,6 +8,7 @@ jobs: outputs: version: ${{ steps.get_version.outputs.version }} upload_url: ${{ steps.create_release.outputs.upload_url }} + new_sha: ${{ steps.commit_updated.outputs.sha }} steps: @@ -19,12 +20,14 @@ jobs: bin/bump_version.py - name: Commit updated version.py + id: commit_updated run: | git config --global user.name 'github-actions' git config --global user.email 'bot@noreply.github.com' git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }} git add setup.py git commit -m "bump version" && git push || echo "No changes to commit" + git log -n 1 --pretty=format:"%h" | tail -n 1 | awk '{print "::set-output name=sha::"$0}' - name: Get version id: get_version @@ -80,6 +83,8 @@ jobs: - name: Checkout uses: actions/checkout@v2 + with: + ref: ${{ needs.release_create.outputs.new_sha }} - name: Set up Python 3.9 uses: actions/setup-python@v2 @@ -125,6 +130,8 @@ jobs: - name: Checkout uses: actions/checkout@v2 + with: + ref: ${{ needs.release_create.outputs.new_sha }} - name: Set up Python 3.9 uses: actions/setup-python@v2 @@ -165,6 +172,8 @@ jobs: - name: Checkout uses: actions/checkout@v2 + with: + ref: ${{ needs.release_create.outputs.new_sha }} - name: Set up Python 3.9 uses: actions/setup-python@v2 From c01617652098de24e19e250495c65fbe7a97ad5a Mon Sep 17 00:00:00 2001 From: mkinney Date: Mon, 7 Mar 2022 22:16:03 -0800 Subject: [PATCH 4/5] Update release.yml --- .github/workflows/release.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f9b5880..6d6d96e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -27,7 +27,7 @@ jobs: git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }} git add setup.py git commit -m "bump version" && git push || echo "No changes to commit" - git log -n 1 --pretty=format:"%h" | tail -n 1 | awk '{print "::set-output name=sha::"$0}' + git log -n 1 --pretty=format:"%H" | tail -n 1 | awk '{print "::set-output name=sha::"$0}' - name: Get version id: get_version @@ -82,7 +82,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: ref: ${{ needs.release_create.outputs.new_sha }} @@ -129,7 +129,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: ref: ${{ needs.release_create.outputs.new_sha }} @@ -171,7 +171,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: ref: ${{ needs.release_create.outputs.new_sha }} From 3912f5728a95d26cc3376f701facf1ad20053151 Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 8 Mar 2022 06:40:00 +0000 Subject: [PATCH 5/5] bump version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index d64e9f2..f643790 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ with open("README.md", "r") as fh: # This call to setup() does all the work setup( name="meshtastic", - version="1.2.88", + version="1.2.89", description="Python API & client shell for talking to Meshtastic devices", long_description=long_description, long_description_content_type="text/markdown",