From aa387fe70f4186fe42a6f2c15a040cfb6f09609a Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Thu, 27 Jun 2024 10:24:51 +0100 Subject: [PATCH 1/8] Defer to .txt files for requirements. These are easier for a user to read and/or install separately with pip. --- pyproject.toml | 10 +++++++--- requirements-dev.txt | 1 + requirements-examples.txt | 0 tox.ini | 9 +-------- 4 files changed, 9 insertions(+), 11 deletions(-) create mode 100644 requirements-examples.txt diff --git a/pyproject.toml b/pyproject.toml index c2a6186..b1c60e1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,10 +1,10 @@ [build-system] -requires = ["hatchling", "hatch-fancy-pypi-readme"] +requires = ["hatchling", "hatch-fancy-pypi-readme", "hatch-requirements-txt"] build-backend = "hatchling.build" [project] name = "PROJECT_NAME" -dynamic = ["version", "readme"] +dynamic = ["version", "readme", "optional-dependencies"] description = "__DESCRIPTION__" license = {file = "LICENSE"} requires-python = ">= 3.7" @@ -36,6 +36,9 @@ classifiers = [ ] dependencies = [] +[tool.hatch.metadata.hooks.requirements_txt.optional-dependencies] +example-depends = ["requirements-examples.txt"] + [project.urls] GitHub = "https://www.github.com/pimoroni/PROJECT_NAME-python" Homepage = "https://www.pimoroni.com" @@ -48,7 +51,8 @@ include = [ "PROJECT_NAME", "README.md", "CHANGELOG.md", - "LICENSE" + "LICENSE", + "requirements-examples.txt" ] [tool.hatch.build.targets.sdist] diff --git a/requirements-dev.txt b/requirements-dev.txt index 525b042..d392e8f 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -5,5 +5,6 @@ isort twine hatch hatch-fancy-pypi-readme +hatch-requirements-txt tox pdoc diff --git a/requirements-examples.txt b/requirements-examples.txt new file mode 100644 index 0000000..e69de29 diff --git a/tox.ini b/tox.ini index 4726cef..2b6d87b 100644 --- a/tox.ini +++ b/tox.ini @@ -23,12 +23,5 @@ commands = ruff check . codespell . deps = - check-manifest - ruff - codespell - isort - twine - build - hatch - hatch-fancy-pypi-readme + -r{toxinidir}/requirements-dev.txt From 3e13e0b89f95a49abed3552b0f9892d32383c887 Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Thu, 27 Jun 2024 10:39:39 +0100 Subject: [PATCH 2/8] CI: Stub tools and run installer. Run a basic check that install.sh --unstable completes without errors. --- .github/workflows/install.yml | 39 +++++++++++++++++++++++++++++++++++ pyproject.toml | 4 ++-- 2 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/install.yml diff --git a/.github/workflows/install.yml b/.github/workflows/install.yml new file mode 100644 index 0000000..a32ce66 --- /dev/null +++ b/.github/workflows/install.yml @@ -0,0 +1,39 @@ +name: Install Test + +on: + pull_request: + push: + branches: + - main + +jobs: + test: + name: Python ${{ matrix.python }} + runs-on: ubuntu-latest + env: + TERM: xterm-256color + strategy: + matrix: + python: ['3.9', '3.10', '3.11'] + + steps: + - name: Checkout Code + uses: actions/checkout@v3 + + - name: Set up Python ${{ matrix.python }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python }} + + - name: Stub files & Patch install.sh + run: | + mkdir -p boot/firmware + touch boot/firmware/config.txt + sed -i "s|/boot/firmware|`pwd`/boot/firmware|g" install.sh + touch raspi-config + chmod +x raspi-config + echo `pwd` >> $GITHUB_PATH + + - name: Run Tests + run: | + ./install.sh --unstable --force diff --git a/pyproject.toml b/pyproject.toml index b1c60e1..b477b15 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -112,6 +112,6 @@ ignore = [ ] [tool.pimoroni] -apt_packages = ["git"] +apt_packages = [] configtxt = [] -commands = ["false"] +commands = [] From 18bed16caed1c637e1037ba999c17c5141a8f73f Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Thu, 27 Jun 2024 11:01:29 +0100 Subject: [PATCH 3/8] CI: Set TERM in workflows. --- .github/workflows/build.yml | 2 ++ .github/workflows/test.yml | 2 ++ 2 files changed, 4 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 07620e3..976fee2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,6 +10,8 @@ jobs: test: name: Python ${{ matrix.python }} runs-on: ubuntu-latest + env: + TERM: xterm-256color strategy: matrix: python: ['3.9', '3.10', '3.11'] diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6f8cff7..170a4a7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,6 +10,8 @@ jobs: test: name: Python ${{ matrix.python }} runs-on: ubuntu-latest + env: + TERM: xterm-256color strategy: matrix: python: ['3.9', '3.10', '3.11'] From 34302e5e02577eeaa697ee977407a79502564caa Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Thu, 27 Jun 2024 11:06:06 +0100 Subject: [PATCH 4/8] CI: Clean up job names. --- .github/workflows/build.yml | 2 +- .github/workflows/install.yml | 4 ++-- .github/workflows/qa.yml | 2 +- .github/workflows/test.yml | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 976fee2..99fdeab 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,7 +8,7 @@ on: jobs: test: - name: Python ${{ matrix.python }} + name: Build (Python ${{ matrix.python }}) runs-on: ubuntu-latest env: TERM: xterm-256color diff --git a/.github/workflows/install.yml b/.github/workflows/install.yml index a32ce66..e01c20f 100644 --- a/.github/workflows/install.yml +++ b/.github/workflows/install.yml @@ -8,7 +8,7 @@ on: jobs: test: - name: Python ${{ matrix.python }} + name: Install (Python ${{ matrix.python }}) runs-on: ubuntu-latest env: TERM: xterm-256color @@ -18,7 +18,7 @@ jobs: steps: - name: Checkout Code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python }} uses: actions/setup-python@v5 diff --git a/.github/workflows/qa.yml b/.github/workflows/qa.yml index ac672a5..2e166c0 100644 --- a/.github/workflows/qa.yml +++ b/.github/workflows/qa.yml @@ -8,7 +8,7 @@ on: jobs: test: - name: linting & spelling + name: Linting & Spelling runs-on: ubuntu-latest env: TERM: xterm-256color diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 170a4a7..9e29cb9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,7 +8,7 @@ on: jobs: test: - name: Python ${{ matrix.python }} + name: Test (Python ${{ matrix.python }}) runs-on: ubuntu-latest env: TERM: xterm-256color @@ -18,7 +18,7 @@ jobs: steps: - name: Checkout Code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python }} uses: actions/setup-python@v5 From 9596ed52c06c1133bfa7107b20e6ebd4787f6d87 Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Thu, 27 Jun 2024 11:10:34 +0100 Subject: [PATCH 5/8] CI: Patch out sudo from raspi-config calls. --- .github/workflows/install.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/install.yml b/.github/workflows/install.yml index e01c20f..e65fee3 100644 --- a/.github/workflows/install.yml +++ b/.github/workflows/install.yml @@ -30,6 +30,7 @@ jobs: mkdir -p boot/firmware touch boot/firmware/config.txt sed -i "s|/boot/firmware|`pwd`/boot/firmware|g" install.sh + sed -i "s|sudo raspi-config|raspi-config|g" pyproject.toml touch raspi-config chmod +x raspi-config echo `pwd` >> $GITHUB_PATH From 1a8c7ff9525fbb57cbe23bc1fdd346c24a8c23ba Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Thu, 27 Jun 2024 11:11:42 +0100 Subject: [PATCH 6/8] CI: install.yml: rename install step. --- .github/workflows/install.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/install.yml b/.github/workflows/install.yml index e65fee3..f3c1a2d 100644 --- a/.github/workflows/install.yml +++ b/.github/workflows/install.yml @@ -35,6 +35,6 @@ jobs: chmod +x raspi-config echo `pwd` >> $GITHUB_PATH - - name: Run Tests + - name: Run install.sh run: | ./install.sh --unstable --force From dcf73c78d95cbdc14460487b58a6aa0a0b32d96f Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Tue, 18 Jun 2024 13:34:04 +0100 Subject: [PATCH 7/8] install.sh: check for and install requirements-examples.txt. --- README.md | 4 ++-- boilerplate.md | 8 ++++++++ install.sh | 15 +++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 140eee7..4652f1b 100644 --- a/README.md +++ b/README.md @@ -66,5 +66,5 @@ You can optionally run `sudo raspi-config` or the graphical Raspberry Pi Configu Some of the examples have additional dependencies. You can install them with: ```bash -pip install -``` \ No newline at end of file +pip install -r requirements-examples.txt +``` diff --git a/boilerplate.md b/boilerplate.md index 254b724..ba10e83 100644 --- a/boilerplate.md +++ b/boilerplate.md @@ -95,6 +95,14 @@ Press Ctrl+C to exit. """) ``` +If your examples need additional dependencies, then list them in: + +``` +requirements-examples.txt +``` + +Otherwise, just delete this file to avoid unnecessarily prompting the user. + ## Install / Uninstall Scripts If your package directory (`PROJECT_NAME/`) differs from your library name, you should update `install.sh` and `uninstall.sh` and hard-code the correct library name. diff --git a/install.sh b/install.sh index 3db90bc..61f1a4a 100755 --- a/install.sh +++ b/install.sh @@ -166,6 +166,12 @@ function pip_pkg_install { check_for_error } +function pip_requirements_install { + # A null Keyring prevents pip stalling in the background + PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring $PYTHON -m pip install -r "$@" + check_for_error +} + while [[ $# -gt 0 ]]; do K="$1" case $K in @@ -335,6 +341,15 @@ fi printf "\n" +if [ -f "requirements-examples.txt" ]; then + if confirm "Would you like to install example dependencies?"; then + inform "Installing dependencies from requirements-examples.txt..." + pip_requirements_install requirements-examples.txt + fi +fi + +printf "\n" + # Use pdoc to generate basic documentation from the installed module if confirm "Would you like to generate documentation?"; then From 5628cd34cac44fba32a6fc88d72043a372cd7858 Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Tue, 1 Oct 2024 10:32:25 +0100 Subject: [PATCH 8/8] CI: Fix duplicate ENV. --- .github/workflows/build.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 99fdeab..5365571 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,13 +10,12 @@ jobs: test: name: Build (Python ${{ matrix.python }}) runs-on: ubuntu-latest - env: - TERM: xterm-256color strategy: matrix: python: ['3.9', '3.10', '3.11'] env: + TERM: xterm-256color RELEASE_FILE: ${{ github.event.repository.name }}-${{ github.event.release.tag_name || github.sha }}-py${{ matrix.python }} steps: