From 7a36ccf17ab36303e95a908df2247104136847dd Mon Sep 17 00:00:00 2001
From: Andre Anjos <andre.dos.anjos@gmail.com>
Date: Tue, 8 Jun 2021 10:01:37 +0200
Subject: [PATCH] [mirror] Add support for osx-arm64 architecture (mac m1)

---
 bob/devtools/mirror.py         | 12 ++++++++++--
 bob/devtools/scripts/mirror.py | 15 +++++++++++++--
 2 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/bob/devtools/mirror.py b/bob/devtools/mirror.py
index 9c13a54b..1d05fab9 100644
--- a/bob/devtools/mirror.py
+++ b/bob/devtools/mirror.py
@@ -80,7 +80,7 @@ def get_json(channel, platform, name):
     ----------
     channel : str
         Complete channel URL
-    platform : {'linux-64', 'osx-64', 'noarch'}
+    platform : {'linux-64', 'osx-64', 'osx-arm64', 'noarch'}
         The platform of interest
     name : str
         The name of the file to retrieve.  If the name ends in '.bz2', then it
@@ -90,11 +90,18 @@ def get_json(channel, platform, name):
     -------
     repodata : dict
         contents of repodata.json
+
+    Raises
+    ------
+    RuntimeError :
+        If the URL cannot be reached
     """
 
     url = channel + "/" + platform + "/" + name
     logger.debug("[checking] %s...", url)
     r = requests.get(url, allow_redirects=True, stream=True)
+    if r.status_code == 404:
+        raise RuntimeError("URL '%s' does not exist" % url)
     size = r.headers.get("Content-length", "??")
     logger.info("[download] %s (%s bytes)...", url, size)
 
@@ -374,7 +381,8 @@ def checksum_packages(repodata, dest_dir, arch, packages):
     dest_dir : str
         Path leading to local mirror
     arch : str
-        Current architecture being considered (e.g. noarch, linux-64 or osx-64)
+        Current architecture being considered (e.g. noarch, linux-64, osx-64,
+        osx-arm64)
     packages : list
         List of packages that are available locally, by name
 
diff --git a/bob/devtools/scripts/mirror.py b/bob/devtools/scripts/mirror.py
index fcd9de0c..3ffbeaec 100644
--- a/bob/devtools/scripts/mirror.py
+++ b/bob/devtools/scripts/mirror.py
@@ -169,7 +169,7 @@ def mirror(
         logger.warn("!!!! DRY RUN MODE !!!!")
         logger.warn("Nothing will be really mirrored")
 
-    DEFAULT_SUBDIRS = ["noarch", "linux-64", "osx-64"]
+    DEFAULT_SUBDIRS = ["noarch", "linux-64", "osx-64", "osx-arm64"]
 
     noarch = os.path.join(dest_dir, "noarch")
     if not os.path.exists(noarch):  # first time
@@ -188,7 +188,18 @@ def mirror(
 
     for arch in DEFAULT_SUBDIRS:
 
-        remote_repodata = get_json(channel_url, arch, "repodata_from_packages.json.bz2")
+        try:
+            remote_repodata = get_json(
+                channel_url, arch, "repodata_from_packages.json.bz2"
+            )
+        except RuntimeError:
+            # the architecture does not exist?
+            logger.warning(
+                "Architecture %s does not seem to exist at channel %s - ignoring...",
+                arch,
+                channel_url,
+            )
+            continue
 
         # merge all available packages into one single dictionary
         remote_package_info = {}
-- 
GitLab