flet-dev / flet

Flet enables developers to easily build realtime web, mobile and desktop apps in Python. No frontend experience required.
https://flet.dev
Apache License 2.0
11.59k stars 454 forks source link

Flet new packages structure and `flet build` v2 #4122

Closed FeodorFitsner closed 1 month ago

FeodorFitsner commented 1 month ago

Closes #3839 Closes #3050

Summary by Sourcery

Revamp the Flet CLI with a new package structure and introduce version 2 of the flet build command. Add cross-platform permissions, support for compiling Python files, and deep linking configuration. Enhance the build and CI processes to support multiple platforms and Python 3.12, and improve security utilities. Update documentation with new README files for Flet packages.

New Features:

Enhancements:

Build:

CI:

Documentation:

Python 3.12

Closes #4007

Packaged Flet app runs on Python 3.12.6 runtime for all platforms.

New packages structure

Closes #3163 Closes #2637

The structure avoids rewriting pip dependencies while installing flet package on various platforms. There was a problem of detecting the correct flet package to install (flet-runtime, flet-embed orflet-pyodide?) if flet was not a direct dependency in user's app.

New Flet packages.

Faster re-builds

Closes #4036

Flutter app created by flet build command is not re-created all the time in a temp directory, but cached in build/flutter directory which gives faster re-builds, improves packaging troubleshooting and does not pollute temp directory.

Permissions

iOS

No more hard-coded permissions in Info.plist.

Setting iOS permissions:

flet build --info-plist permission_1=True|False|description permission_2=True|False|description ...

For example:

flet build --info-plist NSLocationWhenInUseUsageDescription=This app uses location service when in use.

macOS

No hard-coded entitlements in Release.entitlements.

Setting macOS entitlements:

flet build --macos-entitlements name_1=True|False name_2=True|False ...

Default macOS entitlements:

Android

No hard-coded permissions in AndroidManifest.xml.

Setting Android permissions and features:

flet build --android-permissions permission=True|False ... --android-features feature_name=True|False

For example:

flet build \
    --android-permissions android.permission.READ_EXTERNAL_STORAGE=True \
      android.permission.WRITE_EXTERNAL_STORAGE=True \
    --android-features android.hardware.location.network=False

Default Android permissions:

Default permissions can be disabled with --android-permissions option and False value, for example:

flet build --android-permissions android.permission.INTERNET=False

Default Android features:

Cross-platform permission groups

There are pre-defined permissions that mapped to Info.plist, *.entitlements and AndroidManifest.xml for respective platforms.

Setting cross-platform permissions:

flet build --permissions permission_1 permission_2 ...

Supported permissions:

iOS mapping to Info.plist entries

macOS mapping to entitlements

Android mappings

"Data" and "Temp" directories for the app

Closes #4114 Closes #2357

Flet developers have been asking where to store application data, such as uploaded files, SQLite databases, etc. that are persistent across application updates.

This release introduce two environment variables that are available in your Flet apps:

For example, data folder path can be read in your app as:

import os

# it's `None` when running the app in web mode
os.getenv("FLET_APP_DATA")

To make it work in development mode define those variables to suitable locations on your drive, for example:

export FLET_APP_DATA=/path/to/my-app/data
export FLET_APP_TEMP=$TMPDIR
flet run my-app

Deep linking support

Closes #4025

There is a new --deep-linking-url option to configure deep linking for iOS and Android builds. The value must be in the format <sheme>://<host>.

Other features and fixes

sourcery-ai[bot] commented 1 month ago

Reviewer's Guide by Sourcery

This pull request implements a significant restructuring of the Flet packages and introduces a new flet build v2 command. The changes include reorganizing the package structure, updating dependencies, modifying build processes, and adjusting how Flet components are imported and used across the project.

Sequence diagram for the new build process in flet_cli

sequenceDiagram
    participant User
    participant CLI as flet_cli
    participant Core as flet_core
    participant Desktop as flet_desktop
    participant Web as flet_web
    User->>CLI: Run flet build
    CLI->>Core: Initialize build environment
    CLI->>Desktop: Prepare desktop build
    CLI->>Web: Prepare web build
    CLI->>CLI: Execute build commands
    CLI->>User: Return build results

