Exclude hidden entries, venvs and __pycache__ from flet build app package - #6890
Open
FeodorFitsner wants to merge 9 commits into
Open
FeodorFitsner wants to merge 9 commits into
FeodorFitsner wants to merge 9 commits into
Conversation
…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
Contributor
There was a problem hiding this comment.
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
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.
| self.package_app_path, app_include, explicit_excludes | ||
| ) | ||
|
|
||
| exclude_list = list(dict.fromkeys(explicit_excludes + default_excludes)) |
Deploying flet-website-v2 with
|
| 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 |
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.
…ludes # Conflicts: # CHANGELOG.md
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Fix #6839
Problem
flet buildcopied the whole app directory into the package, excluding onlybuild(andassetson 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 throughcompileall.Change
These are now excluded by default:
.on all platforms, plus entries with the hidden attribute on Windows. Hidden entries in subdirectories are still packaged.pyvenv.cfg(created byvenv,uv venvandvirtualenv), sovenv,envorsrc/.venvare caught whatever they're named.__pycache__directories at any depth.Implementation:
flet_cli/utils/app_excludes.py. It returnsos.sep-joined relative paths, which is the form serious_python'scopyDirectorycompares against, including on Windows.build, anything inexclude,assetson web), or folders it excludes itself.--excludelist, so serious_python needs no changes.New options (available on
flet buildandflet 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 overridebuild,assetsor the user'sexcludelist.--no-default-excludes/default_excludes = false: turn default exclusions off entirely.Reporting:
.envis left out, since apps that load it with python-dotenv at runtime would break.-v, the full exclude list and the compile/cleanup settings are logged.Docs: the "Excluding files and directories" section of
publish/index.mddocuments all of the above. Its example no longer recommends--exclude .git .venv.Behavior change
.envand 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:
flet publish, which already drops top-level dot-entries.--dry-runor packaging manifest.cleanup-appdefault.Testing
tests/test_app_excludes.pycovers:pyvenv.cfg__pycache__include, including/separatorsattrib +htest that only runs on Windowsflet build webon an app containing.venv,.flet,.env,__pycache__andpkg/__pycache__:app.zipcontains onlymain.pycandpkg/__init__.pyc.--include .envputs.envback.--no-default-excludesbrings.venvback.Summary by Sourcery
Prevent development artifacts from entering packaged apps by adding default exclusions and configurable overrides.
New Features:
Bug Fixes:
Enhancements:
Documentation:
Tests: