From 778102712fe8f5f772ca10738e69421bbb8ac08f Mon Sep 17 00:00:00 2001 From: kaczmarczyck <43844792+kaczmarczyck@users.noreply.github.com> Date: Tue, 7 Nov 2023 05:13:21 +0100 Subject: [PATCH] venv for Python setup (#653) * Python uses venv * Small fixes to python calls --- .gitignore | 2 ++ deploy.py | 4 ++-- docs/boards/nrf52840_mdk.md | 2 +- docs/boards/nrf52840dk.md | 6 +++--- requirements.txt | 4 ++++ setup.sh | 7 +++++-- tools/authenticator_config.py | 1 - tools/configure.py | 2 +- tools/deploy_partition.py | 1 - tools/run_pylint.sh | 2 ++ tools/vendor_hid_test.py | 13 +++++++++++++ 11 files changed, 33 insertions(+), 11 deletions(-) mode change 100755 => 100644 tools/authenticator_config.py mode change 100755 => 100644 tools/deploy_partition.py diff --git a/.gitignore b/.gitignore index d380480d..fe6cf7aa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ libraries/**/Cargo.lock target/ +/build/ +/py_virtual_env/ # Local installation of elf2tab. /elf2tab/ diff --git a/deploy.py b/deploy.py index e198c492..8fad5a2c 100755 --- a/deploy.py +++ b/deploy.py @@ -1,5 +1,5 @@ -#!/usr/bin/env python3 -# Copyright 2019 Google LLC +#!py_virtual_env/bin/python3 +# Copyright 2019-2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/docs/boards/nrf52840_mdk.md b/docs/boards/nrf52840_mdk.md index 30d74b5b..f9630fcd 100644 --- a/docs/boards/nrf52840_mdk.md +++ b/docs/boards/nrf52840_mdk.md @@ -19,7 +19,7 @@ After general setup, you still need these steps: 1. Run the script: ```shell - python3 uf2conv.py -c -f 0xada52840 -o target/opensk.uf2 target/nrf52840_mdk_dfu_merged.hex + py_virtual_env/bin/python3 uf2conv.py -c -f 0xada52840 -o target/opensk.uf2 target/nrf52840_mdk_dfu_merged.hex ``` 1. Boot into DFU mode. Keep the user button pressed on your hardware while diff --git a/docs/boards/nrf52840dk.md b/docs/boards/nrf52840dk.md index b6027723..faef43d4 100644 --- a/docs/boards/nrf52840dk.md +++ b/docs/boards/nrf52840dk.md @@ -64,10 +64,10 @@ Afterwards, you can upgrade the other partition with ```shell # Board A -> B ./deploy.py --board=nrf52840dk_opensk_b --opensk --programmer=none --version=1 -python3 -m tools.deploy_partition --board=nrf52840dk_opensk_b --version=1 +py_virtual_env/bin/python3 -m tools.deploy_partition --board=nrf52840dk_opensk_b --version=1 # Board B -> A ./deploy.py --board=nrf52840dk_opensk_a --opensk --programmer=none --version=1 -python3 -m tools.deploy_partition --board=nrf52840dk_opensk_a --version=1 +py_virtual_env/bin/python3 -m tools.deploy_partition --board=nrf52840dk_opensk_a --version=1 ``` respectively. You can only upgrade the partition that is not currently running, @@ -81,5 +81,5 @@ for example: ```shell ./deploy.py --board=nrf52840dk_opensk_a --opensk --version=0 --vendor-hid ./deploy.py --board=nrf52840dk_opensk_b --opensk --programmer=none --version=1 --vendor-hid -python3 -m tools.deploy_partition --board=nrf52840dk_opensk_b --version=1 --vendor-hid +py_virtual_env/bin/python3 -m tools.deploy_partition --board=nrf52840dk_opensk_b --version=1 --vendor-hid ``` diff --git a/requirements.txt b/requirements.txt index d81909db..da13ac6d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,3 +8,7 @@ colorama tqdm cryptography fido2 >= 1.0.0 + +# Tests +pylint +hid diff --git a/setup.sh b/setup.sh index 360c16b4..ba0a7d67 100755 --- a/setup.sh +++ b/setup.sh @@ -16,6 +16,8 @@ # Ensure the script doesn't fail on Github workflows export TERM=${TERM:-vt100} done_text="$(tput bold)DONE.$(tput sgr0)" +PY_VENV_NAME=py_virtual_env +PIP="$PY_VENV_NAME"/bin/pip set -e @@ -31,7 +33,8 @@ check_command () { fi } check_command rustup " Follow the steps under https://rustup.rs/ to install it." -check_command pip3 +python3 -m venv "$PY_VENV_NAME" +check_command "$PIP" # Ensure we have certificates, keys, etc. so that the tests can run source tools/gen_key_materials.sh @@ -40,7 +43,7 @@ generate_crypto_materials N rustup show # Nightly is used for testing and fuzzing libraries rustup install nightly -pip3 install --upgrade -r requirements.txt +"$PIP" install --upgrade -r requirements.txt # Install dependency to create applications. mkdir -p elf2tab diff --git a/tools/authenticator_config.py b/tools/authenticator_config.py old mode 100755 new mode 100644 index ea137fe4..103b5e7a --- a/tools/authenticator_config.py +++ b/tools/authenticator_config.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python3 # Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tools/configure.py b/tools/configure.py index bd3ace3e..cfc0cb85 100755 --- a/tools/configure.py +++ b/tools/configure.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3 +#!py_virtual_env/bin/python3 # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tools/deploy_partition.py b/tools/deploy_partition.py old mode 100755 new mode 100644 index d33f6af3..d55bdf69 --- a/tools/deploy_partition.py +++ b/tools/deploy_partition.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python3 # Copyright 2020-2021 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tools/run_pylint.sh b/tools/run_pylint.sh index 58a7cb0e..2055078a 100755 --- a/tools/run_pylint.sh +++ b/tools/run_pylint.sh @@ -16,4 +16,6 @@ # Ensure we are at the project root directory cd $(readlink -f $(dirname $0))/.. +export PATH="py_virtual_env/bin:$PATH" + pylint --score=n `git ls-files --deduplicate --exclude-standard --full-name '*.py'` diff --git a/tools/vendor_hid_test.py b/tools/vendor_hid_test.py index 1bb19506..5c528af6 100644 --- a/tools/vendor_hid_test.py +++ b/tools/vendor_hid_test.py @@ -1,3 +1,16 @@ +# Copyright 2021-2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. """These tests verify the functionality of the VendorHID interface.""" import fido2 from fido2 import ctap