From 6ddea04a63c7a4e92cf79f459e1d01c6cb37ec58 Mon Sep 17 00:00:00 2001 From: Alan Davidson Date: Wed, 12 Feb 2025 16:00:29 -0500 Subject: [PATCH 1/7] add 'set -x' to build.sh, with a comment explaining all the options --- build.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/build.sh b/build.sh index bc268b9..b1a6ba2 100755 --- a/build.sh +++ b/build.sh @@ -1,7 +1,11 @@ #!/usr/bin/env bash # setup.sh -- environment bootstrapper for python virtualenv -set -euo pipefail +# x: print out commands as they are run +# e: exit on any failure +# u: using a nonexistent environment variable is an error +# o pipefail: in a pipeline, any intermediate step exiting with failure counts as an overall fail +set -xeuo pipefail SUDO=sudo if ! command -v $SUDO; then From e207c4a20e381bab5fb2a1581f6b52f6c935e968 Mon Sep 17 00:00:00 2001 From: Alan Davidson Date: Wed, 12 Feb 2025 16:13:58 -0500 Subject: [PATCH 2/7] add a make target to just build, without setting up from scratch --- Makefile | 12 ++++++++++-- build.sh | 4 ---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index cf6e874..c5c1624 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,18 @@ +# These targets do not construct files named after the target itself. Rerun them every time. +.PHONY: setup build test dist/main lint + setup: ./build.sh - + +build: dist/main + test: PYTHONPATH=./src pytest + +dist/main: + . .venv/bin/activate && python -m PyInstaller --onefile --hidden-import="googleapiclient" --add-data="./src:src" src/main.py -dist/archive.tar.gz: +dist/archive.tar.gz: dist/main tar -czvf dist/archive.tar.gz dist/main lint: diff --git a/build.sh b/build.sh index b1a6ba2..662422d 100755 --- a/build.sh +++ b/build.sh @@ -36,9 +36,5 @@ echo creating virtualenv at $VIRTUAL_ENV python3 -m venv $VIRTUAL_ENV echo installing dependencies from requirements.txt $VIRTUAL_ENV/bin/pip install -r requirements.txt -U -source $VIRTUAL_ENV/bin/activate -$PYTHON -m PyInstaller --onefile --hidden-import="googleapiclient" --add-data="./src:src" src/main.py # When running as a local module, we need meta.json to be in the same directory as the module. ln -sf ../meta.json dist -tar -czvf dist/archive.tar.gz dist/main - From 65b23efafa2ff048adf8e78212f197045dd853c9 Mon Sep 17 00:00:00 2001 From: Alan Davidson Date: Wed, 12 Feb 2025 16:33:07 -0500 Subject: [PATCH 3/7] source the venv for all commands that use it --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index c5c1624..d29e957 100644 --- a/Makefile +++ b/Makefile @@ -7,14 +7,14 @@ setup: build: dist/main test: - PYTHONPATH=./src pytest + . .venv/bin/activate && PYTHONPATH=./src pytest dist/main: . .venv/bin/activate && python -m PyInstaller --onefile --hidden-import="googleapiclient" --add-data="./src:src" src/main.py - + dist/archive.tar.gz: dist/main tar -czvf dist/archive.tar.gz dist/main lint: - pylint --disable=C0114,E0401,E1101,C0116,W0613,R0913,C0116,R0914,C0103,W0201,W0719 src/ + . .venv/bin/activate && pylint --disable=C0114,E0401,E1101,C0116,W0613,R0913,C0116,R0914,C0103,W0201,W0719 src/ From 44fb667f3331993a9f3439bebc556ccaf023a7d8 Mon Sep 17 00:00:00 2001 From: Alan Davidson Date: Wed, 12 Feb 2025 16:33:19 -0500 Subject: [PATCH 4/7] the default target should be the .tar.gz file --- Makefile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index d29e957..aa898c4 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,10 @@ # These targets do not construct files named after the target itself. Rerun them every time. .PHONY: setup build test dist/main lint +# This first target is the one that runs by default. +dist/archive.tar.gz: dist/main + tar -czvf dist/archive.tar.gz dist/main + setup: ./build.sh @@ -12,9 +16,6 @@ test: dist/main: . .venv/bin/activate && python -m PyInstaller --onefile --hidden-import="googleapiclient" --add-data="./src:src" src/main.py -dist/archive.tar.gz: dist/main - tar -czvf dist/archive.tar.gz dist/main - lint: . .venv/bin/activate && pylint --disable=C0114,E0401,E1101,C0116,W0613,R0913,C0116,R0914,C0103,W0201,W0719 src/ From 58d9f5b9ece29d444b0cadf04b5ee9db1466a4bd Mon Sep 17 00:00:00 2001 From: Alan Davidson Date: Wed, 12 Feb 2025 16:39:24 -0500 Subject: [PATCH 5/7] bugfix: construct the dist/ directory during setup even if we don't build everything then --- build.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build.sh b/build.sh index 662422d..ddafb5d 100755 --- a/build.sh +++ b/build.sh @@ -36,5 +36,7 @@ echo creating virtualenv at $VIRTUAL_ENV python3 -m venv $VIRTUAL_ENV echo installing dependencies from requirements.txt $VIRTUAL_ENV/bin/pip install -r requirements.txt -U + # When running as a local module, we need meta.json to be in the same directory as the module. +mkdir -p dist ln -sf ../meta.json dist From 014fa0832e7d7653e1049bdddb8602be5277925d Mon Sep 17 00:00:00 2001 From: Alan Davidson Date: Tue, 18 Feb 2025 15:20:18 -0500 Subject: [PATCH 6/7] run 'make setup' in github CI actions --- .github/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 79cd155..752203f 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -19,7 +19,7 @@ jobs: python --version pip install --upgrade pip pip --version - pip install -r requirements.txt + make setup - name: Run lint run: make lint From 671ed32916671f614126bf0a30d065ee8845bc45 Mon Sep 17 00:00:00 2001 From: Alan Davidson Date: Tue, 18 Feb 2025 15:22:05 -0500 Subject: [PATCH 7/7] rename build.sh -> setup.sh --- Makefile | 2 +- build.sh => setup.sh | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename build.sh => setup.sh (100%) diff --git a/Makefile b/Makefile index aa898c4..b3a56e3 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ dist/archive.tar.gz: dist/main tar -czvf dist/archive.tar.gz dist/main setup: - ./build.sh + ./setup.sh build: dist/main diff --git a/build.sh b/setup.sh similarity index 100% rename from build.sh rename to setup.sh