Openembedded Bitbake Development
 help / color / mirror / Atom feed
* [bitbake-devel][PATCH] fetch2/crate: replace instance method monkey-patching with URL dispatch
@ 2026-05-07 14:37 thomas.perrot
  0 siblings, 0 replies; only message in thread
From: thomas.perrot @ 2026-05-07 14:37 UTC (permalink / raw)
  To: bitbake-devel; +Cc: thomas.petazzoni, Thomas Perrot

From: Thomas Perrot <thomas.perrot@bootlin.com>

Instead of overwriting self.latest_versionstring at init time to swap
in a different implementation, have latest_versionstring() inspect
ud.versionsurl and dispatch to the appropriate private helper.

This avoids surprising instance-level mutation and makes the branching
logic explicit and readable.

Signed-off-by: Thomas Perrot <thomas.perrot@bootlin.com>
---
 lib/bb/fetch2/crate.py | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/lib/bb/fetch2/crate.py b/lib/bb/fetch2/crate.py
index b46d4f1a9801..bb12f4e9b7c2 100644
--- a/lib/bb/fetch2/crate.py
+++ b/lib/bb/fetch2/crate.py
@@ -81,7 +81,6 @@ class Crate(Wget):
         if host == 'crates.io':
             ud.url = "https://static.crates.io/crates/%s/%s/download" % (name, version)
             ud.versionsurl = 'https://index.crates.io/' + self._generate_index_path(name)
-            self.latest_versionstring = self.latest_versionstring_from_index
         else:
             ud.url = "https://%s/%s/%s/download" % (host, name, version)
             ud.versionsurl = "https://%s/%s/versions" % (host, name)
@@ -158,7 +157,16 @@ class Crate(Wget):
 
     def latest_versionstring(self, ud, d):
         """
-        Return the latest version available when versionsurl is the [name]/versions URL.
+        Return the latest upstream version, dispatching to the appropriate
+        parser based on the versionsurl format.
+        """
+        if ud.versionsurl.startswith('https://index.crates.io/'):
+            return self._latest_versionstring_from_index(ud, d)
+        return self._latest_versionstring_from_api(ud, d)
+
+    def _latest_versionstring_from_api(self, ud, d):
+        """
+        Parse the latest version from a [name]/versions JSON API response.
         """
         json_data = json.loads(self._fetch_index(ud.versionsurl, ud, d))
         versions = [(0, i["num"], "") for i in json_data["versions"]]
@@ -166,10 +174,9 @@ class Crate(Wget):
 
         return (versions[-1][1], "") if versions else ("", "")
 
-    def latest_versionstring_from_index(self, ud, d):
+    def _latest_versionstring_from_index(self, ud, d):
         """
-        Return the latest version available when versionsurl is a Cargo index
-        file.
+        Parse the latest version from a Cargo sparse index file (NDJSON).
         https://doc.rust-lang.org/cargo/reference/registry-index.html#index-files
         """
         versions = []
-- 
2.54.0



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-05-07 14:38 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-07 14:37 [bitbake-devel][PATCH] fetch2/crate: replace instance method monkey-patching with URL dispatch thomas.perrot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox