Skip to content

feat(build): cache flet-build-template.zip; share FLET_CACHE_DIR with Gradle#6558

Merged
FeodorFitsner merged 2 commits into
mainfrom
template-cache
Jun 6, 2026
Merged

feat(build): cache flet-build-template.zip; share FLET_CACHE_DIR with Gradle#6558
FeodorFitsner merged 2 commits into
mainfrom
template-cache

Conversation

@FeodorFitsner
Copy link
Copy Markdown
Contributor

@FeodorFitsner FeodorFitsner commented Jun 6, 2026

Summary

Fixes #6555flet debug android was re-downloading both flet-build-template.zip and the three python-android-dart-3.12-<abi>.tar.gz tarballs on every build. This PR is the CLI half; the Gradle half ships in flet-dev/serious-python#208 (serious_python_android 1.0.1).

  • Build template caching: the zip at the versioned release URL is immutable, so caching is a simple "use if present, else download once" via urllib + atomic .tmp + os.replace. cookiecutter is then handed the local zip path (it unpacks identically to a remote URL). Custom --template URLs and the local-dev template path are untouched — the cache layer only engages for the default versioned-release URL. The status message still prints the remote URL so users see what's being used; the per-project hash stamp also keys on the remote URL, not the machine-local path.
  • Shared cache root: the helper resolves $FLET_CACHE_DIR (or ~/.flet/cache) and exports it back to os.environ, so the Gradle child process inherits it and serious_python_android >= 1.0.1 lands its Python dist tarballs under the same root by default. No new flag needed.
  • serious_python pin bump in the bundled build template (1.0.01.0.1) so the Gradle-side caching from flet-dev/serious-python#208 is actually picked up.
  • New helper file: sdk/python/packages/flet-cli/src/flet_cli/utils/template_cache.py (~40 LOC, stdlib only, no new deps).

Test plan

  • Cold run: rm -rf ~/.flet/cache && flet debug android -vv against a sample app — confirm ~/.flet/cache/build-template/v<version>/flet-build-template.zip and ~/.flet/cache/python-build/v3.12/python-android-dart-3.12-*.tar.gz are created and the build succeeds.
  • Warm run: run the same command again — "Creating app shell" should complete in seconds (no network), and Gradle downloadDistArchive_* tasks should complete via 304 conditional GETs.
  • FLET_CACHE_DIR override: FLET_CACHE_DIR=/tmp/flet-cache flet debug android — confirm both the template zip and the three tarballs land under /tmp/flet-cache/.
  • Custom --template untouched: pass --template <some-git-url> — confirm the caching layer is not engaged and cookiecutter goes straight to the git URL as before.
  • Offline with warm cache: kill network — build should still succeed from cache.

Companion PR

Merge alongside flet-dev/serious-python#208 (release serious_python_android 1.0.1 with the matching Gradle-side caching).

🤖 Generated with Claude Code

Summary by Sourcery

Cache the default Android build template and unify the cache location with Gradle to speed up repeated builds and adopt the latest serious_python Android caching behavior.

New Features:

  • Introduce on-disk caching of the versioned default flet-build-template.zip so subsequent flet build / flet debug runs reuse a locally stored template instead of re-downloading it.

Enhancements:

  • Add a shared Flet cache root resolver that honors and sets FLET_CACHE_DIR, ensuring the CLI and Gradle-based Android tooling use the same cache directory for build artifacts.
  • Update the Android build template to depend on serious_python 1.0.1 so builds leverage its improved Python distribution caching and revalidation.

Documentation:

  • Document the new build template caching behavior and shared cache root in the changelog.

FeodorFitsner and others added 2 commits June 6, 2026 12:10
…CACHE_DIR with Gradle

Fixes #6555.

Add a small on-disk cache for the build template zip downloaded by
`flet build` / `flet debug`. The template at a versioned release URL
is immutable, so caching is "use if present, else download once" — no
revalidation needed. The download bypasses cookiecutter's network
fetch and writes to <cache>/build-template/v<flet-version>/flet-build-template.zip
via urllib + atomic .tmp + os.replace; cookiecutter then unpacks the
local zip path directly.

Cache root resolution: $FLET_CACHE_DIR if set, otherwise
~/.flet/cache. The resolved root is exported back into os.environ so
the Gradle child process (serious_python_android >= 1.0.1) lands its
Python dist tarballs under the same root by default, fixing the
multi-minute "downloadDistArchive_*" delay on every Android debug
build.

Bumps the bundled build template's serious_python pin from 1.0.0 to
1.0.1 so the new persistent Python-tarball cache + conditional-GET
revalidation in serious_python_android 1.0.1 is picked up. Custom
--template URLs and the local-dev template path are unchanged — the
cache layer only engages for the default versioned-release URL.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've reviewed this pull request using the Sourcery rules engine

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Jun 6, 2026

Deploying flet-website-v2 with  Cloudflare Pages  Cloudflare Pages

Latest commit: 50ef0d0
Status: ✅  Deploy successful!
Preview URL: https://10369a7c.flet-website-v2.pages.dev
Branch Preview URL: https://template-cache.flet-website-v2.pages.dev

View logs

@FeodorFitsner FeodorFitsner merged commit 93a4c27 into main Jun 6, 2026
45 checks passed
@FeodorFitsner FeodorFitsner deleted the template-cache branch June 6, 2026 20:11
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