Skip to content

Exclude hidden entries, venvs and __pycache__ from flet build app package - #6890

Open
FeodorFitsner wants to merge 9 commits into
mainfrom
fix-build-default-excludes
Open

FeodorFitsner wants to merge 9 commits into
mainfrom
fix-build-default-excludes

Conversation

@FeodorFitsner

@FeodorFitsner FeodorFitsner commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Fix #6839

Problem

flet build copied the whole app directory into the package, excluding only build (and assets on web). When the app path is the project root, which is the layout used by the examples and Flet Studio, the package included .venv, .git, .flet (dev storage), IDE folders and __pycache__. The venv was even run through compileall.

Change

These are now excluded by default:

  • Hidden entries directly in the app path: names starting with . on all platforms, plus entries with the hidden attribute on Windows. Hidden entries in subdirectories are still packaged.
  • Virtual environments at any depth, detected by pyvenv.cfg (created by venv, uv venv and virtualenv), so venv, env or src/.venv are caught whatever they're named.
  • __pycache__ directories at any depth.

Implementation:

  • The scan lives in the new flet_cli/utils/app_excludes.py. It returns os.sep-joined relative paths, which is the form serious_python's copyDirectory compares against, including on Windows.
  • It never enters folders that are already excluded (build, anything in exclude, assets on web), or folders it excludes itself.
  • The results are merged into the existing --exclude list, so serious_python needs no changes.

New options (available on flet build and flet debug):

  • --include / [tool.flet(.<platform>).app] include: keep specific default-excluded entries, for example .env. This only undoes the new default exclusions; it does not override build, assets or the user's exclude list.
  • --no-default-excludes / default_excludes = false: turn default exclusions off entirely.

Reporting:

  • One line at normal verbosity lists what was left out.
  • A warning appears when .env is left out, since apps that load it with python-dotenv at runtime would break.
  • With -v, the full exclude list and the compile/cleanup settings are logged.

Docs: the "Excluding files and directories" section of publish/index.md documents all of the above. Its example no longer recommends --exclude .git .venv.

Behavior change

.env and other dot-prefixed files in the app root are no longer packaged. This is called out in the changelog with how to keep them.

Not in this PR

From the discussion in #6839:

  • Changes to flet publish, which already drops top-level dot-entries.
  • A --dry-run or packaging manifest.
  • Changing the cleanup-app default.

Testing

  • New tests/test_app_excludes.py covers:
    • hidden entries at the top level vs nested
    • venv detection with and without pyvenv.cfg
    • nested __pycache__
    • pruning of excluded folders
    • include, including / separators
    • skipping of already-excluded paths
    • the Windows hidden attribute: simulated on all platforms, plus a real attrib +h test that only runs on Windows
  • The full flet-cli suite passes.
  • End to end with flet build web on an app containing .venv, .flet, .env, __pycache__ and pkg/__pycache__:
    • The app part of app.zip contains only main.pyc and pkg/__init__.pyc.
    • --include .env puts .env back.
    • --no-default-excludes brings .venv back.

Summary by Sourcery

Prevent development artifacts from entering packaged apps by adding default exclusions and configurable overrides.

New Features:

  • Exclude top-level hidden entries, virtual environments, and pycache directories from app packages by default, with options to include selected paths or disable these exclusions.
  • Report default exclusions during packaging and warn when root-level .env files are omitted.

Bug Fixes:

  • Prevent development files and virtual environments from being copied into flet build and debug app packages.
  • Ensure empty platform-specific configuration values override global Flet settings instead of falling back to them.

Enhancements:

  • Centralize app exclusion discovery and platform-specific configuration resolution for build settings.

Documentation:

  • Document default app-package exclusions, inclusion overrides, disabling default exclusions, and platform-specific setting precedence.

Tests:

  • Add coverage for default exclusion discovery, include and exclude behavior, Windows hidden attributes, and platform-setting precedence.

…kage

flet build copied the whole app directory except build/, so apps whose
app path is the project root shipped .venv, .git, .flet (dev storage)
and __pycache__ to end users.

Exclude by default:
- hidden entries in the app root (leading dot on all platforms, plus the
  hidden attribute on Windows)
- virtual environments at any depth, detected by pyvenv.cfg
- __pycache__ directories at any depth

Add --include / [tool.flet.app] include to keep specific entries (e.g.
.env) and --no-default-excludes / default_excludes = false to opt out.
The build prints what was excluded, warns when .env is dropped, and
logs the full exclude list and cleanup settings with -v.

Fix #6839

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Packaging argument handling and remediation output contain correctness issues for valid filenames and configurations.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 3 Medium severity · 1 Low severity

Open (4)
What changed in this PR

Adds safer default exclusions when packaging Flet apps.

Changes:

  • Excludes hidden entries, virtual environments, and __pycache__.
  • Adds inclusion and opt-out configuration.
  • Adds tests, documentation, reporting, and changelog guidance.
File Description
CHANGELOG.md Documents the behavior change.
website/​docs/​publish/​index.md Explains exclusions and configuration.
tests/​test_app_excludes.py Tests exclusion discovery.
utils/​app_excludes.py Implements exclusion scanning.
commands/​build_base.py Integrates exclusions into packaging.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread sdk/python/packages/flet-cli/src/flet_cli/commands/build_base.py Outdated
self.package_app_path, app_include, explicit_excludes
)

exclude_list = list(dict.fromkeys(explicit_excludes + default_excludes))
Comment thread sdk/python/packages/flet-cli/src/flet_cli/commands/build_base.py
Comment thread sdk/python/packages/flet-cli/src/flet_cli/commands/build_base.py Outdated
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Deploying flet-website-v2 with  Cloudflare Pages  Cloudflare Pages

Latest commit: bbefd31
Status: ✅  Deploy successful!
Preview URL: https://840dd3a7.flet-website-v2.pages.dev
Branch Preview URL: https://fix-build-default-excludes.flet-website-v2.pages.dev

View logs

Platform-then-global lookups chained with `or`, so `[]` or `{}` under
[tool.flet.<platform>] fell through to [tool.flet]. Add
get_platform_setting(), which returns the platform value whenever it is
present, rebase get_bool_setting() on it, and use it for app.exclude,
app.include, source_packages, dev_packages, target_arch,
extract_packages, cleanup.app_files, cleanup.package_files and
flutter.build_args.

Scalar settings (org, bundle_id, artifact, splash colors) keep falling
back, since an empty string there is not a meaningful override.
File names are arbitrary, so a hidden entry with brackets in its name
could be swallowed as a style tag or raise MarkupError before
packaging.
The warning also fires for .env.* files, but always suggested including
.env. include matches exact paths, so following it left .env.local
excluded. List the actual files in both the CLI and pyproject.toml
suggestions.
…e per flag

serious_python 5.0.0 no longer splits --exclude, --cleanup-app-files and
--cleanup-package-files values on commas. Pass each path and glob as its
own option instead of comma-joining them, so a hidden file named
".a,main.py" no longer excludes main.py and brace globs like
**/{tests,docs} reach the cleanup step intact.
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.

flet build app packaging: incomplete default exclusions, and no way to see what was dropped

2 participants