Skip to content

v1: Migrated poetry to uv #5253

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 38 additions & 63 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ environment:
- job_name: Build Flet for web
job_group: build_flet
job_depends_on: build_flet_package
PYODIDE_URL: https://github.com/pyodide/pyodide/releases/download/0.27.5/pyodide-core-0.27.5.tar.bz2
APPVEYOR_BUILD_WORKER_IMAGE: ubuntu2004

- job_name: Test Python 3.10
Expand Down Expand Up @@ -162,9 +163,9 @@ for:
install:
- python --version
- pip3 install --upgrade setuptools wheel twine tomlkit
- ps: (Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | python -
- ps: Add-SessionPath "$HOME\AppData\Roaming\Python\Scripts"
- poetry --version
- ps: irm https://astral.sh/uv/install.ps1 | iex
- ps: Add-SessionPath "$HOME\.local\bin"
- uv --version
- dart pub global activate fvm
- set PATH=%LOCALAPPDATA%\Pub\Cache\bin;%USERPROFILE%\fvm\default\bin;%PATH%
- fvm install %FLUTTER_VERSION%
Expand Down Expand Up @@ -194,13 +195,9 @@ for:
- mkdir %flet_sdk_root%\packages\flet-desktop\src\flet_desktop\app
- xcopy flet %flet_sdk_root%\packages\flet-desktop\src\flet_desktop\app\flet\ /s /e

# install poetry env
# build package
- cd %flet_sdk_root%
- poetry install

# build "flet-desktop" package
- cd packages\flet-desktop
- poetry build
- uv build --wheel --package flet-desktop
- ps: |
$ErrorActionPreference = "Continue"
Get-ChildItem -Path dist/*-py3-none-any.whl | ForEach-Object {
Expand All @@ -209,15 +206,14 @@ for:
Remove-Item $_.FullName
}
$ErrorActionPreference = "Stop"
- cd %APPVEYOR_BUILD_FOLDER%
- dir %flet_sdk_root%\packages\flet-desktop\dist
- dir dist

# publish
- ps: |
if (($env:APPVEYOR_REPO_BRANCH -eq "main" -or $env:APPVEYOR_REPO_TAG_NAME) -and (-not $env:APPVEYOR_PULL_REQUEST_NUMBER)) {
twine upload $env:flet_sdk_root\packages\flet-desktop\dist\*
twine upload $env:flet_sdk_root\dist\*
} elseif (-not $env:APPVEYOR_PULL_REQUEST_NUMBER) {
$wheels = (Get-ChildItem $env:flet_sdk_root/packages/flet-desktop/dist/*.whl | Select-Object -ExpandProperty FullName)
$wheels = (Get-ChildItem $env:flet_sdk_root/dist/*.whl | Select-Object -ExpandProperty FullName)
foreach ($wheel in $wheels) {
curl.exe -sF package=@$wheel https://$env:GEMFURY_TOKEN@push.fury.io/flet/
}
Expand All @@ -227,7 +223,7 @@ for:

artifacts:
- path: client\build\windows\x64\runner\flet-windows.zip
- path: sdk\python\packages\flet-desktop\dist\*.whl
- path: sdk\python\packages\*.whl

deploy:
provider: GitHub
Expand Down Expand Up @@ -261,27 +257,22 @@ for:
# Python package
- patch_python_package_versions

# install poetry env
# build package
- cd $flet_sdk_root
- poetry install

# build "flet-desktop" package
- pushd packages/flet-desktop
- poetry build
- uv build --wheel --package flet-desktop
- sh: |
for file in dist/*-py3-none-any.whl; do
python $root/ci/repackage_wheel_with_tag.py $file "py3-none-macosx_12_0_arm64"
python $root/ci/repackage_wheel_with_tag.py $file "py3-none-macosx_10_14_x86_64"
rm $file
done
- popd

# publish
- publish_to_pypi packages/flet-desktop/dist/*.whl
- publish_to_pypi dist/*.whl

artifacts:
- path: client/flet-macos.tar.gz
- path: sdk/python/packages/flet-desktop/dist/*.whl
- path: sdk/python/dist/*.whl

deploy:
provider: GitHub
Expand Down Expand Up @@ -346,13 +337,13 @@ for:
# Python package
- patch_python_package_versions

# install poetry env
# build package
- cd $flet_sdk_root
- poetry install

# build "flet-desktop" package
- pushd packages/flet-desktop
- poetry build
- sh: |
if [[ "$PACKAGE_NAME" == "flet-desktop-light" ]]; then
sed -i 's/flet-desktop/flet-desktop-light/g' pyproject.toml
Copy link
Preview

Copilot AI Apr 28, 2025

Choose a reason for hiding this comment

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

[nitpick] Ensure that the sed substitution for replacing 'flet-desktop' with 'flet-desktop-light' in pyproject.toml is idempotent and targets only the intended configuration lines. Consider refining the match pattern to avoid inadvertent changes to unrelated parts of the file.

Suggested change
sed -i 's/flet-desktop/flet-desktop-light/g' pyproject.toml
sed -i '/^name = "flet-desktop"$/s/flet-desktop/flet-desktop-light/' pyproject.toml

Copilot uses AI. Check for mistakes.

fi
- uv build --wheel --package $PACKAGE_NAME
- sh: |
for file in dist/*-py3-none-any.whl; do
for tag in "${wheel_tags[@]}"; do
Expand All @@ -361,14 +352,13 @@ for:
done
rm "$file"
done
- popd

# publish
- publish_to_pypi packages/flet-desktop/dist/*.whl
- publish_to_pypi dist/*.whl

artifacts:
- path: client/flet-linux-*.tar.gz
- path: sdk/python/packages/flet-desktop/dist/*.whl
- path: sdk/python/dist/*.whl

deploy:
provider: GitHub
Expand All @@ -395,28 +385,25 @@ for:
- flutter build web --wasm
- cp -R build/web $flet_sdk_root/packages/flet-web/src/flet_web
# fix on mobile Safari: https://github.com/flutter/flutter/issues/145111#issuecomment-2714599139
- cp "$(dirname "$(command -v flutter)")/cache/flutter_web_sdk/flutter_js/flutter.js.map" $flet_sdk_root/packages/flet-web/src/flet_web
- ls "$(dirname "$(command -v flutter)")/cache/flutter_web_sdk/flutter_js"
- cp "$(dirname "$(command -v flutter)")/cache/flutter_web_sdk/flutter_js/flutter.js.map" $flet_sdk_root/packages/flet-web/src/flet_web/web
- curl -L $PYODIDE_URL | tar -xj -C "$flet_sdk_root/packages/flet-web/src/flet_web/web"
- popd
- tar -czvf client/build/flet-web.tar.gz -C client/build/web .

# Python package
- patch_python_package_versions

# install poetry env
# build package
- cd $flet_sdk_root
- poetry install

# build "flet-web" package
- pushd packages/flet-web
- poetry build
- popd
- uv build --wheel --package flet-web

# publish
- publish_to_pypi packages/flet-web/dist/*.whl
- publish_to_pypi dist/*.whl

artifacts:
- path: client/build/flet-web.tar.gz
- path: sdk/python/packages/flet-web/dist/*.whl
- path: sdk/python/dist/*.whl

deploy:
provider: GitHub
Expand All @@ -437,14 +424,13 @@ for:
- cd sdk/python
- python -m ensurepip --upgrade
- pip3 install --upgrade setuptools pip
- curl -sSL https://install.python-poetry.org | python -
- curl -LsSf https://astral.sh/uv/install.sh | sh
- export PATH="$HOME/.local/bin:$PATH"
- poetry install

build: off

test_script:
- poetry run pytest
- uv run pytest

######################
# Python Build #
Expand All @@ -461,30 +447,19 @@ for:
build_script:
- patch_python_package_versions

# install poetry env
# build packages
- cd $flet_sdk_root
- poetry install
- uv build --wheel --package flet-cli
- uv build --wheel --package flet

# build "flet-cli" package
- pushd packages/flet-cli
- poetry build
- popd

# build "flet" package
- pushd packages/flet
- poetry build
# update deps
- python $root/ci/update-flet-wheel-deps.py dist
- popd

# publish package
- |
publish_to_pypi \
packages/flet-cli/dist/*.whl \
packages/flet/dist/*.whl
# publish packages
- publish_to_pypi dist/*.whl

artifacts:
- path: sdk/python/packages/flet-cli/dist/*
- path: sdk/python/packages/flet/dist/*
- path: sdk/python/dist/*.whl

deploy:
provider: GitHub
Expand Down
46 changes: 19 additions & 27 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ git clone https://github.com/flet-dev/flet

## Python SDK

### Install Poetry
### Install uv

#### Windows

```powershell
(Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | py -
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
```

Be sure to add `%USERPROFILE%\AppData\Roaming\Python\Scripts` to `PATH`.

#### macOS
#### macOS/Linux

```
curl -sSL https://install.python-poetry.org | python3 -
curl -LsSf https://astral.sh/uv/install.sh | sh
```

### Open worker directory
Expand All @@ -37,7 +37,7 @@ cd sdk/python
To install all Flet dependencies and enable the project as editable package run:

```
poetry install
uv sync
```

### Check the installation
Expand All @@ -57,7 +57,7 @@ flet.app(target=main)
and then run it:

```
poetry run python hello.py
uv run python hello.py
```

During the first run Flet Client (`flet`) executable will be downloaded from [Flet GitHub releases](https://github.com/flet-dev/flet/releases) to a user temp directory and then started from there. The version of release to download from is taken from `flet/version.py` file.
Expand All @@ -66,10 +66,10 @@ You should see a new native OS window opened with "Hello, world!" in it.

### Running tests

Pytest should be run with `poetry run`:
Pytest should be run with `uv run`:

```
poetry run pytest
uv run pytest
```

### Code formatting
Expand All @@ -95,19 +95,10 @@ Install `isort` extension for imports formatting: https://marketplace.visualstud

### pre-commit

[pre-commit](https://pre-commit.com) is a dev dependency of Flet and is automatically installed by `poetry install`.
To install the pre-commit hooks run: `poetry run pre-commit install`.
[pre-commit](https://pre-commit.com) is a dev dependency of Flet and is automatically installed by `uv sync`.
To install the pre-commit hooks run: `uv run pre-commit install`.
Once installed, every time you commit, pre-commit will run the configured hooks against changed files.

## Possible installation error when working with a source package

When you run python3 hello.py, you might encounter an error like this:
`FileNotFoundError: [Error 2] No such file or directory: '/var/folders/xm/cyv42vbs27gff3s39vy97rx00000gn/T/fletd-0.1.50/fletd'`

To resolve the issue, just delete this folder `../T/fletd-0.1.50/fletd`. The folder is the one with the FileNotFound Error encountered earlier.

It should work now.

## Flutter client

Add the `FLET_VIEW_PATH` and `FLET_WEB_PATH` variables to the environment variables or profile scripts for your respective OS, making sure to modify the path accordingly:
Expand Down Expand Up @@ -163,7 +154,7 @@ Create a new folder preferably named `playground` (it has been added to the giti
Try running the below command, where `<your-main.py>` is the file to test your additions:

```bash
poetry run flet run -w -p 8550 playground/<your-main.py>
uv run flet run -w -p 8550 playground/<your-main.py>
```
You should see http://127.0.0.1:8550/ opened in the browser and also a desktop window with the output of your code.
Making changes to the `<your-main.py>` will automatically trigger a hot reload.
Expand All @@ -182,9 +173,10 @@ You will be able to see the debugging outputs of the flet client in this termina
- slowest: use `flutter run` as seen previously.

- When you make changes to the flet **python** files, you will need to restart/rerun the Python client for the changes to take effect in the opened flutter applications. This is done with the same command:
```bash
poetry run flet run -w -p 8550 playground/<your-main.py>
```

```bash
uv run flet run -w -p 8550 playground/<your-main.py>
```

## Releasing Flet

Expand Down Expand Up @@ -252,17 +244,17 @@ which ruby
* **GitHub Desktop**: https://desktop.github.com/download/
Open GitHub Desktop app, install Rosetta.

* **Poetry**: https://python-poetry.org/docs/#installing-with-the-official-installer
* **uv**: https://docs.astral.sh/uv/getting-started/installation/

After installing poetry, set PATH:
After installing uv, set PATH:
```
echo 'export PATH=$HOME/.local/bin:$PATH' >> ~/.zprofile
```

Check Poetry version and make sure it's in PATH:
Check `uv` version and make sure it's in PATH:

```
poetry --version
uv --version
```

* **Android Studio** for Android SDK required by Flutter: https://developer.android.com/studio
Expand Down
2 changes: 1 addition & 1 deletion ci/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ echo "flet_sdk_root: $flet_sdk_root"

python --version
pip install --upgrade setuptools wheel twine tomlkit
curl -sSL https://install.python-poetry.org | python3 -
curl -LsSf https://astral.sh/uv/install.sh | sh
export PATH="$HOME/.local/bin:$PATH"

function patch_python_package_versions() {
Expand Down
13 changes: 7 additions & 6 deletions ci/patch_toml_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@
t["project"]["version"] = ver

# patch dependencies
deps = t["tool"]["poetry"]["dependencies"]
deps: list[str] = t["project"]["dependencies"]


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
for i in range(0, len(deps)):
dep = deps[i]
if dep == dep_name:
deps[i] = f"{dep_name}=={ver}"
elif dep.startswith(f"{dep_name};"):
deps[i] = dep.replace(f"{dep_name};", f"{dep_name}=={ver};")


Comment on lines +28 to 35
Copy link
Preview

Copilot AI Apr 28, 2025

Choose a reason for hiding this comment

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

The dependency version update logic in patch_dep relies on simple string matching, which might not correctly handle cases where dependencies already contain version constraints or extras. Consider using a more robust parser or regex to accurately update dependency strings.

Suggested change
for i in range(0, len(deps)):
dep = deps[i]
if dep == dep_name:
deps[i] = f"{dep_name}=={ver}"
elif dep.startswith(f"{dep_name};"):
deps[i] = dep.replace(f"{dep_name};", f"{dep_name}=={ver};")
for i in range(len(deps)):
dep = deps[i]
# Parse dependency into components
if ";" in dep:
base, marker = dep.split(";", 1)
else:
base, marker = dep, None
if "[" in base:
name, extras = base.split("[", 1)
extras = "[" + extras # Add back the opening bracket
else:
name, extras = base, ""
# Update version if the dependency name matches
if name.strip() == dep_name:
new_base = f"{name.strip()}{extras}=={ver}"
deps[i] = f"{new_base};{marker}" if marker else new_base

Copilot uses AI. Check for mistakes.

patch_dep("flet-cli")
Expand Down
4 changes: 2 additions & 2 deletions ci/update-flet-wheel-deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ def update_metadata(metadata_file, version):
i = 0
while i < len(lines):
# insert Requires-Dist: flet-desktop-light ...
if lines[i].startswith("Requires-Dist: flet-desktop "):
if lines[i].startswith("Requires-Dist: flet-desktop=="):
lines.insert(
i + 1,
f'Requires-Dist: flet-desktop-light (=={version}) ; platform_system == "Linux" and (extra == "all" or extra == "desktop")\n',
f'Requires-Dist: flet-desktop-light=={version}; platform_system == "Linux" and (extra == "all" or extra == "desktop")\n',
)
lines[i] = re.sub(
r'platform_system != "desktop-light"',
Expand Down
Binary file added client/web/assets/fonts/roboto.woff2
Binary file not shown.
Loading