diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 07620e3..5365571 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,13 +8,14 @@ on: jobs: test: - name: Python ${{ matrix.python }} + name: Build (Python ${{ matrix.python }}) runs-on: ubuntu-latest 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: diff --git a/.github/workflows/install.yml b/.github/workflows/install.yml new file mode 100644 index 0000000..f3c1a2d --- /dev/null +++ b/.github/workflows/install.yml @@ -0,0 +1,40 @@ +name: Install Test + +on: + pull_request: + push: + branches: + - main + +jobs: + test: + name: Install (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@v4 + + - 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 + sed -i "s|sudo raspi-config|raspi-config|g" pyproject.toml + touch raspi-config + chmod +x raspi-config + echo `pwd` >> $GITHUB_PATH + + - name: Run install.sh + run: | + ./install.sh --unstable --force 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 6f8cff7..9e29cb9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,15 +8,17 @@ on: jobs: test: - name: Python ${{ matrix.python }} + name: Test (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 + uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python }} uses: actions/setup-python@v5 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 diff --git a/pyproject.toml b/pyproject.toml index c2a6186..b477b15 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] @@ -108,6 +112,6 @@ ignore = [ ] [tool.pimoroni] -apt_packages = ["git"] +apt_packages = [] configtxt = [] -commands = ["false"] +commands = [] 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