Skip to content
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
11 changes: 10 additions & 1 deletion ascenderkit/api/mixins/has_copy.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
from typing import Any, Callable

from ascenderkit.api.pages import Page
from ascenderkit.utils import random_title
from ascenderkit.utils import PseudoNamespace, random_title


class HasCopy:
# Supplied by the Page this is mixed into: response-body fields arrive
# through Page.__getattr__, the rest are Page's own. Annotations rather
# than assignments, so nothing is created at runtime.
json: PseudoNamespace
connection: Any
get_related: Callable[..., Any]

def can_copy(self):
return self.get_related('copy').can_copy

Expand Down
7 changes: 7 additions & 0 deletions ascenderkit/api/mixins/has_create.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Any

from collections import defaultdict
import inspect

Expand Down Expand Up @@ -201,6 +203,11 @@ def _filter_ds_from_payload(obj, *a, **kw):


class HasCreate:
# Supplied by the Page this is mixed into: response-body fields arrive
# through Page.__getattr__, the rest are Page's own. Annotations rather
# than assignments, so nothing is created at runtime.
connection: Any

# For reference only. Use self.ds, or self._dependency_store if mutating.
dependencies = []
optional_dependencies = []
Expand Down
7 changes: 7 additions & 0 deletions ascenderkit/api/mixins/has_instance_groups.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
from typing import Any

from contextlib import suppress

import ascenderkit.exceptions as exc


class HasInstanceGroups:
# Supplied by the Page this is mixed into: response-body fields arrive
# through Page.__getattr__, the rest are Page's own. Annotations rather
# than assignments, so nothing is created at runtime.
related: Any

def add_instance_group(self, instance_group):
with suppress(exc.NoContent):
self.related['instance_groups'].post(dict(id=instance_group.id))
Expand Down
7 changes: 7 additions & 0 deletions ascenderkit/api/mixins/has_notifications.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Any

from contextlib import suppress

import ascenderkit.exceptions as exc
Expand All @@ -7,6 +9,11 @@


class HasNotifications:
# Supplied by the Page this is mixed into: response-body fields arrive
# through Page.__getattr__, the rest are Page's own. Annotations rather
# than assignments, so nothing is created at runtime.
related: Any

def add_notification_template(self, notification_template, endpoint="notification_templates_success"):
from ascenderkit.api.pages.workflow_job_templates import WorkflowJobTemplate

Expand Down
16 changes: 16 additions & 0 deletions ascenderkit/api/mixins/has_status.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from datetime import datetime, timezone
from typing import Any, Callable
import json

from ascenderkit.utils import poll_until
Expand All @@ -14,6 +15,21 @@ def bytes_to_str(obj):


class HasStatus:
# Supplied by the Page this is mixed into: the first three come from the
# response body through Page.__getattr__, the rest are Page's own methods.
# Annotations rather than assignments, so nothing is created at runtime and
# nothing shadows what Page provides.
status: str
id: int
type: str
related: Any
job_explanation: str
result_stdout: str
result_traceback: str
execution_environment: Any
get: Callable[..., Any]
walk: Callable[..., Any]

completed_statuses = ['successful', 'failed', 'error', 'canceled']
started_statuses = ['pending', 'running'] + completed_statuses

Expand Down
9 changes: 9 additions & 0 deletions ascenderkit/api/mixins/has_survey.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
from typing import Any, Callable

from ascenderkit.utils import random_title


class HasSurvey:
# Supplied by the Page this is mixed into: response-body fields arrive
# through Page.__getattr__, the rest are Page's own. Annotations rather
# than assignments, so nothing is created at runtime.
related: Any
survey_enabled: bool
patch: Callable[..., Any]

def add_survey(self, spec=None, name=None, description=None, required=False, enabled=True):
payload = dict(
name=name or 'Survey - {}'.format(random_title()),
Expand Down
5 changes: 5 additions & 0 deletions ascenderkit/api/mixins/has_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@


class HasVariables:
# Supplied by the Page this is mixed into: response-body fields arrive
# through Page.__getattr__, the rest are Page's own. Annotations rather
# than assignments, so nothing is created at runtime.
json: PseudoNamespace

@property
def variables(self):
return PseudoNamespace(yaml.safe_load(self.json.variables))
12 changes: 12 additions & 0 deletions ascenderkit/api/pages/page.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from contextlib import suppress
from typing import Any, Callable
import inspect
import logging
import json
Expand Down Expand Up @@ -339,6 +340,17 @@ def exception_from_status_code(status_code):


class PageList:
# Supplied by the Page this is mixed into: json, connection and r are set in
# Page.__init__, next and previous come from the response body through
# Page.__getattr__, and get is Page's own. Annotations rather than
# assignments, so nothing is created at runtime.
json: dict
connection: Any
r: Any
next: str | None
previous: str | None
get: Callable[..., Any]

NATURAL_KEY = None

@property
Expand Down