From 4fffb072e0b461c95f71db6571769f2ff2d208aa Mon Sep 17 00:00:00 2001 From: jungle Date: Fri, 21 Jun 2024 10:27:24 +0100 Subject: [PATCH 1/5] user agent --- docs/src/cudo_compute/cudo_api.py | 22 +++++++++++++++++++++- helpers/cudo_api.py | 9 +++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/docs/src/cudo_compute/cudo_api.py b/docs/src/cudo_compute/cudo_api.py index 9f4ee71..2f7a85b 100644 --- a/docs/src/cudo_compute/cudo_api.py +++ b/docs/src/cudo_compute/cudo_api.py @@ -1,5 +1,7 @@ import cudo_compute as cudo import os +import importlib.metadata + home = os.path.expanduser("~") @@ -17,6 +19,13 @@ def client(): configuration.host = "https://rest.compute.cudo.org" client = cudo.ApiClient(configuration) + version = '' + try: + version = importlib.metadata.version('cudo-compute') + except: + pass + + client.user_agent('cudo-compute-python-client/'+version) return client, None @@ -31,7 +40,10 @@ def get_api_key(): def get_project_id(): key_config, context_config, error = cudo.AuthConfig.load_config(home + '/.config/cudo/cudo.yml', "") if not error: - return context_config['project'], None + if 'project' in context_config: + return context_config['project'], None + else: + return None, Exception('No project set in configuration (cudo.yml)') else: return None, error @@ -43,6 +55,14 @@ def project_id(): return '' +def project_id_throwable(): + p, e = get_project_id() + if e is None: + return p + else: + raise e + + # APIs def api_keys(): c, err = client() diff --git a/helpers/cudo_api.py b/helpers/cudo_api.py index 8eca7f5..2f7a85b 100644 --- a/helpers/cudo_api.py +++ b/helpers/cudo_api.py @@ -1,5 +1,7 @@ import cudo_compute as cudo import os +import importlib.metadata + home = os.path.expanduser("~") @@ -17,6 +19,13 @@ def client(): configuration.host = "https://rest.compute.cudo.org" client = cudo.ApiClient(configuration) + version = '' + try: + version = importlib.metadata.version('cudo-compute') + except: + pass + + client.user_agent('cudo-compute-python-client/'+version) return client, None From d1de51ff7ce96507ce2dc4d750823cac99ef599d Mon Sep 17 00:00:00 2001 From: jungle Date: Fri, 21 Jun 2024 10:30:37 +0100 Subject: [PATCH 2/5] version bump --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 7209a0e..ca146d1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "cudo-compute" -version = "0.1.10" +version = "0.1.11" authors = [ { name = "Cudo Ventures", email = "dev@cudoventures.com" }, ] From e881a18ef2735c41a7ba16c76ed0ccc7ea958375 Mon Sep 17 00:00:00 2001 From: jungle Date: Fri, 21 Jun 2024 10:42:30 +0100 Subject: [PATCH 3/5] version bump --- docs/src/cudo_compute/cudo_api.py | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/src/cudo_compute/cudo_api.py b/docs/src/cudo_compute/cudo_api.py index 2f7a85b..58b82e6 100644 --- a/docs/src/cudo_compute/cudo_api.py +++ b/docs/src/cudo_compute/cudo_api.py @@ -25,7 +25,7 @@ def client(): except: pass - client.user_agent('cudo-compute-python-client/'+version) + client.user_agent = 'cudo-compute-python-client/'+version return client, None diff --git a/pyproject.toml b/pyproject.toml index ca146d1..14ba3d5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "cudo-compute" -version = "0.1.11" +version = "0.1.12" authors = [ { name = "Cudo Ventures", email = "dev@cudoventures.com" }, ] From dae9b9e653d1fc3bb13ed9d372f6b64407a2df9d Mon Sep 17 00:00:00 2001 From: jungle Date: Fri, 21 Jun 2024 10:46:40 +0100 Subject: [PATCH 4/5] version bump --- helpers/cudo_api.py | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/helpers/cudo_api.py b/helpers/cudo_api.py index 2f7a85b..58b82e6 100644 --- a/helpers/cudo_api.py +++ b/helpers/cudo_api.py @@ -25,7 +25,7 @@ def client(): except: pass - client.user_agent('cudo-compute-python-client/'+version) + client.user_agent = 'cudo-compute-python-client/'+version return client, None diff --git a/pyproject.toml b/pyproject.toml index 14ba3d5..3530cf2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "cudo-compute" -version = "0.1.12" +version = "0.1.13" authors = [ { name = "Cudo Ventures", email = "dev@cudoventures.com" }, ] From 6b0d5345d5d418a673134386b9499e992e66e783 Mon Sep 17 00:00:00 2001 From: jungle Date: Fri, 21 Jun 2024 12:45:40 +0100 Subject: [PATCH 5/5] format --- helpers/cudo_api.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/helpers/cudo_api.py b/helpers/cudo_api.py index 58b82e6..aeb3cb5 100644 --- a/helpers/cudo_api.py +++ b/helpers/cudo_api.py @@ -2,7 +2,6 @@ import os import importlib.metadata - home = os.path.expanduser("~") @@ -25,7 +24,7 @@ def client(): except: pass - client.user_agent = 'cudo-compute-python-client/'+version + client.user_agent = 'cudo-compute-python-client/' + version return client, None