chris.models.logged_in

Subclasses of classes from chris.models.data which are returned from an chris.client.authed.AuthenticatedClient. These classes may have read-write functionality on the ChRIS API.

  1"""
  2Subclasses of classes from `chris.models.data` which are returned
  3from an `chris.client.authed.AuthenticatedClient`.
  4These classes may have read-write functionality on the *ChRIS* API.
  5"""
  6from dataclasses import dataclass
  7from typing import Optional
  8
  9from serde import deserialize
 10
 11from chris.link import http
 12from chris.link.linked import LinkedModel
 13from chris.models.data import PluginInstanceData, FeedData, UserData, FeedNoteData
 14from chris.models.enums import PluginType
 15from chris.models.public import PublicPlugin
 16from chris.models.types import *
 17
 18
 19@deserialize
 20@dataclass(frozen=True)
 21class User(UserData, LinkedModel):
 22    pass  # TODO change_email, change_password
 23
 24
 25@deserialize
 26@dataclass(frozen=True)
 27class File(LinkedModel):
 28    """
 29    A file in CUBE.
 30    """
 31
 32    url: str
 33    fname: FileFname
 34    fsize: int
 35    file_resource: FileResourceUrl
 36
 37    @property
 38    def parent(self) -> str:
 39        """
 40        Get the parent (directory) of a file.
 41
 42        Examples
 43        --------
 44
 45        ```python
 46        assert file.fname == 'chris/feed_4/pl-dircopy_7/data/hello-world.txt'
 47        assert file.parent == 'chris/feed_4/pl-dircopy_7/data'
 48        ```
 49        """
 50        split = self.fname.split("/")
 51        if len(split) <= 1:
 52            return self.fname
 53        return "/".join(split[:-1])
 54
 55    # TODO download methods
 56
 57
 58@deserialize
 59@dataclass(frozen=True)
 60class PluginInstance(PluginInstanceData):
 61    @http.get("feed")
 62    async def get_feed(self) -> "Feed":
 63        """Get the feed this plugin instance belongs to."""
 64        ...
 65
 66    @http.put("url")
 67    async def set(
 68        self, title: Optional[str] = None, status: Optional[str] = None
 69    ) -> "PluginInstance":
 70        """
 71        Set the title or status of this plugin instance.
 72        """
 73        ...
 74
 75    @http.delete("url")
 76    async def delete(self) -> None:
 77        """Delete this plugin instance."""
 78        ...
 79
 80
 81@deserialize
 82@dataclass(frozen=True)
 83class FeedNote(FeedNoteData):
 84    @http.get("feed")
 85    async def get_feed(self) -> "Feed":
 86        """Get the feed this note belongs to."""
 87        ...
 88
 89    @http.put("url")
 90    async def set(
 91        self, title: Optional[str] = None, content: Optional[str] = None
 92    ) -> "FeedNote":
 93        """Change this note."""
 94        ...
 95
 96
 97@deserialize
 98@dataclass(frozen=True)
 99class Feed(FeedData):
