Skip to content

Commit 48dca6f

Browse files
Poetry 2.0 support, Flutter and JDK installation fixes (flet-dev#4748)
* Switch to `[project]`, remove python ver upper limit * Fix Flutter installation by supporting zip unpacking with symlinks * Configure JDK path for Flutter Close flet-dev#4727
1 parent b98e0a0 commit 48dca6f

File tree

8 files changed

+125
-29
lines changed

8 files changed

+125
-29
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
[tool.poetry]
1+
[project]
22
name = "flet-cli"
33
version = "0.1.0"
44
description = "Flet CLI"
5-
authors = ["Appveyor Systems Inc. <hello@flet.dev>"]
5+
authors = [{name = "Appveyor Systems Inc.", email ="hello@flet.dev"}]
66
license = "Apache-2.0"
77
readme = "README.md"
8+
requires-python = ">=3.9"
89

10+
[tool.poetry]
911
packages = [{ include = "flet_cli", from = "src" }]
1012

1113
[tool.poetry.urls]
@@ -14,7 +16,6 @@ Repository = "https://github.com/flet-dev/flet"
1416
Documentation = "https://flet.dev/docs"
1517

1618
[tool.poetry.dependencies]
17-
python = "^3.9"
1819
flet = { version = "0.1.0" }
1920
watchdog = "^4.0.0"
2021
packaging = "*"

sdk/python/packages/flet-cli/src/flet_cli/commands/build.py

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import flet.version
1212
import flet_cli.utils.processes as processes
1313
import yaml
14-
from flet.utils import copy_tree, is_windows, slugify
14+
from flet.utils import cleanup_path, copy_tree, is_windows, slugify
1515
from flet.utils.platform_utils import get_bool_env_var
1616
from flet.version import update_version
1717
from flet_cli.commands.base import BaseCommand
@@ -681,9 +681,35 @@ def install_flutter(self):
681681
ext = ".bat" if platform.system() == "Windows" else ""
682682
self.flutter_exe = os.path.join(flutter_dir, "bin", f"flutter{ext}")
683683
self.dart_exe = os.path.join(flutter_dir, "bin", f"dart{ext}")
684-
self.env["PATH"] = os.pathsep.join(
685-
[os.path.join(flutter_dir, "bin"), os.environ.get("PATH", "")]
684+
path_env = cleanup_path(
685+
cleanup_path(os.environ.get("PATH", ""), "flutter"), "dart"
686686
)
687+
self.env["PATH"] = os.pathsep.join([os.path.join(flutter_dir, "bin"), path_env])
688+
689+
# desktop mode
690+
if self.config_platform in ["macos", "windows", "linux"]:
691+
if self.verbose > 0:
692+
console.log(
693+
f"Ensure Flutter has desktop support enabled",
694+
style=verbose1_style,
695+
)
696+
config_result = self.run(
697+
[
698+
self.flutter_exe,
699+
"config",
700+
"--suppress-analytics",
701+
f"--enable-{self.config_platform}-desktop",
702+
],
703+
cwd=os.getcwd(),
704+
capture_output=self.verbose < 1,
705+
)
706+
if config_result.returncode != 0:
707+
if config_result.stdout:
708+
console.log(config_result.stdout, style=verbose1_style)
709+
if config_result.stderr:
710+
console.log(config_result.stderr, style=error_style)
711+
self.cleanup(config_result.returncode)
712+
687713
console.log(
688714
f"Flutter {MINIMAL_FLUTTER_VERSION} installed {self.emojis['checkmark']}"
689715
)
@@ -692,7 +718,32 @@ def install_jdk(self):
692718
from flet_cli.utils.jdk import install_jdk
693719

694720
self.status.update(f"[bold blue]Installing JDK...")
695-
self.env["JAVA_HOME"] = install_jdk(self.log_stdout, progress=self.progress)
721+
jdk_dir = install_jdk(self.log_stdout, progress=self.progress)
722+
self.env["JAVA_HOME"] = jdk_dir
723+
724+
# config flutter's JDK dir
725+
if self.verbose > 0:
726+
console.log(
727+
f"Configuring Flutter's path to JDK",
728+
style=verbose1_style,
729+
)
730+
config_result = self.run(
731+
[
732+
self.flutter_exe,
733+
"config",
734+
"--suppress-analytics",
735+
f"--jdk-dir={jdk_dir}",
736+
],
737+
cwd=os.getcwd(),
738+
capture_output=self.verbose < 1,
739+
)
740+
if config_result.returncode != 0:
741+
if config_result.stdout:
742+
console.log(config_result.stdout, style=verbose1_style)
743+
if config_result.stderr:
744+
console.log(config_result.stderr, style=error_style)
745+
self.cleanup(config_result.returncode)
746+
696747
console.log(f"JDK installed {self.emojis['checkmark']}")
697748

698749
def install_android_sdk(self):

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

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,36 +27,61 @@ def download_with_progress(url, dest_path, progress: Optional[Progress] = None):
2727
def extract_with_progress(
2828
archive_path, extract_to, progress: Optional[Progress] = None
2929
):
30-
"""Extracts an archive with a progress bar and preserves file attributes."""
30+
"""Extracts an archive with a progress bar and preserves file attributes, including symbolic links."""
3131
if archive_path.endswith(".zip"):
3232
with zipfile.ZipFile(archive_path, "r") as archive:
3333
total_files = len(archive.namelist())
3434
if progress:
3535
task = progress.add_task("Extracting...", total=total_files)
3636
for member in archive.namelist():
37-
member = archive.getinfo(member)
38-
archive.extract(member, extract_to)
37+
member_info = archive.getinfo(member)
38+
# Check if the member is a symbolic link
39+
is_symlink = (member_info.external_attr >> 16) & 0o120000 == 0o120000
40+
extracted_path = os.path.join(extract_to, member_info.filename)
41+
42+
if is_symlink:
43+
# Read the target of the symlink from the archive
44+
with archive.open(member_info) as target_file:
45+
target = target_file.read().decode("utf-8")
46+
# Create the symbolic link
47+
os.symlink(target, extracted_path)
48+
else:
49+
# Extract regular files and directories
50+
archive.extract(member_info, extract_to)
51+
52+
# Preserve permissions
53+
if member_info.external_attr > 0xFFFF:
54+
os.chmod(extracted_path, member_info.external_attr >> 16)
55+
3956
if progress:
4057
progress.update(task, advance=1)
41-
# preserve permissions
42-
extracted_path = os.path.join(extract_to, member.filename)
43-
if member.external_attr > 0xFFFF:
44-
os.chmod(extracted_path, member.external_attr >> 16)
4558
if progress:
4659
progress.remove_task(task)
60+
4761
elif archive_path.endswith(".tar.xz") or archive_path.endswith(".tar.gz"):
4862
with tarfile.open(archive_path, "r:*") as archive:
4963
members = archive.getmembers()
5064
total_files = len(members)
5165
if progress:
5266
task = progress.add_task("Extracting...", total=total_files)
5367
for member in members:
54-
archive.extract(member, extract_to)
55-
if progress:
56-
progress.update(task, advance=1)
57-
# Preserve permissions (executable flags, etc.)
5868
extracted_path = os.path.join(extract_to, member.name)
59-
if member.isfile():
69+
70+
if member.issym():
71+
# Create symbolic link manually
72+
os.symlink(member.linkname, extracted_path)
73+
elif member.islnk():
74+
# Create hard link manually
75+
os.link(os.path.join(extract_to, member.linkname), extracted_path)
76+
else:
77+
# Extract regular files and directories
78+
archive.extract(member, extract_to)
79+
80+
# Preserve permissions
81+
if member.isfile() or member.isdir():
6082
os.chmod(extracted_path, member.mode)
83+
84+
if progress:
85+
progress.update(task, advance=1)
6186
if progress:
6287
progress.remove_task(task)

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
[tool.poetry]
1+
[project]
22
name = "flet-desktop"
33
version = "0.1.0"
44
description = "Flet Desktop client in Flutter"
5-
authors = ["Appveyor Systems Inc. <hello@flet.dev>"]
5+
authors = [{name = "Appveyor Systems Inc.", email ="hello@flet.dev"}]
66
license = "Apache-2.0"
77
readme = "README.md"
8+
requires-python = ">=3.9"
89

10+
[tool.poetry]
911
packages = [
1012
{ include = "flet_desktop", from = "src" },
1113
]
@@ -20,7 +22,6 @@ Repository = "https://github.com/flet-dev/flet"
2022
Documentation = "https://flet.dev/docs"
2123

2224
[tool.poetry.dependencies]
23-
python = "^3.9"
2425
flet = { version = "0.1.0" }
2526

2627
[tool.poetry.group.dev.dependencies]

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
[tool.poetry]
1+
[project]
22
name = "flet-web"
33
version = "0.1.0"
44
description = "Flet web client in Flutter."
5-
authors = ["Appveyor Systems Inc. <hello@flet.dev>"]
5+
authors = [{name = "Appveyor Systems Inc.", email ="hello@flet.dev"}]
66
license = "Apache-2.0"
77
readme = "README.md"
8+
requires-python = ">=3.9"
89

10+
[tool.poetry]
911
packages = [{ include = "flet_web", from = "src" }]
1012

1113
include = [{ path = "src/flet_web/web/**/*", format = ["sdist", "wheel"] }]
@@ -16,7 +18,6 @@ Repository = "https://github.com/flet-dev/flet"
1618
Documentation = "https://flet.dev/docs"
1719

1820
[tool.poetry.dependencies]
19-
python = "^3.9"
2021
flet = { version = "0.1.0" }
2122
fastapi = "*"
2223
uvicorn = { extras = ["standard"], version = "*" }

sdk/python/packages/flet/pyproject.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
[tool.poetry]
1+
[project]
22
name = "flet"
33
version = "0.1.0"
44
description = "Flet for Python - easily build interactive multi-platform apps in Python"
5-
authors = ["Appveyor Systems Inc. <hello@flet.dev>"]
5+
authors = [{name = "Appveyor Systems Inc.", email ="hello@flet.dev"}]
66
license = "Apache-2.0"
77
readme = "README.md"
8+
requires-python = ">=3.9"
89

10+
[tool.poetry]
911
packages = [{ include = "flet", from = "src" }]
1012

1113
[tool.poetry.urls]
@@ -14,7 +16,6 @@ Repository = "https://github.com/flet-dev/flet"
1416
Documentation = "https://flet.dev/docs"
1517

1618
[tool.poetry.dependencies]
17-
python = "^3.9"
1819
flet-cli = { version = "0.1.0", optional = true }
1920
flet-desktop = { version = "0.1.0", optional = true, markers = "platform_system == 'Darwin' or platform_system == 'Windows'" }
2021
flet-web = { version = "0.1.0", optional = true }

sdk/python/packages/flet/src/flet/utils/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from flet.utils.classproperty import classproperty
33
from flet.utils.deprecated import deprecated
44
from flet.utils.files import (
5+
cleanup_path,
56
copy_tree,
67
get_current_script_dir,
78
is_within_directory,

sdk/python/packages/flet/src/flet/utils/files.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,21 @@ def is_exe(fpath):
4242

4343
return None
4444

45+
46+
def cleanup_path(path: str, executable: str):
47+
cleaned_dirs = []
48+
for path_dir in path.split(os.pathsep):
49+
found = False
50+
for file_name in [executable, f"{executable}.bat", f"{executable}.cmd"]:
51+
if os.path.isfile(os.path.join(path_dir, file_name)):
52+
found = True
53+
break
54+
if not found:
55+
cleaned_dirs.append(path_dir)
56+
57+
return os.pathsep.join(cleaned_dirs)
58+
59+
4560
def get_current_script_dir():
4661
pathname = os.path.dirname(sys.argv[0])
47-
return os.path.abspath(pathname)
62+
return os.path.abspath(pathname)

0 commit comments

Comments
 (0)