Skip to content

Commit

Permalink
Merge pull request #2 from cudoventures/user-agent
Browse files Browse the repository at this point in the history
User agent
  • Loading branch information
JungleCatSW authored Jun 21, 2024
2 parents 525d11f + 6b0d534 commit 30e7028
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
22 changes: 21 additions & 1 deletion docs/src/cudo_compute/cudo_api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import cudo_compute as cudo
import os
import importlib.metadata


home = os.path.expanduser("~")

Expand All @@ -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


Expand All @@ -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

Expand All @@ -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()
Expand Down
8 changes: 8 additions & 0 deletions helpers/cudo_api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import cudo_compute as cudo
import os
import importlib.metadata

home = os.path.expanduser("~")

Expand All @@ -17,6 +18,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


Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "cudo-compute"
version = "0.1.10"
version = "0.1.13"
authors = [
{ name = "Cudo Ventures", email = "dev@cudoventures.com" },
]
Expand Down

0 comments on commit 30e7028

Please sign in to comment.