From ec22dbe1360ee82dc542d28798bb9751ed1f8e06 Mon Sep 17 00:00:00 2001 From: Matthieu Muffato Date: Wed, 7 Sep 2022 21:08:31 +0100 Subject: [PATCH] Added a cache in `library_url` None is a valid value, so to distinguish between it and "_library_url hasn't been computed yet", I check the attribute's presence. --- shpc/main/registry/remote.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/shpc/main/registry/remote.py b/shpc/main/registry/remote.py index 28952447c..cacfd2a84 100644 --- a/shpc/main/registry/remote.py +++ b/shpc/main/registry/remote.py @@ -126,16 +126,21 @@ def library_url(self): """ Retrieve the web url, either pages or (eventually) custom. """ + if hasattr(self, "_library_url"): # Cannot do "if self._library_url" because None is a valid value + return self._library_url url = self.url if url.endswith(".git"): url = url[:-4] parts = url.split("/") domain = parts[2] if domain in self.library_url_schemes: - return self.library_url_schemes[domain] % ( + self._library_url = self.library_url_schemes[domain] % ( parts[3], "/".join(parts[4:]), ) + else: + self._library_url = None + return self._library_url def exists(self, name): """ @@ -184,11 +189,10 @@ def _update_cache(self, force=False): if self._cache and not force: return - library_url = self.library_url - if library_url is None: + if self.library_url is None: return self._update_clone_cache() # Check for exposed library API on GitHub or GitLab pages - response = requests.get(library_url) + response = requests.get(self.library_url) if response.status_code != 200: return self._update_clone_cache() self._cache = response.json()