Skip to content

Commit

Permalink
Flet new packages structure and flet build v2 (#4122)
Browse files Browse the repository at this point in the history
  • Loading branch information
FeodorFitsner authored Oct 9, 2024
1 parent fb0d037 commit 6811d6f
Show file tree
Hide file tree
Showing 112 changed files with 2,158 additions and 1,594 deletions.
319 changes: 215 additions & 104 deletions .appveyor.yml

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
30 changes: 30 additions & 0 deletions ci/common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
export root=$APPVEYOR_BUILD_FOLDER
export flet_sdk_root=$root/sdk/python
echo "flet_sdk_root: $flet_sdk_root"

python --version
pip install --upgrade setuptools wheel twine poetry tomlkit virtualenv

function patch_python_package_versions() {
PYPI_VER="${APPVEYOR_BUILD_VERSION/+/.dev}"
sed -i -e "s/version = \"\"/version = \"$PYPI_VER\"/g" $flet_sdk_root/packages/flet-core/src/flet_core/version.py
python3 $root/ci/patch_toml_versions.py $flet_sdk_root/packages/flet/pyproject.toml $PYPI_VER
python3 $root/ci/patch_toml_versions.py $flet_sdk_root/packages/flet-cli/pyproject.toml $PYPI_VER
python3 $root/ci/patch_toml_versions.py $flet_sdk_root/packages/flet-core/pyproject.toml $PYPI_VER
python3 $root/ci/patch_toml_versions.py $flet_sdk_root/packages/flet-desktop/pyproject.toml $PYPI_VER
python3 $root/ci/patch_toml_versions.py $flet_sdk_root/packages/flet-web/pyproject.toml $PYPI_VER
}

function patch_flet_desktop_package_name() {
python3 $root/ci/patch_toml_package_name.py $flet_sdk_root/packages/flet-desktop/pyproject.toml $1
}

function publish_to_pypi() {
if [[ ("$APPVEYOR_REPO_BRANCH" == "main" || "$APPVEYOR_REPO_TAG_NAME" != "") && "$APPVEYOR_PULL_REQUEST_NUMBER" == "" ]]; then
twine upload "$@"
elif [[ "$APPVEYOR_PULL_REQUEST_NUMBER" == "" ]]; then
for wheel in "$@"; do
curl -F package=@$wheel https://$GEMFURY_TOKEN@push.fury.io/flet/
done
fi
}
File renamed without changes.
7 changes: 0 additions & 7 deletions ci/install_go.ps1

This file was deleted.

11 changes: 0 additions & 11 deletions ci/install_go.sh

This file was deleted.

2 changes: 0 additions & 2 deletions ci/install_goreleaser.sh

This file was deleted.

25 changes: 25 additions & 0 deletions ci/patch_toml_package_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import os
import pathlib
import sys

import tomlkit

if len(sys.argv) < 2:
print("Specify toml file and a new package name")
sys.exit(1)

current_dir = pathlib.Path(os.getcwd())
toml_path = current_dir.joinpath(current_dir, sys.argv[1])
package_name = sys.argv[2]
print(f"Patching TOML file {toml_path} to {package_name}")

# read
with open(toml_path, "r") as f:
t = tomlkit.parse(f.read())

# patch name
t["tool"]["poetry"]["name"] = package_name

# save
with open(toml_path, "w") as f:
f.write(tomlkit.dumps(t))
21 changes: 15 additions & 6 deletions sdk/python/patch_toml.py → ci/patch_toml_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,21 @@

# patch dependencies
deps = t["tool"]["poetry"]["dependencies"]
if deps.get("flet-core"):
deps["flet-core"] = ver
if deps.get("flet-runtime"):
deps["flet-runtime"] = ver
if deps.get("flet"):
deps["flet"] = ver


def patch_dep(dep_name):
if deps.get(dep_name):
if isinstance(deps[dep_name], dict):
deps[dep_name]["version"] = ver
else:
deps[dep_name] = ver


patch_dep("flet-core")
patch_dep("flet-cli")
patch_dep("flet-desktop")
patch_dep("flet-web")
patch_dep("flet")

# save
with open(toml_path, "w") as f:
Expand Down
45 changes: 45 additions & 0 deletions ci/update-flet-wheel-deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash

# find wheel
wheel=$(realpath $(find $1 -maxdepth 1 -name "flet-*.whl"))

# Check if a file was found
if [ -z "$wheel" ]; then
echo "No file found matching the pattern flet-*.whl"
else
echo "Found file: $wheel"
fi

version=$(echo "$wheel" | sed -E 's/.*-([0-9]+[^-]+)-.*/\1/')
echo "$version"

# Define temporary directory and file
tmp_dir=$(mktemp -d)

# Unpack the wheel file
python -m wheel unpack --dest $tmp_dir $wheel

# get unpacked wheel dir
wheel_dir=$(realpath $(find $tmp_dir -maxdepth 1 -name "flet-*"))
echo "wheel temp dir: $wheel_dir"

pushd $wheel_dir

# process metadata
for metadata_file in *.dist-info/METADATA; do
# Replace the condition in METADATA
sed -i "/^Requires-Dist: flet-desktop /a Requires-Dist: flet-desktop-light (==$version) ; platform_system == 'Linux' and 'embedded' not in platform_version" "$metadata_file"
sed -i "s/platform_system != \"desktop-light\"/(platform_system == 'Darwin' or platform_system == 'Windows') and 'embedded' not in platform_version/g" "$metadata_file"
sed -i "s/platform_system != \"embedded\"/(platform_system == 'Darwin' or platform_system == 'Linux' or platform_system == 'Windows') and 'embedded' not in platform_version/g" "$metadata_file"
cat $metadata_file
done

# Repack the wheel
rm $wheel
python -m wheel pack --dest-dir $(dirname $wheel) .

# Cleanup temporary directory
popd
rm -rf "$tmp_dir"

echo "Successfully updated flet-*.whl with platform-specific dependencies."
16 changes: 13 additions & 3 deletions client/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import 'dart:io';

import 'package:flet/flet.dart';
// --FAT_CLIENT_START--
import 'package:flet_audio/flet_audio.dart' as flet_audio;
// --FAT_CLIENT_END--
import 'package:flet_audio_recorder/flet_audio_recorder.dart'
as flet_audio_recorder;
import "package:flet_flashlight/flet_flashlight.dart" as flet_flashlight;
import 'package:flet_geolocator/flet_geolocator.dart' as flet_geolocator;
import 'package:flet_lottie/flet_lottie.dart' as flet_lottie;
import 'package:flet_map/flet_map.dart' as flet_map;
import 'package:flet_permission_handler/flet_permission_handler.dart' as flet_permission_handler;
import 'package:flet_permission_handler/flet_permission_handler.dart'
as flet_permission_handler;
import 'package:flet_rive/flet_rive.dart' as flet_rive;
// --FAT_CLIENT_START--
import 'package:flet_video/flet_video.dart' as flet_video;
// --FAT_CLIENT_END--
import 'package:flet_webview/flet_webview.dart' as flet_webview;
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
Expand All @@ -27,14 +32,17 @@ void main([List<String>? args]) async {
await setupDesktop();

WidgetsFlutterBinding.ensureInitialized();

// --FAT_CLIENT_START--
flet_audio.ensureInitialized();
flet_video.ensureInitialized();
// --FAT_CLIENT_END--
flet_audio_recorder.ensureInitialized();
flet_geolocator.ensureInitialized();
flet_permission_handler.ensureInitialized();
flet_lottie.ensureInitialized();
flet_map.ensureInitialized();
flet_rive.ensureInitialized();
flet_video.ensureInitialized();
flet_webview.ensureInitialized();
flet_flashlight.ensureInitialized();

Expand Down Expand Up @@ -94,14 +102,16 @@ void main([List<String>? args]) async {
assetsDir: assetsDir,
errorsHandler: errorsHandler,
createControlFactories: [
// --FAT_CLIENT_START--
flet_audio.createControl,
flet_video.createControl,
// --FAT_CLIENT_END--
flet_audio_recorder.createControl,
flet_geolocator.createControl,
flet_permission_handler.createControl,
flet_lottie.createControl,
flet_map.createControl,
flet_rive.createControl,
flet_video.createControl,
flet_webview.createControl,
flet_flashlight.createControl,
],
Expand Down
8 changes: 4 additions & 4 deletions client/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -941,18 +941,18 @@ packages:
dependency: transitive
description:
name: rive
sha256: "23ffbeb1d45956b2d5ecd4b2c2d3bae2e61bc32b61fc2e9a48021e28feab6b5f"
sha256: ec44b6cf7341e21727c4b0e762f4ac82f9a45f7e52df3ebad2d1289a726fbaaf
url: "https://pub.dev"
source: hosted
version: "0.13.0"
version: "0.13.1"
rive_common:
dependency: transitive
description:
name: rive_common
sha256: "3fcaa47dd20dde59d197fc71dce174ca0a7ce9083a0fb73cf457e2cd111b0bbc"
sha256: "0f070bc0e764c570abd8b34d744ef30d1292bd4051f2e0951bbda755875fce6a"
url: "https://pub.dev"
source: hosted
version: "0.3.2"
version: "0.3.3"
safe_local_storage:
dependency: transitive
description:
Expand Down
6 changes: 4 additions & 2 deletions client/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@ dependencies:

flet:
path: ../packages/flet
# --FAT_CLIENT_START--
flet_audio:
path: ../packages/flet_audio
flet_video:
path: ../packages/flet_video
# --FAT_CLIENT_END--
flet_lottie:
path: ../packages/flet_lottie
flet_map:
Expand All @@ -47,8 +51,6 @@ dependencies:
path: ../packages/flet_permission_handler
flet_geolocator:
path: ../packages/flet_geolocator
flet_video:
path: ../packages/flet_video
flet_webview:
path: ../packages/flet_webview
flet_flashlight:
Expand Down
20 changes: 20 additions & 0 deletions client/web/flutter_bootstrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{{flutter_js}}
{{flutter_build_config}}

var loading = document.querySelector('#loading');
_flutter.loader.load({
serviceWorkerSettings: {
serviceWorkerVersion: {{flutter_service_worker_version}},
},
onEntrypointLoaded: async function (engineInitializer) {
loading.classList.add('main_done');
const appRunner = await engineInitializer.initializeEngine({useColorEmoji: useColorEmoji});

loading.classList.add('init_done');
await appRunner.runApp();

window.setTimeout(function () {
loading.remove();
}, 200);
}
});
34 changes: 1 addition & 33 deletions client/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@
<!-- useColorEmoji -->

<!-- pyodideCode -->

<script>
// The value below is injected by flutter build, do not touch.
var serviceWorkerVersion = null;
</script>
<!-- This script adds the flutter initialization JS code -->
<script src="flutter.js" defer></script>
</head>

<body>
Expand Down Expand Up @@ -101,31 +94,6 @@
</style>
<img src="icons/loading-animation.png" alt="Loading..." />
</div>
<script>
window.addEventListener('load', function () {
var loading = document.querySelector('#loading');
_flutter.loader.loadEntrypoint({
serviceWorker: {
serviceWorkerVersion: serviceWorkerVersion,
}
}).then(function (engineInitializer) {
loading.classList.add('main_done');
return engineInitializer.initializeEngine({
renderer: webRenderer,
useColorEmoji: useColorEmoji,
});
}).then(function (appRunner) {
loading.classList.add('init_done');
return appRunner.runApp();
}).then(function (app) {
// Wait a few milliseconds so users can see the "zoooom" animation
// before getting rid of the "loading" div.
window.setTimeout(function () {
loading.remove();
}, 200);
});
});
</script>
<script src="flutter_bootstrap.js" async></script>
</body>

</html>
2 changes: 1 addition & 1 deletion packages/flet_rive/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dependencies:
sdk: flutter

collection: ^1.16.0
rive: ^0.13.0
rive: 0.13.1

flet:
path: ../flet/
Expand Down
10 changes: 0 additions & 10 deletions sdk/python/build-pyodide.cmd

This file was deleted.

17 changes: 17 additions & 0 deletions sdk/python/packages/flet-cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Flet CLI

Flet CLI is a command-line interface tool for Flet, a framework for building interactive multi-platform applications using Python.

## Features

- Create new Flet projects
- Run Flet applications
- Package and deploy Flet apps

## Basic Usage

To create a new Flet project:

```
flet create myapp
```
Loading

0 comments on commit 6811d6f

Please sign in to comment.