From 1e94d64123c54b791f84aeee2d4b739be896ff4d Mon Sep 17 00:00:00 2001 From: Kyle Laker Date: Sat, 28 Aug 2021 20:58:16 -0400 Subject: [PATCH 1/3] Remove unnecessary block We actually always want to ensure that the `finch.install_path` directory exists and now that we're using `checksum` on `get_url` that won't execute if the hash matches. We can then selectively unarchive the `zip` only when the download changed something. Even still, we may want to eventually consider always unarchiving. --- roles/finch/tasks/main.yml | 49 ++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/roles/finch/tasks/main.yml b/roles/finch/tasks/main.yml index a1a1c39a..4a7fc23f 100644 --- a/roles/finch/tasks/main.yml +++ b/roles/finch/tasks/main.yml @@ -1,31 +1,28 @@ --- # tasks file for Finch -- name: Check Finch - stat: - path: '{{ finch.zip }}' - register: st -- block: - - name: Create Finch directory - file: - path: '{{ finch.install_path }}' - state: directory - owner: root - group: root - mode: "0755" - - name: Fetch Finch zip - get_url: - url: '{{ finch.url }}' - dest: '{{ finch.zip }}' - checksum: 'sha1:{{ finch.hash }}' - force: yes - - name: Unpack Finch zip - unarchive: - dest: '{{ finch.install_path }}' - src: '{{ finch.zip }}' - owner: root - group: root - mode: "0755" - when: st.stat.checksum|default("") != finch.hash +- name: Create Finch directory + file: + path: '{{ finch.install_path }}' + state: directory + owner: root + group: root + mode: "0755" +- name: Fetch Finch zip + get_url: + url: '{{ finch.url }}' + dest: '{{ finch.zip }}' + checksum: 'sha1:{{ finch.hash }}' + force: yes + register: download_finch +- name: Unpack Finch zip + unarchive: + dest: '{{ finch.install_path }}' + src: '{{ finch.zip }}' + owner: root + group: root + mode: "0755" + # noqa no-handler + when: download_finch.changed - name: Install Finch udev rule copy: src: 55-finch.rules From 16d3c8b7f2bf4c18ae59c81c7e9ac8733ef95a66 Mon Sep 17 00:00:00 2001 From: Kyle Laker Date: Sat, 28 Aug 2021 21:00:01 -0400 Subject: [PATCH 2/3] Properly set PYTHONPATH and HIDAPI_LIB_PATH The contents that we're looking for are actually within the folder within the zip (FinchPython120). We add this as a new variable that's available (though it's rather unlikely to change) and use that for these two environment variables. --- roles/finch/tasks/main.yml | 8 ++++---- roles/finch/vars/main.yml | 3 +++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/roles/finch/tasks/main.yml b/roles/finch/tasks/main.yml index 4a7fc23f..29971db0 100644 --- a/roles/finch/tasks/main.yml +++ b/roles/finch/tasks/main.yml @@ -33,14 +33,14 @@ - name: Install Finch extra - dance2.py copy: src: dance2.py - dest: '{{ finch.install_path }}' + dest: '{{ finch.extract_base }}' owner: root group: root mode: "0644" - name: Install Finch extra - maze.py copy: src: maze.py - dest: '{{ finch.install_path }}' + dest: '{{ finch.extract_base }}' owner: root group: root mode: "0644" @@ -49,7 +49,7 @@ path: '{{ global_profile_path }}' marker: "## {mark} Finch profile entries ##" block: | - export HIDAPI_LIB_PATH={{ finch.install_path }} - export PYTHONPATH=$PYTHONPATH:{{ finch.install_path }} + export HIDAPI_LIB_PATH={{ finch.extract_base }} + export PYTHONPATH=$PYTHONPATH:{{ finch.extract_base }} notify: - Suggest restart diff --git a/roles/finch/vars/main.yml b/roles/finch/vars/main.yml index 8b2cfcdc..e1e8631c 100644 --- a/roles/finch/vars/main.yml +++ b/roles/finch/vars/main.yml @@ -5,3 +5,6 @@ finch: zip: '{{ global_base_path }}/FinchPython120.zip' hash: '841a7f7ca3a11678ecb6319e9983f87c57eb80da' install_path: '{{ global_base_path }}/FinchPython' + # The "root" of the zip file is a "FinchPython120" directory. This variable will + # need to be updated if the structure of the zip changes. + extract_base: '{{ global_base_path }}/FinchPython/FinchPython120' From c407ee677ab21515300e68338f11a15c00a93bce Mon Sep 17 00:00:00 2001 From: Kyle Laker Date: Sat, 28 Aug 2021 21:01:15 -0400 Subject: [PATCH 3/3] Remove the __pycache__ folder Recent versions of the zip file have created a __pycache__ directory that has `.pyc` files for `finch.py` and `finchconnection.py` for CPython 3.6 and 3.9; however, we really probably want to avoid having users actually use those .pyc files. --- roles/finch/tasks/main.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/roles/finch/tasks/main.yml b/roles/finch/tasks/main.yml index 29971db0..a8159ab8 100644 --- a/roles/finch/tasks/main.yml +++ b/roles/finch/tasks/main.yml @@ -23,6 +23,12 @@ mode: "0755" # noqa no-handler when: download_finch.changed +# Recent versions of the Finch zip file have mistakenly included the +# __pycache__ directory +- name: Delete Finch pycache + file: + path: '{{ finch.extract_base }}/__pycache__' + state: absent - name: Install Finch udev rule copy: src: 55-finch.rules