100    """
101    A feed of a logged in user.
102    """
103
104    @http.put("url")
105    async def set(
106        self, name: Optional[str] = None, owner: Optional[str | Username] = None
107    ) -> "Feed":
108        """
109        Change the name or the owner of this feed.
110
111        Parameters
112        ----------
113        name
114            new name for this feed
115        owner
116            new owner for this feed
117        """
118        ...
119
120    @http.get("note")
121    async def get_note(self) -> FeedNote:
122        ...
123
124
125@deserialize
126@dataclass(frozen=True)
127class Plugin(PublicPlugin):
128    """
129    A ChRIS plugin. Create a plugin instance of this plugin to run it.
130    """
131
132    instances: ApiUrl
133
134    @http.post("instances")
135    async def _create_instance_raw(self, **kwargs) -> PluginInstance:
136        ...
137
138    async def create_instance(
139        self, previous: Optional[PluginInstance] = None, **kwargs
140    ) -> PluginInstance:
141        """
142        Create a plugin instance, i.e. "run" this plugin.
143
144        Parameters common to all plugins are described below.
145        Not all valid parameters are listed, since each plugin's parameters are different.
146        Some plugins have required parameters too.
147        To list all possible parameters, make a GET request to the specific plugin's instances link.
148
149        Parameters
150        ----------
151        previous: chris.models.data.PluginInstanceData
152            Previous plugin instance
153        previous_id: int
154            Previous plugin instance ID number (conflicts with `previous`)
155        compute_resource_name: Optional[str]
156            Name of compute resource to use
157        memory_limit: Optional[str]
158            Memory limit. Format is *x*Mi or *x*Gi where x is an integer.
159        cpu_limit: Optional[str]
160            CPU limit. Format is *x*m for *x* is an integer in millicores.
161        gpu_limit: Optional[int]
162            GPU limit.
163        """
164        if previous is not None:
165            if "previous_id" in kwargs:
166                raise ValueError("Cannot give both previous and previous_id.")
167            if not isinstance(previous, PluginInstance):
168                raise TypeError(f"{previous} is not a PluginInstance")
169            kwargs["previous_id"] = previous.id
170        if self.plugin_type is PluginType.fs:
171            if "previous_id" in kwargs:
172                raise ValueError(
173                    "Cannot create plugin instance of a fs-type plugin with a previous plugin instance."
174                )
175        elif "previous_id" not in kwargs:
176            raise ValueError(
177                f'Plugin type is "{self.plugin_type.value}" so previous is a required parameter.'
178            )
179        return await self._create_instance_raw(**kwargs)
@deserialize
@dataclass(frozen=True)
class User(chris.models.data.UserData, chris.link.linked.LinkedModel):
20@deserialize
21@dataclass(frozen=True)
22class User(UserData, LinkedModel):
23    pass  # TODO change_email, change_password
User( s: aiohttp.client.ClientSession, max_search_requests: int, url: chris.models.types.UserUrl, id: chris.models.types.UserId, username: chris.models.types.Username, email: str)
Inherited Members
chris.link.linked.Linked
max_search_requests
@deserialize
@dataclass(frozen=True)
class File(chris.link.linked.LinkedModel):
26@deserialize
27@dataclass(frozen=True)
28class File(LinkedModel):
29    """
30    A file in CUBE.
31    """
32
33    url: str
34    fname: FileFname
35    fsize: int
36    file_resource: FileResourceUrl
37
38    @property
39    def parent(self) -> str:
40        """
41        Get the parent (directory) of a file.
42
43        Examples
44        --------
45
46        ```python
47        assert file.fname == 'chris/feed_4/pl-dircopy_7/data/hello-world.txt'
48        assert file.parent == 'chris/feed_4/pl-dircopy_7/data'
49        ```
50        """
51        split = self.fname.split("/")
52        if len(split) <= 1:
53            return self.fname
54        return "/".join(split[:-1])
55
56    # TODO download methods

A file in CUBE.

File( s: aiohttp.client.ClientSession, max_search_requests: int, url: str, fname: chris.models.types.FileFname, fsize: int, file_resource: chris.models.types.FileResourceUrl)
parent: str

Get the parent (directory) of a file.

