From 90e97ce5426ced21089670c4f28869f670f5bb91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B8=D0=BA=D1=82=D0=BE=D1=80?= <78488229+viktor138irk@users.noreply.github.com> Date: Tue, 12 May 2026 01:44:27 +0900 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D1=87=D1=82=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B2=D0=B5=D1=80=D1=81?= =?UTF-8?q?=D0=B8=D0=B8=20Flutter=20=D0=B8=D0=B7=20pubspec.yaml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/pubspec_tools.py | 46 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 backend/pubspec_tools.py diff --git a/backend/pubspec_tools.py b/backend/pubspec_tools.py new file mode 100644 index 0000000..e3bb8ed --- /dev/null +++ b/backend/pubspec_tools.py @@ -0,0 +1,46 @@ +import re +from pathlib import Path + + +_VERSION_RE = re.compile(r'^\s*version\s*:\s*([^\s#]+)') + + +def read_pubspec_version(workspace: str) -> dict | None: + """Read Flutter version/build from pubspec.yaml. + + Supports the standard Flutter format: version: 1.2.3+45 + Returns None when pubspec.yaml is missing or version is not declared. + """ + pubspec_path = Path(workspace).resolve() / 'pubspec.yaml' + if not pubspec_path.exists(): + return None + + try: + content = pubspec_path.read_text(encoding='utf-8') + except UnicodeDecodeError: + content = pubspec_path.read_text(errors='ignore') + + for line in content.splitlines(): + match = _VERSION_RE.match(line) + if not match: + continue + + full_version = match.group(1).strip() + version, build = _split_flutter_version(full_version) + return { + 'success': True, + 'version': version, + 'build': build, + 'full_version': full_version, + 'pubspec_path': pubspec_path.as_posix(), + } + + return None + + +def _split_flutter_version(full_version: str) -> tuple[str, str]: + if '+' not in full_version: + return full_version, '1' + + version, build = full_version.split('+', 1) + return version.strip() or '0.0.1', build.strip() or '1'