Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User agent #2

Merged
merged 5 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = "[email protected]" },
]
Expand Down
Loading