Examples
assert file.fname == 'chris/feed_4/pl-dircopy_7/data/hello-world.txt'
assert file.parent == 'chris/feed_4/pl-dircopy_7/data'
Inherited Members
chris.link.linked.Linked
max_search_requests
@deserialize
@dataclass(frozen=True)
class PluginInstance(chris.models.data.PluginInstanceData):
59@deserialize
60@dataclass(frozen=True)
61class PluginInstance(PluginInstanceData):
62    @http.get("feed")
63    async def get_feed(self) -> "Feed":
64        """Get the feed this plugin instance belongs to."""
65        ...
66
67    @http.put("url")
68    async def set(
69        self, title: Optional[str] = None, status: Optional[str] = None
70    ) -> "PluginInstance":
71        """
72        Set the title or status of this plugin instance.
73        """
74        ...
75
76    @http.delete("url")
77    async def delete(self) -> None:
78        """Delete this plugin instance."""
79        ...
PluginInstance( s: aiohttp.client.ClientSession, max_search_requests: int, url: chris.models.types.PluginInstanceUrl, id: chris.models.types.PluginInstanceId, title: str, compute_resource_name: chris.models.types.ComputeResourceName, plugin_id: chris.models.types.PluginId, plugin_name: chris.models.types.PluginName, plugin_version: chris.models.types.PluginVersion, plugin_type: chris.models.enums.PluginType, pipeline_inst: Optional[int], feed_id: chris.models.types.FeedId, start_date: datetime.datetime, end_date: datetime.datetime, output_path: chris.models.types.CubeFilePath, status: chris.models.enums.Status, summary: str, raw: str, owner_username: chris.models.types.Username, cpu_limit: int, memory_limit: int, number_of_workers: int, gpu_limit: int, error_code: chris.models.types.CUBEErrorCode, previous: Optional[chris.models.types.PluginInstanceUrl], feed: chris.models.types.FeedUrl, plugin: chris.models.types.PluginUrl, descendants: chris.models.types.DescendantsUrl, files: chris.models.types.FilesUrl, parameters: chris.models.types.PluginInstanceParametersUrl, compute_resource: chris.models.types.ComputeResourceUrl, splits: chris.models.types.SplitsUrl, previous_id: Optional[int] = None, size: Optional[int] = None, template: Optional[dict] = None)
@http.get('feed')
async def get_feed(self) -> chris.models.logged_in.Feed:
62    @http.get("feed")
63    async def get_feed(self) -> "Feed":
64        """Get the feed this plugin instance belongs to."""
65        ...

Get the feed this plugin instance belongs to.

@http.put('url')
async def set( self, title: Optional[str] = None, status: Optional[str] = None) -> chris.models.logged_in.PluginInstance:
67    @http.put("url")
68    async def set(
69        self, title: Optional[str] = None, status: Optional[str] = None
70    ) -> "PluginInstance":
71        """
72        Set the title or status of this plugin instance.
73        """
74        ...

Set the title or status of this plugin instance.

@http.delete('url')
async def delete(self) -> None:
76    @http.delete("url")
77    async def delete(self) -> None:
78        """Delete this plugin instance."""
79        ...

Delete this plugin instance.

Inherited Members
chris.models.data.PluginInstanceData
previous_id
size
template
chris.link.linked.Linked
max_search_requests
@deserialize
@dataclass(frozen=True)
class FeedNote(chris.models.data.FeedNoteData):
82@deserialize
83@dataclass(frozen=True)
84class FeedNote(FeedNoteData):
85    @http.get("feed")
86    async def get_feed(self) -> "Feed":
87        """Get the feed this note belongs to."""
88        ...
89
90    @http.put("url")
91    async def set(
92        self, title: Optional[str] = None, content: Optional[str] = None
93    ) -> "FeedNote":
94        """Change this note."""
95        ...
FeedNote( s: aiohttp.client.ClientSession, max_search_requests: int, url: chris.models.types.FeedUrl, id: chris.models.types.NoteId, title: str, content: str, feed: chris.models.types.FeedUrl)
@http.get('feed')
async def get_feed(self) -> chris.models.logged_in.Feed:
85    @http.get("feed")
86    async def get_feed(self) -> "Feed":
87        """Get the feed this note belongs to."""
88        ...

Get the feed this note belongs to.

@http.put('url')
async def set( self, title: Optional[str] = None, content: Optional[str] = None) -> chris.models.logged_in.FeedNote:
90    @http.put("url")
91    async def set(
92        self, title: Optional[str] = None, content: Optional[str] = None
93    ) -> "FeedNote":
94        """Change this note."""
95        ...

