Skip to content
Merged
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
44 changes: 34 additions & 10 deletions sdk/python/flet/version.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
import subprocess as sp
"""Provide the current Flet version."""


from pkg_resources import parse_version
import os
import subprocess as sp
from pathlib import Path

import flet
from flet.utils import which


# this value will be replaced by CI
version = ""


def update_version():
in_repo = sp.run(
"""Return the current version or default."""
working = Path().absolute()
os.chdir(Path(flet.__file__).absolute().parent)
in_repo = which("git") and sp.run(
["git", "status"],
capture_output=True,
text=True,
Expand All @@ -18,15 +26,31 @@ def update_version():
if in_repo:
# NOTE: this may break if there is a tag name starting with
# "v" that isn't a version number
tags = sp.run(
["git", "tag"],
class RepositoryError(OSError):
pass

git_p = sp.run(
["git", "describe", "--abbrev=0"],
capture_output=True,
text=True,
).stdout.splitlines()
versions = filter(lambda t: t.startswith("v"), tags)
return sorted(versions, key=parse_version)[-1][1:]
return "0.1.60"
)
err = git_p.stderr.strip()

if "cannot describe anything" in err:
msg = "You may be using a repo cloned from a fork. "
msg += "If so please clone the original Flet repo"
raise RepositoryError(msg)

if err:
msg = "Unknown error while fetching the version: {err}"
raise RepositoryError(msg)
version = git_p.stdout.strip()[1:]

else:
version = "0.1.60"
os.chdir(working)
return version


if not globals().get("version", None):
if not version:
version = update_version()