Architecture diagram for the new Flet package structure

graph TD;
    subgraph Flet
        subgraph CLI
            flet_cli --> flet_cli_commands
        end
        subgraph Core
            flet_core --> flet_core_utils
        end
        subgraph Desktop
            flet_desktop
        end
        subgraph Web
            flet_web
        end
    end
    flet_cli --> flet_core
    flet_cli --> flet_desktop
    flet_cli --> flet_web
    flet_desktop --> flet_core
    flet_web --> flet_core

Class diagram for the updated Command class in flet_cli

classDiagram
    class Command {
        -emojis: dict
        -dart_exe: Optional[str]
        -verbose: bool
        -build_dir: Optional[Path]
        -flutter_dir: Optional[Path]
        -flutter_exe: Optional[str]
        -platforms: dict
        -cross_platform_permissions: dict
        +add_arguments(parser: argparse.ArgumentParser) void
        +handle(options: argparse.Namespace) void
    }

File-Level Changes

Change Details Files
Restructured Flet packages
  • Created new packages: flet-cli, flet-desktop, and flet-web
  • Removed packages: flet-runtime, flet-embed, and flet-pyodide
  • Updated import statements across the project to reflect new package structure
  • Moved utility functions to more appropriate locations
sdk/python/packages/flet/src/flet/app.py
sdk/python/packages/flet/src/flet/security/__init__.py
sdk/python/packages/flet/src/flet/utils/__init__.py
sdk/python/packages/flet-core/src/flet_core/page.py
sdk/python/packages/flet-cli/src/flet_cli/cli.py
Implemented new flet build v2 command
  • Added support for building desktop and web applications
  • Introduced new command-line arguments for build customization
  • Implemented cross-platform permissions handling
  • Added support for compiling Python files to .pyc
sdk/python/packages/flet-cli/src/flet_cli/commands/build.py
Updated CI/CD pipeline
  • Modified AppVeyor configuration to support new package structure
  • Updated build and test processes for different platforms
  • Added new scripts for patching versions and publishing packages
.appveyor.yml
ci/common.sh
ci/update-flet-wheel-deps.sh
ci/patch_toml_versions.py
ci/patch_toml_package_name.py
Refactored client-side code
  • Updated Flutter dependencies and configurations
  • Modified how Flet components are initialized and used in the client
  • Introduced conditional compilation for different client types (desktop, web)
client/lib/main.dart
client/pubspec.yaml
client/web/index.html
client/web/flutter_bootstrap.js

Tips and commands #### Interacting with Sourcery - **Trigger a new review:** Comment `@sourcery-ai review` on the pull request. - **Continue discussions:** Reply directly to Sourcery's review comments. - **Generate a GitHub issue from a review comment:** Ask Sourcery to create an issue from a review comment by replying to it. - **Generate a pull request title:** Write `@sourcery-ai` anywhere in the pull request title to generate a title at any time. - **Generate a pull request summary:** Write `@sourcery-ai summary` anywhere in the pull request body to generate a PR summary at any time. You can also use this command to specify where the summary should be inserted. #### Customizing Your Experience Access your [dashboard](https://app.sourcery.ai) to: - Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others. - Change the review language. - Add, remove or edit custom review instructions. - Adjust other review settings. #### Getting Help - [Contact our support team](mailto:support@sourcery.ai) for questions or feedback. - Visit our [documentation](https://docs.sourcery.ai) for detailed guides and information. - Keep in touch with the Sourcery team by following us on [X/Twitter](https://x.com/SourceryAI), [LinkedIn](https://www.linkedin.com/company/sourcery-ai/) or [GitHub](https://github.com/sourcery-ai).
CodeOfHarald commented 1 month ago

Thanks for the new features :) @FeodorFitsner When can we expect a new release?

FeodorFitsner commented 1 month ago

Hopefully next week.