Change this note.

Inherited Members
chris.link.linked.Linked
max_search_requests
@deserialize
@dataclass(frozen=True)
class Feed(chris.models.data.FeedData):
 98@deserialize
 99@dataclass(frozen=True)
100class Feed(FeedData):
101    """
102    A feed of a logged in user.
103    """
104
105    @http.put("url")
106    async def set(
107        self, name: Optional[str] = None, owner: Optional[str | Username] = None
108    ) -> "Feed":
109        """
110        Change the name or the owner of this feed.
111
112        Parameters
113        ----------
114        name
115            new name for this feed
116        owner
117            new owner for this feed
118        """
119        ...
120
121    @http.get("note")
122    async def get_note(self) -> FeedNote:
123        ...

A feed of a logged in user.

Feed( s: aiohttp.client.ClientSession, max_search_requests: int, url: chris.models.types.FeedUrl, id: chris.models.types.FeedId, creation_date: datetime.datetime, modification_date: datetime.datetime, name: str, creator_username: chris.models.types.Username, created_jobs: int, waiting_jobs: int, scheduled_jobs: int, started_jobs: int, registering_jobs: int, finished_jobs: int, errored_jobs: int, cancelled_jobs: int, owner: list[chris.models.types.UserUrl], note: chris.models.types.NoteUrl, tags: chris.models.types.TagsUrl, taggings: chris.models.types.TaggingsUrl, comments: chris.models.types.CommentsUrl, files: chris.models.types.FilesUrl, plugin_instances: chris.models.types.PluginInstancesUrl)
@http.put('url')
async def set( self, name: Optional[str] = None, owner: Union[str, chris.models.types.Username, NoneType] = None) -> chris.models.logged_in.Feed:
105    @http.put("url")
106    async def set(
107        self, name: Optional[str] = None, owner: Optional[str | Username] = None
108    ) -> "Feed":
109        """
110        Change the name or the owner of this feed.
111
112        Parameters
113        ----------
114        name
115            new name for this feed
116        owner
117            new owner for this feed
118        """
119        ...

Change the name or the owner of this feed.

Parameters
  • name: new name for this feed
  • owner: new owner for this feed
@http.get('note')
async def get_note(self) -> chris.models.logged_in.FeedNote:
121    @http.get("note")
122    async def get_note(self) -> FeedNote:
123        ...
Inherited Members
chris.link.linked.Linked
max_search_requests
@deserialize
@dataclass(frozen=True)
class Plugin(chris.models.public.PublicPlugin):
126@deserialize
127@dataclass(frozen=True)
128class Plugin(PublicPlugin):
129    """
130    A ChRIS plugin. Create a plugin instance of this plugin to run it.
131    """
132
133    instances: ApiUrl
134
135    @http.post("instances")
136    async def _create_instance_raw(self, **kwargs) -> PluginInstance:
137        ...
138
139    async def create_instance(
140        self, previous: Optional[PluginInstance] = None, **kwargs
141    ) -> PluginInstance:
142        """
143        Create a plugin instance, i.e. "run" this plugin.
144
145        Parameters common to all plugins are described below.
146        Not all valid parameters are listed, since each plugin's parameters are different.
147        Some plugins have required parameters too.
148        To list all possible parameters, make a GET request to the specific plugin's instances link.
149
150        Parameters
151        ----------
152        previous: chris.models.data.PluginInstanceData
153            Previous plugin instance
154        previous_id: int
155            Previous plugin instance ID number (conflicts with `previous`)
156        compute_resource_name: Optional[str]
157            Name of compute resource to use
158        memory_limit: Optional[str]
159            Memory limit. Format is *x*Mi or *x*Gi where x is an integer.
160        cpu_limit: Optional[str]
161            CPU limit. Format is *x*m for *x* is an integer in millicores.
162        gpu_limit: Optional[int]
163            GPU limit.
164        """
165        if previous is not None:
166            if "previous_id" in kwargs:
167                raise ValueError("Cannot give both previous and previous_id.")
168            if not isinstance(previous, PluginInstance):
169                raise TypeError(f"{previous} is not a PluginInstance")
170            kwargs["previous_id"] = previous.id
171        if self.plugin_type is PluginType.fs:
172            if "previous_id" in kwargs:
173                raise ValueError(
174                    "Cannot create plugin instance of a fs-type plugin with a previous plugin instance."
175                )
176        elif "previous_id" not in kwargs:
177            raise ValueError(
178                f'Plugin type is "{self.plugin_type.value}" so previous is a required parameter.'
179            )
180        return await self._create_instance_raw(**kwargs)

A ChRIS plugin. Create a plugin instance of this plugin to run it.

Plugin( s: aiohttp.client.ClientSession, max_search_requests: int, url: chris.models.types.PluginUrl, id: chris.models.types.PluginId, name: chris.models.types.PluginName, version: chris.models.types.PluginVersion, dock_image: chris.models.types.ImageTag, public_repo: str, plugin_type: chris.models.enums.PluginType, instances: chris.models.types.ApiUrl)
async def create_instance( self, previous: Optional[chris.models.logged_in.PluginInstance] = None, **kwargs) -> chris.models.logged_in.PluginInstance:
139    async def create_instance(
140        self, previous: Optional[PluginInstance] = None, **kwargs
141    ) -> PluginInstance:
142        """
143        Create a plugin instance, i.e. "run" this plugin.
144
145        Parameters common to all plugins are described below.
146        Not all valid parameters are listed, since each plugin's parameters are different.
147        Some plugins have required parameters too.
148        To list all possible parameters, make a GET request to the specific plugin's instances link.
149
150        Parameters
151        ----------
152        previous: chris.models.data.PluginInstanceData
153            Previous plugin instance
154        previous_id: int
155            Previous plugin instance ID number (conflicts with `previous`)
156        compute_resource_name: Optional[str]
157            Name of compute resource to use
158        memory_limit: Optional[str]
159            Memory limit. Format is *x*Mi or *x*Gi where x is an integer.
160        cpu_limit: Optional[str]
161            CPU limit. Format is *x*m for *x* is an integer in millicores.
162        gpu_limit: Optional[int]
163            GPU limit.
164        """
165        if previous is not None:
166            if "previous_id" in kwargs:
167                raise ValueError("Cannot give both previous and previous_id.")
168            if not isinstance(previous, PluginInstance):
169                raise TypeError(f"{previous} is not a PluginInstance")
170            kwargs["previous_id"] = previous.id
171        if self.plugin_type is PluginType.fs:
172            if "previous_id" in kwargs:
173                raise ValueError(
174                    "Cannot create plugin instance of a fs-type plugin with a previous plugin instance."
175                )
176        elif "previous_id" not in kwargs:
177            raise ValueError(
178                f'Plugin type is "{self.plugin_type.value}" so previous is a required parameter.'
179            )
180        return await self._create_instance_raw(**kwargs)

Create a plugin instance, i.e. "run" this plugin.

Parameters common to all plugins are described below. Not all valid parameters are listed, since each plugin's parameters are different. Some plugins have required parameters too. To list all possible parameters, make a GET request to the specific plugin's instances link.

Parameters
  • previous (chris.models.data.PluginInstanceData): Previous plugin instance
  • previous_id (int): Previous plugin instance ID number (conflicts with previous)
  • compute_resource_name (Optional[str]): Name of compute resource to use
  • memory_limit (Optional[str]): Memory limit. Format is xMi or xGi where x is an integer.
  • cpu_limit (Optional[str]): CPU limit. Format is xm for x is an integer in millicores.
  • gpu_limit (Optional[int]): GPU limit.
Inherited Members
chris.link.linked.Linked
max_search_requests