From b21e4ea9fa75ffef00a04311aebfede935ffc441 Mon Sep 17 00:00:00 2001 From: Mateusz <2871798+orhtej2@users.noreply.github.com> Date: Sun, 14 Jul 2024 14:36:06 +0200 Subject: [PATCH] Bump `ynh` number on non-main-asset-only updates. --- .../autoupdate_app_sources.py | 22 +++++++++++++------ autoupdate_app_sources/requirements.txt | 1 - 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/autoupdate_app_sources/autoupdate_app_sources.py b/autoupdate_app_sources/autoupdate_app_sources.py index 48c56d2..73893f1 100755 --- a/autoupdate_app_sources/autoupdate_app_sources.py +++ b/autoupdate_app_sources/autoupdate_app_sources.py @@ -256,6 +256,9 @@ class AppAutoUpdater: if state == State.up_to_date: return (State.up_to_date, "", "", "") + if main_version == "": + self.repo.manifest_raw = self.bump_version(self.repo.manifest_raw, self.current_version, bump_ynh_level=True) + if edit: self.repo.edit_manifest(self.repo.manifest_raw) @@ -580,19 +583,24 @@ class AppAutoUpdater: ] if is_main: - - def repl(m: re.Match) -> str: - return m.group(1) + new_version + '~ynh1"' - - content = re.sub( - r"(\s*version\s*=\s*[\"\'])([^~\"\']+)(\~ynh\d+[\"\'])", repl, content - ) + content = self.bump_version(content, new_version) for old, new in replacements: content = content.replace(old, new) return content + def bump_version(self, content: str, new_version: str, bump_ynh_level: bool = False) -> str: + ynh_level = 1 + if bump_ynh_level: + ynh_level = int(re.search(r"\s*version\s*=\s*[\"\'][^~\"\']+~ynh(\d+)[\"\']", content).group(1)) + 1 + + def repl(m: re.Match) -> str: + return m.group(1) + new_version + f'~ynh{ynh_level}"' + + return re.sub( + r"(\s*version\s*=\s*[\"\'])([^~\"\']+)(~ynh\d+[\"\'])", repl, content + ) def paste_on_haste(data): # NB: we hardcode this here and can't use the yunopaste command diff --git a/autoupdate_app_sources/requirements.txt b/autoupdate_app_sources/requirements.txt index 737faa3..4acb0cc 100644 --- a/autoupdate_app_sources/requirements.txt +++ b/autoupdate_app_sources/requirements.txt @@ -2,4 +2,3 @@ requests PyGithub toml tqdm -GitPython \ No newline at end of file