Skip to content

Commit 86b99bf

Browse files
v0: Migrate Poetry to uv (#5377)
* v1: Migrated `poetry` to `uv` (#5253) * poetry replaced with uv * Try building with CI * add uv to path * Fix sdk path * Support for desktop light * unpack pyodide * Update contributing guide * Enable Ruff * Cleanup after merge
1 parent 2a1facb commit 86b99bf

File tree

20 files changed

+2382
-3162
lines changed

20 files changed

+2382
-3162
lines changed

.appveyor.yml

Lines changed: 40 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ skip_commits:
1010

1111
environment:
1212
python_stack: python 3.12
13-
FLUTTER_VERSION: 3.29.2
13+
FLUTTER_VERSION: 3.29.3
1414
GITHUB_TOKEN:
1515
secure: 9SKIwc3VSfYJ5IChvNR74qi9xlUYK71gpBEZQSL4ZiqOEIAultwlQo3tHiHGLS8tz+EQtwMXEoWvw1Bl4y7oImJiH7lPjqo+BZnD7fzj9jwUYdDrP0u/HcmTxLHedH2b
1616
TWINE_USERNAME: __token__
@@ -68,6 +68,7 @@ environment:
6868
- job_name: Build Flet for web
6969
job_group: build_flet
7070
job_depends_on: build_flet_package
71+
PYODIDE_URL: https://github.com/pyodide/pyodide/releases/download/0.27.5/pyodide-core-0.27.5.tar.bz2
7172
APPVEYOR_BUILD_WORKER_IMAGE: ubuntu2004
7273

7374
- job_name: Test Python 3.9
@@ -167,9 +168,9 @@ for:
167168
install:
168169
- python --version
169170
- pip3 install --upgrade setuptools wheel twine tomlkit
170-
- ps: (Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | python -
171-
- ps: Add-SessionPath "$HOME\AppData\Roaming\Python\Scripts"
172-
- poetry --version
171+
- ps: irm https://astral.sh/uv/install.ps1 | iex
172+
- ps: Add-SessionPath "$HOME\.local\bin"
173+
- uv --version
173174
- dart pub global activate fvm
174175
- set PATH=%LOCALAPPDATA%\Pub\Cache\bin;%USERPROFILE%\fvm\default\bin;%PATH%
175176
- fvm install %FLUTTER_VERSION%
@@ -199,13 +200,9 @@ for:
199200
- mkdir %flet_sdk_root%\packages\flet-desktop\src\flet_desktop\app
200201
- xcopy flet %flet_sdk_root%\packages\flet-desktop\src\flet_desktop\app\flet\ /s /e
201202

202-
# install poetry env
203+
# build package
203204
- cd %flet_sdk_root%
204-
- poetry install
205-
206-
# build "flet-desktop" package
207-
- cd packages\flet-desktop
208-
- poetry build
205+
- uv build --wheel --package flet-desktop
209206
- ps: |
210207
$ErrorActionPreference = "Continue"
211208
Get-ChildItem -Path dist/*-py3-none-any.whl | ForEach-Object {
@@ -214,15 +211,14 @@ for:
214211
Remove-Item $_.FullName
215212
}
216213
$ErrorActionPreference = "Stop"
217-
- cd %APPVEYOR_BUILD_FOLDER%
218-
- dir %flet_sdk_root%\packages\flet-desktop\dist
214+
- dir dist
219215

220216
# publish
221217
- ps: |
222218
if (($env:APPVEYOR_REPO_BRANCH -eq "main" -or $env:APPVEYOR_REPO_TAG_NAME) -and (-not $env:APPVEYOR_PULL_REQUEST_NUMBER)) {
223-
twine upload $env:flet_sdk_root\packages\flet-desktop\dist\*
219+
twine upload $env:flet_sdk_root\dist\*
224220
} elseif (-not $env:APPVEYOR_PULL_REQUEST_NUMBER) {
225-
$wheels = (Get-ChildItem $env:flet_sdk_root/packages/flet-desktop/dist/*.whl | Select-Object -ExpandProperty FullName)
221+
$wheels = (Get-ChildItem $env:flet_sdk_root/dist/*.whl | Select-Object -ExpandProperty FullName)
226222
foreach ($wheel in $wheels) {
227223
curl.exe -sF package=@$wheel https://$env:GEMFURY_TOKEN@push.fury.io/flet/
228224
}
@@ -232,7 +228,7 @@ for:
232228

233229
artifacts:
234230
- path: client\build\windows\x64\runner\flet-windows.zip
235-
- path: sdk\python\packages\flet-desktop\dist\*.whl
231+
- path: sdk\python\packages\*.whl
236232

237233
deploy:
238234
provider: GitHub
@@ -266,27 +262,22 @@ for:
266262
# Python package
267263
- patch_python_package_versions
268264

269-
# install poetry env
265+
# build package
270266
- cd $flet_sdk_root
271-
- poetry install
272-
273-
# build "flet-desktop" package
274-
- pushd packages/flet-desktop
275-
- poetry build
267+
- uv build --wheel --package flet-desktop
276268
- sh: |
277269
for file in dist/*-py3-none-any.whl; do
278270
python $root/ci/repackage_wheel_with_tag.py $file "py3-none-macosx_12_0_arm64"
279271
python $root/ci/repackage_wheel_with_tag.py $file "py3-none-macosx_10_14_x86_64"
280272
rm $file
281273
done
282-
- popd
283274
284275
# publish
285-
- publish_to_pypi packages/flet-desktop/dist/*.whl
276+
- publish_to_pypi dist/*.whl
286277

287278
artifacts:
288279
- path: client/flet-macos.tar.gz
289-
- path: sdk/python/packages/flet-desktop/dist/*.whl
280+
- path: sdk/python/dist/*.whl
290281

291282
deploy:
292283
provider: GitHub
@@ -351,13 +342,13 @@ for:
351342
# Python package
352343
- patch_python_package_versions
353344

354-
# install poetry env
345+
# build package
355346
- cd $flet_sdk_root
356-
- poetry install
357-
358-
# build "flet-desktop" package
359-
- pushd packages/flet-desktop
360-
- poetry build
347+
- sh: |
348+
if [[ "$PACKAGE_NAME" == "flet-desktop-light" ]]; then
349+
sed -i 's/flet-desktop/flet-desktop-light/g' pyproject.toml
350+
fi
351+
- uv build --wheel --package $PACKAGE_NAME
361352
- sh: |
362353
for file in dist/*-py3-none-any.whl; do
363354
for tag in "${wheel_tags[@]}"; do
@@ -366,14 +357,13 @@ for:
366357
done
367358
rm "$file"
368359
done
369-
- popd
370360
371361
# publish
372-
- publish_to_pypi packages/flet-desktop/dist/*.whl
362+
- publish_to_pypi dist/*.whl
373363

374364
artifacts:
375365
- path: client/flet-linux-*.tar.gz
376-
- path: sdk/python/packages/flet-desktop/dist/*.whl
366+
- path: sdk/python/dist/*.whl
377367

378368
deploy:
379369
provider: GitHub
@@ -400,27 +390,26 @@ for:
400390
- flutter build web --release
401391
- rm -rf build/web/canvaskit
402392
- cp -R build/web $flet_sdk_root/packages/flet-web/src/flet_web
393+
# fix on mobile Safari: https://github.com/flutter/flutter/issues/145111#issuecomment-2714599139
394+
- ls "$(dirname "$(command -v flutter)")/cache/flutter_web_sdk/flutter_js"
395+
- cp "$(dirname "$(command -v flutter)")/cache/flutter_web_sdk/flutter_js/flutter.js.map" $flet_sdk_root/packages/flet-web/src/flet_web/web
396+
- curl -L $PYODIDE_URL | tar -xj -C "$flet_sdk_root/packages/flet-web/src/flet_web/web"
403397
- popd
404398
- tar -czvf client/build/flet-web.tar.gz -C client/build/web .
405399

406400
# Python package
407401
- patch_python_package_versions
408402

409-
# install poetry env
403+
# build package
410404
- cd $flet_sdk_root
411-
- poetry install
412-
413-
# build "flet-web" package
414-
- pushd packages/flet-web
415-
- poetry build
416-
- popd
405+
- uv build --wheel --package flet-web
417406

418407
# publish
419-
- publish_to_pypi packages/flet-web/dist/*.whl
408+
- publish_to_pypi dist/*.whl
420409

421410
artifacts:
422411
- path: client/build/flet-web.tar.gz
423-
- path: sdk/python/packages/flet-web/dist/*.whl
412+
- path: sdk/python/dist/*.whl
424413

425414
deploy:
426415
provider: GitHub
@@ -441,14 +430,13 @@ for:
441430
- cd sdk/python
442431
- python -m ensurepip --upgrade
443432
- pip3 install --upgrade setuptools pip
444-
- curl -sSL https://install.python-poetry.org | python -
433+
- curl -LsSf https://astral.sh/uv/install.sh | sh
445434
- export PATH="$HOME/.local/bin:$PATH"
446-
- poetry install
447435

448436
build: off
449437

450438
test_script:
451-
- poetry run pytest
439+
- uv run pytest
452440

453441
######################
454442
# Python Build #
@@ -465,30 +453,19 @@ for:
465453
build_script:
466454
- patch_python_package_versions
467455

468-
# install poetry env
456+
# build packages
469457
- cd $flet_sdk_root
470-
- poetry install
458+
- uv build --wheel --package flet-cli
459+
- uv build --wheel --package flet
471460

472-
# build "flet-cli" package
473-
- pushd packages/flet-cli
474-
- poetry build
475-
- popd
476-
477-
# build "flet" package
478-
- pushd packages/flet
479-
- poetry build
461+
# update deps
480462
- python $root/ci/update-flet-wheel-deps.py dist
481-
- popd
482463

483-
# publish package
484-
- |
485-
publish_to_pypi \
486-
packages/flet-cli/dist/*.whl \
487-
packages/flet/dist/*.whl
464+
# publish packages
465+
- publish_to_pypi dist/*.whl
488466

489467
artifacts:
490-
- path: sdk/python/packages/flet-cli/dist/*
491-
- path: sdk/python/packages/flet/dist/*
468+
- path: sdk/python/dist/*.whl
492469

493470
deploy:
494471
provider: GitHub

CONTRIBUTING.md

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ git clone https://github.com/flet-dev/flet
1010

1111
## Python SDK
1212

13-
### Install Poetry
13+
### Install uv
1414

1515
#### Windows
1616

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

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

23-
#### macOS
23+
#### macOS/Linux
2424

2525
```
26-
curl -sSL https://install.python-poetry.org | python3 -
26+
curl -LsSf https://astral.sh/uv/install.sh | sh
2727
```
2828

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

3939
```
40-
poetry install
40+
uv sync
4141
```
4242

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

5959
```
60-
poetry run python hello.py
60+
uv run python hello.py
6161
```
6262

6363
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.
@@ -66,10 +66,10 @@ You should see a new native OS window opened with "Hello, world!" in it.
6666

6767
### Running tests
6868

69-
Pytest should be run with `poetry run`:
69+
Pytest should be run with `uv run`:
7070

7171
```
72-
poetry run pytest
72+
uv run pytest
7373
```
7474

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

9696
### pre-commit
9797

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

102-
## Possible installation error when working with a source package
103-
104-
When you run python3 hello.py, you might encounter an error like this:
105-
`FileNotFoundError: [Error 2] No such file or directory: '/var/folders/xm/cyv42vbs27gff3s39vy97rx00000gn/T/fletd-0.1.50/fletd'`
106-
107-
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.
108-
109-
It should work now.
110-
111102
## Flutter client
112103

113104
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:
@@ -167,7 +158,7 @@ Create a new folder preferably named `playground` (it has been added to the giti
167158
Try running the below command, where `<your-main.py>` is the file to test your additions:
168159
169160
```bash
170-
poetry run flet run -w -p 8550 playground/<your-main.py>
161+
uv run flet run -w -p 8550 playground/<your-main.py>
171162
```
172163
You should see http://127.0.0.1:8550/ opened in the browser and also a desktop window with the output of your code.
173164
Making changes to the `<your-main.py>` will automatically trigger a hot reload.
@@ -186,9 +177,10 @@ You will be able to see the debugging outputs of the flet client in this termina
186177
- slowest: use `flutter run` as seen previously.
187178

188179
- 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:
189-
```bash
190-
poetry run flet run -w -p 8550 playground/<your-main.py>
191-
```
180+
181+
```bash
182+
uv run flet run -w -p 8550 playground/<your-main.py>
183+
```
192184

193185
## Releasing Flet
194186

@@ -256,17 +248,17 @@ which ruby
256248
* **GitHub Desktop**: https://desktop.github.com/download/
257249
Open GitHub Desktop app, install Rosetta.
258250

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

261-
After installing poetry, set PATH:
253+
After installing uv, set PATH:
262254
```
263255
echo 'export PATH=$HOME/.local/bin:$PATH' >> ~/.zprofile
264256
```
265257

266-
Check Poetry version and make sure it's in PATH:
258+
Check `uv` version and make sure it's in PATH:
267259

268260
```
269-
poetry --version
261+
uv --version
270262
```
271263

272264
* **Android Studio** for Android SDK required by Flutter: https://developer.android.com/studio

ci/common.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ echo "flet_sdk_root: $flet_sdk_root"
44

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

1010
function patch_python_package_versions() {

ci/patch_toml_versions.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,16 @@
2121
t["project"]["version"] = ver
2222

2323
# patch dependencies
24-
deps = t["tool"]["poetry"]["dependencies"]
24+
deps: list[str] = t["project"]["dependencies"]
2525

2626

2727
def patch_dep(dep_name):
28-
if deps.get(dep_name):
29-
if isinstance(deps[dep_name], dict):
30-
deps[dep_name]["version"] = ver
31-
else:
32-
deps[dep_name] = ver
28+
for i in range(0, len(deps)):
29+
dep = deps[i]
30+
if dep == dep_name:
31+
deps[i] = f"{dep_name}=={ver}"
32+
elif dep.startswith(f"{dep_name};"):
33+
deps[i] = dep.replace(f"{dep_name};", f"{dep_name}=={ver};")
3334

3435

3536
patch_dep("flet-cli")

0 commit comments

Comments
 (0)