Skip to content

recipe-tester: support test-only deps via tests/requirements.txt#98

Merged
ndonkoHenri merged 1 commit into
mainfrom
test-requirements
Jul 7, 2026
Merged

recipe-tester: support test-only deps via tests/requirements.txt#98
ndonkoHenri merged 1 commit into
mainfrom
test-requirements

Conversation

@ndonkoHenri

Copy link
Copy Markdown

Motivation

The recipe-tester app installs flet + pytest + <recipe>, so the only third-party packages available on-device are the recipe's own Requires-Dist. That's fine for most recipes (numpy etc. come in transitively), but a zero-runtime-dep recipe can't exercise its integration paths on-device at all.

What changed

  • stage_recipe.sh: after staging tests, an optional recipes/<name>/tests/requirements.txt (one PEP 508 spec per line; blanks and #-comments skipped) is expanded into the generated pyproject.toml.
  • pyproject.toml.tpl: new __TEST_DEPS__ token line inside the dependencies array (replaced with zero or more dep lines — absent file emits nothing).
  • README.md: documents the convention, incl. the constraint that each test dep must be installable for the mobile target (pure-Python from PyPI, or a recipe already published on pypi.flet.dev / seeded via prebuild_recipes) — the same constraint a real app faces — and the guidance to prefer importorskip for genuinely-optional integrations.

Implementation notes

  • Template expansion is a bash line-loop with printf '%s' rather than sed: PEP 508 markers legitimately contain double quotes (numpy; python_version >= "3.10"), which have no safe portable sed-RHS escaping (BSD vs GNU).
  • Deps are emitted as TOML literal (single-quoted) strings so markers pass through verbatim; a single quote inside a spec is rejected with an explicit ::error::.
  • Token matches are exact-line, so template comments that merely mention a token pass through unexpanded.
  • Empty-array expansion is guarded (${arr[@]+...}) for macOS bash 3.2 under set -u, so the script keeps working for local devs on the system bash.
  • No behavior change when the file is absent: generated deps are identical to before (verified by TOML-parsing the output for a recipe without the file).

The tester app installs flet + pytest + the recipe's Requires-Dist only,
so a zero-runtime-dep recipe (safetensors) can't exercise integration
paths on-device — its numpy test could only ever skip. stage_recipe.sh
now expands an optional recipes/<name>/tests/requirements.txt (one
PEP 508 spec per line, comments/blanks skipped) into the generated
pyproject via a __TEST_DEPS__ token line in the template.

Template expansion is a bash line loop with printf rather than sed:
specs legitimately contain double quotes in markers, which have no safe
portable sed-RHS escaping. Deps are emitted as TOML literal strings, so
single quotes inside a spec are rejected with an error. Token matches
are exact-line, so comments mentioning a token pass through verbatim.
Empty-array expansion is guarded for macOS bash 3.2 under set -u.
@ndonkoHenri ndonkoHenri merged commit 63519d6 into main Jul 7, 2026
5 of 11 checks passed
@ndonkoHenri ndonkoHenri deleted the test-requirements branch July 7, 2026 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant