Skip to content

Commit 15ac9b9

Browse files
Switch to tomllib/tomli for pyproject.toml parsing (#5714)
Replaces the toml dependency with tomli for Python <3.11 and tomllib for Python >=3.11. Updates pyproject.toml and utility code to use the appropriate library for parsing pyproject.toml files, ensuring compatibility with newer Python versions. Fix #5701
1 parent 639be4f commit 15ac9b9

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

sdk/python/packages/flet-cli/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ dependencies = [
1111
"watchdog >=4.0.0",
1212
"packaging >=25.0",
1313
"qrcode >=7.4.2",
14-
"toml >=0.10.2",
14+
"tomli >= 1.1.0 ; python_version < '3.11'",
1515
"cookiecutter >=2.6.0"
1616
]
1717

sdk/python/packages/flet-cli/src/flet_cli/utils/pyproject_toml.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1+
import sys
12
from pathlib import Path
23
from typing import Any, Optional
34

4-
import toml
5+
if sys.version_info >= (3, 11):
6+
import tomllib
7+
else:
8+
import tomli as tomllib
59

610

711
def load_pyproject_toml(project_dir: Path):
812
pyproject_toml: Optional[dict[str, Any]] = {}
913
pyproject_toml_file = project_dir.joinpath("pyproject.toml")
1014
if pyproject_toml_file.exists():
1115
with pyproject_toml_file.open("r", encoding="utf-8") as f:
12-
pyproject_toml = toml.loads(f.read())
16+
pyproject_toml = tomllib.loads(f.read())
1317

1418
def get_pyproject(setting: Optional[str] = None):
1519
if not setting:

0 commit comments

Comments
 (0)