From 51dd81844552680a9294896b9782bf0a9607cefd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Thu, 15 Feb 2024 09:54:03 +0100 Subject: [PATCH 1/4] Remove debug print --- autoupdate_app_sources/autoupdate_app_sources.py | 1 - 1 file changed, 1 deletion(-) diff --git a/autoupdate_app_sources/autoupdate_app_sources.py b/autoupdate_app_sources/autoupdate_app_sources.py index bd85a36..4225d22 100755 --- a/autoupdate_app_sources/autoupdate_app_sources.py +++ b/autoupdate_app_sources/autoupdate_app_sources.py @@ -532,7 +532,6 @@ def main() -> None: for app, info in apps_updated.items(): result_message += f"\n- {app}" if isinstance(info, tuple): - print(info) result_message += f" ({info[0]} -> {info[1]})" if info[2] is not None: result_message += f" see {info[2]}" From ae6b32c786311af2585e62cf8fa39f8cddcfd62d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Thu, 15 Feb 2024 11:04:57 +0100 Subject: [PATCH 2/4] Handle invalid syntax in some local app's manifest during initial apps listing --- .../autoupdate_app_sources.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/autoupdate_app_sources/autoupdate_app_sources.py b/autoupdate_app_sources/autoupdate_app_sources.py index 4225d22..5e7aba4 100755 --- a/autoupdate_app_sources/autoupdate_app_sources.py +++ b/autoupdate_app_sources/autoupdate_app_sources.py @@ -57,7 +57,7 @@ def get_github() -> tuple[tuple[str, str] | None, github.Github | None, github.I return None, None, None -def apps_to_run_auto_update_for(): +def apps_to_run_auto_update_for() -> list[str]: apps_flagged_as_working_and_on_yunohost_apps_org = [ app for app, infos in get_catalog().items() @@ -67,12 +67,15 @@ def apps_to_run_auto_update_for(): relevant_apps = [] for app in apps_flagged_as_working_and_on_yunohost_apps_org: - manifest_toml = app_cache_folder(app) / "manifest.toml" - if manifest_toml.exists(): - manifest = toml.load(manifest_toml.open("r", encoding="utf-8")) - sources = manifest.get("resources", {}).get("sources", {}) - if any("autoupdate" in source for source in sources.values()): - relevant_apps.append(app) + try: + manifest_toml = app_cache_folder(app) / "manifest.toml" + if manifest_toml.exists(): + manifest = toml.load(manifest_toml.open("r", encoding="utf-8")) + sources = manifest.get("resources", {}).get("sources", {}) + if any("autoupdate" in source for source in sources.values()): + relevant_apps.append(app) + except Exception as e: + print(f"Error while loading {app}'s manifest: {e}") return relevant_apps From 7ee6711119f8924cb835dbf23773cac4882c7068 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Thu, 15 Feb 2024 11:05:48 +0100 Subject: [PATCH 3/4] Cleanup for mypy, code simplification --- .../autoupdate_app_sources.py | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/autoupdate_app_sources/autoupdate_app_sources.py b/autoupdate_app_sources/autoupdate_app_sources.py index 5e7aba4..367b7e4 100755 --- a/autoupdate_app_sources/autoupdate_app_sources.py +++ b/autoupdate_app_sources/autoupdate_app_sources.py @@ -101,7 +101,7 @@ class LocalOrRemoteRepo: github = get_github()[1] assert github, "Could not get github authentication!" self.repo = github.get_repo(f"Yunohost-Apps/{app}_ynh") - self.pr_branch = None + self.pr_branch: str | None = None # Determine base branch, either `testing` or default branch try: self.base_branch = self.repo.get_branch("testing").name @@ -148,15 +148,14 @@ class LocalOrRemoteRepo: return False def create_pr(self, branch: str, title: str, message: str) -> str | None: - if self.local: - logging.warning("Can't create pull requests for local repositories") - return if self.remote: # Open the PR pr = self.repo.create_pull( title=title, body=message, head=branch, base=self.base_branch ) return pr.url + logging.warning("Can't create pull requests for local repositories") + return None def get_pr(self, branch: str) -> str: return next(pull.html_url for pull in self.repo.get_pulls(head=branch)) @@ -177,7 +176,8 @@ class AppAutoUpdater: self.main_upstream = self.manifest.get("upstream", {}).get("code") - def run(self, edit: bool = False, commit: bool = False, pr: bool = False) -> bool | tuple[str | None, str | None, str | None]: + def run(self, edit: bool = False, commit: bool = False, pr: bool = False + ) -> bool | tuple[str | None, str | None, str | None]: has_updates = False main_version = None pr_url = None @@ -318,10 +318,10 @@ class AppAutoUpdater: if isinstance(assets, str) and infos["url"] == assets: print(f"URL for asset {name} is up to date") - return + return None if isinstance(assets, dict) and assets == {k: infos[k]["url"] for k in assets.keys()}: print(f"URLs for asset {name} are up to date") - return + return None print(f"Update needed for {name}") return new_version, assets, more_info @@ -341,6 +341,7 @@ class AppAutoUpdater: upstream = (infos.get("autoupdate", {}).get("upstream", self.main_upstream).strip("/")) _, remote_type, revision_type = strategy.split("_") + api: GithubAPI | GitlabAPI | GiteaForgejoAPI if remote_type == "github": assert ( upstream and upstream.startswith("https://github.com/") @@ -411,6 +412,7 @@ class AppAutoUpdater: version_format = infos.get("autoupdate", {}).get("force_version", "%Y.%m.%d") latest_version = latest_commit_date.strftime(version_format) return latest_version, latest_tarball, "" + return None def replace_version_and_asset_in_manifest(self, content: str, new_version: str, new_assets_urls: str | dict, current_assets: dict, is_main: bool): @@ -460,15 +462,15 @@ def paste_on_haste(data): class StdoutSwitch: class DummyFile: - def __init__(self): + def __init__(self) -> None: self.result = "" - def write(self, x): + def write(self, x: str) -> None: self.result += x def __init__(self) -> None: self.save_stdout = sys.stdout - sys.stdout = self.DummyFile() + sys.stdout = self.DummyFile() # type: ignore def reset(self) -> str: result = "" @@ -486,13 +488,14 @@ def run_autoupdate_for_multiprocessing(data) -> tuple[bool, str, Any] | None: stdoutswitch = StdoutSwitch() try: result = AppAutoUpdater(app).run(edit=edit, commit=commit, pr=pr) - if result is not False: - return True, app, result + if result is False: + return None + return True, app, result except Exception: - result = stdoutswitch.reset() + log_str = stdoutswitch.reset() import traceback t = traceback.format_exc() - return False, app, f"{result}\n{t}" + return False, app, f"{log_str}\n{t}" def main() -> None: From 1509a0c2eddb0a63874cdc8933c7bd0ce7726b57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Thu, 15 Feb 2024 15:14:19 +0100 Subject: [PATCH 4/4] Add back the logging_sender --- autoupdate_app_sources/autoupdate_app_sources.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/autoupdate_app_sources/autoupdate_app_sources.py b/autoupdate_app_sources/autoupdate_app_sources.py index 367b7e4..2285283 100755 --- a/autoupdate_app_sources/autoupdate_app_sources.py +++ b/autoupdate_app_sources/autoupdate_app_sources.py @@ -21,6 +21,7 @@ import github sys.path.insert(0, str(Path(__file__).parent.parent)) from rest_api import GithubAPI, GitlabAPI, GiteaForgejoAPI, RefType # noqa: E402,E501 pylint: disable=import-error,wrong-import-position +import appslib.logging_sender # noqa: E402 pylint: disable=import-error,wrong-import-position from appslib.utils import REPO_APPS_ROOT, get_catalog # noqa: E402 pylint: disable=import-error,wrong-import-position from app_caches import app_cache_folder # noqa: E402 pylint: disable=import-error,wrong-import-position @@ -75,7 +76,8 @@ def apps_to_run_auto_update_for() -> list[str]: if any("autoupdate" in source for source in sources.values()): relevant_apps.append(app) except Exception as e: - print(f"Error while loading {app}'s manifest: {e}") + logging.error(f"Error while loading {app}'s manifest: {e}") + raise e return relevant_apps @@ -509,10 +511,14 @@ def main() -> None: parser.add_argument("-j", "--processes", type=int, default=multiprocessing.cpu_count()) args = parser.parse_args() + appslib.logging_sender.enable() + if args.commit and not args.edit: - parser.error("--commit requires --edit") + logging.error("--commit requires --edit") + sys.exit(1) if args.pr and not args.commit: - parser.error("--pr requires --commit") + logging.error("--pr requires --commit") + sys.exit(1) # Handle apps or no apps apps = list(args.apps) if args.apps else apps_to_run_auto_update_for()