canvas 0.1.4__py3-none-any.whl → 0.1.5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of canvas might be problematic. Click here for more details.

Files changed (70) hide show
  1. canvas-0.1.5.dist-info/METADATA +176 -0
  2. canvas-0.1.5.dist-info/RECORD +66 -0
  3. {canvas-0.1.4.dist-info → canvas-0.1.5.dist-info}/WHEEL +1 -1
  4. canvas-0.1.5.dist-info/entry_points.txt +3 -0
  5. canvas_cli/apps/__init__.py +0 -0
  6. canvas_cli/apps/auth/__init__.py +3 -0
  7. canvas_cli/apps/auth/tests.py +142 -0
  8. canvas_cli/apps/auth/utils.py +163 -0
  9. canvas_cli/apps/logs/__init__.py +3 -0
  10. canvas_cli/apps/logs/logs.py +59 -0
  11. canvas_cli/apps/plugin/__init__.py +9 -0
  12. canvas_cli/apps/plugin/plugin.py +286 -0
  13. canvas_cli/apps/plugin/tests.py +32 -0
  14. canvas_cli/conftest.py +28 -0
  15. canvas_cli/main.py +78 -0
  16. canvas_cli/templates/plugins/default/cookiecutter.json +4 -0
  17. canvas_cli/templates/plugins/default/{{ cookiecutter.__project_slug }}/CANVAS_MANIFEST.json +29 -0
  18. canvas_cli/templates/plugins/default/{{ cookiecutter.__project_slug }}/README.md +12 -0
  19. canvas_cli/templates/plugins/default/{{ cookiecutter.__project_slug }}/protocols/__init__.py +0 -0
  20. canvas_cli/templates/plugins/default/{{ cookiecutter.__project_slug }}/protocols/my_protocol.py +55 -0
  21. canvas_cli/tests.py +11 -0
  22. canvas_cli/utils/__init__.py +0 -0
  23. canvas_cli/utils/context/__init__.py +3 -0
  24. canvas_cli/utils/context/context.py +172 -0
  25. canvas_cli/utils/context/tests.py +130 -0
  26. canvas_cli/utils/print/__init__.py +3 -0
  27. canvas_cli/utils/print/print.py +60 -0
  28. canvas_cli/utils/print/tests.py +70 -0
  29. canvas_cli/utils/urls/__init__.py +3 -0
  30. canvas_cli/utils/urls/tests.py +12 -0
  31. canvas_cli/utils/urls/urls.py +27 -0
  32. canvas_cli/utils/validators/__init__.py +3 -0
  33. canvas_cli/utils/validators/manifest_schema.py +80 -0
  34. canvas_cli/utils/validators/tests.py +36 -0
  35. canvas_cli/utils/validators/validators.py +40 -0
  36. canvas_sdk/__init__.py +0 -0
  37. canvas_sdk/commands/__init__.py +27 -0
  38. canvas_sdk/commands/base.py +118 -0
  39. canvas_sdk/commands/commands/assess.py +48 -0
  40. canvas_sdk/commands/commands/diagnose.py +44 -0
  41. canvas_sdk/commands/commands/goal.py +48 -0
  42. canvas_sdk/commands/commands/history_present_illness.py +15 -0
  43. canvas_sdk/commands/commands/medication_statement.py +28 -0
  44. canvas_sdk/commands/commands/plan.py +15 -0
  45. canvas_sdk/commands/commands/prescribe.py +48 -0
  46. canvas_sdk/commands/commands/questionnaire.py +17 -0
  47. canvas_sdk/commands/commands/reason_for_visit.py +36 -0
  48. canvas_sdk/commands/commands/stop_medication.py +18 -0
  49. canvas_sdk/commands/commands/update_goal.py +48 -0
  50. canvas_sdk/commands/constants.py +9 -0
  51. canvas_sdk/commands/tests/test_utils.py +195 -0
  52. canvas_sdk/commands/tests/tests.py +407 -0
  53. canvas_sdk/data/__init__.py +0 -0
  54. canvas_sdk/effects/__init__.py +1 -0
  55. canvas_sdk/effects/banner_alert/banner_alert.py +37 -0
  56. canvas_sdk/effects/banner_alert/constants.py +19 -0
  57. canvas_sdk/effects/base.py +30 -0
  58. canvas_sdk/events/__init__.py +1 -0
  59. canvas_sdk/protocols/__init__.py +1 -0
  60. canvas_sdk/protocols/base.py +12 -0
  61. canvas_sdk/tests/__init__.py +0 -0
  62. canvas_sdk/utils/__init__.py +3 -0
  63. canvas_sdk/utils/http.py +72 -0
  64. canvas_sdk/utils/tests.py +63 -0
  65. canvas_sdk/views/__init__.py +0 -0
  66. canvas/main.py +0 -19
  67. canvas-0.1.4.dist-info/METADATA +0 -285
  68. canvas-0.1.4.dist-info/RECORD +0 -6
  69. canvas-0.1.4.dist-info/entry_points.txt +0 -3
  70. {canvas → canvas_cli}/__init__.py +0 -0
@@ -0,0 +1 @@
1
+ from canvas_sdk.protocols.base import BaseProtocol
@@ -0,0 +1,12 @@
1
+ import json
2
+
3
+
4
+ class BaseProtocol:
5
+ """
6
+ The class that protocols inherit from.
7
+ """
8
+
9
+ def __init__(self, event, secrets=None) -> None:
10
+ self.event = event
11
+ self.context = json.loads(event.context)
12
+ self.secrets = secrets or {}
File without changes
@@ -0,0 +1,3 @@
1
+ from canvas_sdk.utils.http import Http
2
+
3
+ __all__ = ("Http",)
@@ -0,0 +1,72 @@
1
+ import time
2
+ from functools import wraps
3
+ from typing import Any, Callable, TypeVar
4
+
5
+ import requests
6
+ import statsd
7
+
8
+ F = TypeVar("F", bound=Callable)
9
+
10
+
11
+ class Http:
12
+ """A helper class for completing HTTP calls with metrics tracking."""
13
+
14
+ def __init__(self) -> None:
15
+ self.session = requests.Session()
16
+ self.statsd_client = statsd.StatsClient()
17
+
18
+ @staticmethod
19
+ def measure_time(fn: F | None = None) -> Callable[[F], F] | F:
20
+ """A decorator to store timing of HTTP calls."""
21
+
22
+ def _decorator(fn: F) -> F:
23
+ @wraps(fn)
24
+ def wrapper(self: "Http", *args: Any, **kwargs: Any) -> Any:
25
+ start_time = time.time()
26
+ result = fn(self, *args, **kwargs)
27
+ end_time = time.time()
28
+ timing = int((end_time - start_time) * 1000)
29
+ self.statsd_client.timing(f"http_{fn.__name__}", timing)
30
+ return result
31
+
32
+ return wrapper
33
+
34
+ return _decorator(fn) if fn else _decorator
35
+
36
+ @measure_time
37
+ def get(self, url: str, headers: dict = {}) -> requests.Response:
38
+ """Sends a GET request."""
39
+ return self.session.get(url, headers=headers)
40
+
41
+ @measure_time
42
+ def post(
43
+ self,
44
+ url: str,
45
+ json: dict | None = None,
46
+ data: dict | str | list | bytes | None = None,
47
+ headers: dict = {},
48
+ ) -> requests.Response:
49
+ """Sends a POST request."""
50
+ return self.session.post(url, json=json, data=data, headers=headers)
51
+
52
+ @measure_time
53
+ def put(
54
+ self,
55
+ url: str,
56
+ json: dict | None = None,
57
+ data: dict | str | list | bytes | None = None,
58
+ headers: dict = {},
59
+ ) -> requests.Response:
60
+ """Sends a PUT request."""
61
+ return self.session.put(url, json=json, data=data, headers=headers)
62
+
63
+ @measure_time
64
+ def patch(
65
+ self,
66
+ url: str,
67
+ json: dict | None = None,
68
+ data: dict | str | list | bytes | None = None,
69
+ headers: dict = {},
70
+ ) -> requests.Response:
71
+ """Sends a PATCH request."""
72
+ return self.session.patch(url, json=json, data=data, headers=headers)
@@ -0,0 +1,63 @@
1
+ from unittest.mock import MagicMock, patch
2
+
3
+ from canvas_sdk.utils import Http
4
+
5
+
6
+ @patch("requests.Session.get")
7
+ def test_http_get(mock_get: MagicMock) -> None:
8
+ http = Http()
9
+ http.get("https://www.canvasmedical.com/", headers={"Authorization": "Bearer as;ldkfjdkj"})
10
+ mock_get.assert_called_once_with(
11
+ "https://www.canvasmedical.com/", headers={"Authorization": "Bearer as;ldkfjdkj"}
12
+ )
13
+
14
+
15
+ @patch("requests.Session.post")
16
+ def test_http_post(mock_post: MagicMock) -> None:
17
+ http = Http()
18
+ http.post(
19
+ "https://www.canvasmedical.com/",
20
+ json={"hey": "hi"},
21
+ data="grant-type=client_credentials",
22
+ headers={"Content-type": "application/json"},
23
+ )
24
+ mock_post.assert_called_once_with(
25
+ "https://www.canvasmedical.com/",
26
+ json={"hey": "hi"},
27
+ data="grant-type=client_credentials",
28
+ headers={"Content-type": "application/json"},
29
+ )
30
+
31
+
32
+ @patch("requests.Session.put")
33
+ def test_http_put(mock_put: MagicMock) -> None:
34
+ http = Http()
35
+ http.put(
36
+ "https://www.canvasmedical.com/",
37
+ json={"hey": "hi"},
38
+ data="grant-type=client_credentials",
39
+ headers={"Content-type": "application/json"},
40
+ )
41
+ mock_put.assert_called_once_with(
42
+ "https://www.canvasmedical.com/",
43
+ json={"hey": "hi"},
44
+ data="grant-type=client_credentials",
45
+ headers={"Content-type": "application/json"},
46
+ )
47
+
48
+
49
+ @patch("requests.Session.patch")
50
+ def test_http_patch(mock_patch: MagicMock) -> None:
51
+ http = Http()
52
+ http.patch(
53
+ "https://www.canvasmedical.com/",
54
+ json={"hey": "hi"},
55
+ data="grant-type=client_credentials",
56
+ headers={"Content-type": "application/json"},
57
+ )
58
+ mock_patch.assert_called_once_with(
59
+ "https://www.canvasmedical.com/",
60
+ json={"hey": "hi"},
61
+ data="grant-type=client_credentials",
62
+ headers={"Content-type": "application/json"},
63
+ )
File without changes
canvas/main.py DELETED
@@ -1,19 +0,0 @@
1
- import typer
2
- from canvas_brush.apps.auth import app as auth_app
3
- from canvas_brush.apps.logs import logs as logs_command
4
- from canvas_brush.apps.plugin import app as plugin_app
5
- from canvas_brush.main import main, print_config
6
-
7
- app = typer.Typer()
8
-
9
- app.add_typer(auth_app, name="auth", help="Manage authenticating in Canvas instances")
10
- app.add_typer(plugin_app, name="plugin", help="Manage plugins in a Canvas instance")
11
-
12
- app.command(short_help="Listens and prints log streams from the instance")(logs_command)
13
- app.command(short_help="Print the config and exit")(print_config)
14
-
15
- app.callback()(main)
16
-
17
-
18
- if __name__ == "__main__":
19
- app()
@@ -1,285 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: canvas
3
- Version: 0.1.4
4
- Summary: SDK to customize event-driven actions in your Canvas instance
5
- License: MIT
6
- Author: Canvas Team
7
- Author-email: engineering@canvasmedical.com
8
- Requires-Python: >=3.12,<4.0
9
- Classifier: License :: OSI Approved :: MIT License
10
- Classifier: Programming Language :: Python :: 3
11
- Classifier: Programming Language :: Python :: 3.12
12
- Requires-Dist: canvas-brush (>=1.2.2,<2.0.0)
13
- Requires-Dist: canvas-core (>=0.84.1,<0.85.0)
14
- Requires-Dist: typer (>=0.9.0,<0.10.0)
15
- Description-Content-Type: text/markdown
16
-
17
- ### Getting Started
18
-
19
- `pip install canvas`
20
-
21
- **Usage**:
22
-
23
- ```console
24
- $ canvas [OPTIONS] COMMAND [ARGS]...
25
- ```
26
-
27
- **Options**:
28
-
29
- - `--no-ansi`: Disable colorized output
30
- - `--version`
31
- - `--verbose`: Show extra output
32
- - `--install-completion`: Install completion for the current shell.
33
- - `--show-completion`: Show completion for the current shell, to copy it or customize the installation.
34
- - `--help`: Show this message and exit.
35
-
36
- **Commands**:
37
-
38
- - `auth`: Manage authenticating in Canvas instances
39
- - `logs`: Listens and prints log streams from the instance
40
- - `plugin`: Manage plugins in a Canvas instance
41
- - `print-config`: Print the config and exit
42
-
43
- ## `canvas auth`
44
-
45
- Manage authenticating in Canvas instances
46
-
47
- **Usage**:
48
-
49
- ```console
50
- $ canvas auth [OPTIONS] COMMAND [ARGS]...
51
- ```
52
-
53
- **Options**:
54
-
55
- - `--help`: Show this message and exit.
56
-
57
- **Commands**:
58
-
59
- - `add-api-key`: Add a host=api-key pair to the keychain, so it can be used in other requests
60
- - `get-api-key`: Print the api_key for the given host
61
- - `remove-api-key`: Removes a host from the keychain, and as the default if it's the one
62
- - `set-default-host`: Set the host as the default host in the config file
63
-
64
- ### `canvas auth add-api-key`
65
-
66
- Add a host=api-key pair to the keychain, so it can be used in other requests.
67
- Optionally set a default so `--host` isn't required everywhere
68
-
69
- **Usage**:
70
-
71
- ```console
72
- $ canvas auth add-api-key [OPTIONS]
73
- ```
74
-
75
- **Options**:
76
-
77
- - `--host TEXT`: [required]
78
- - `--api-key TEXT`: [required]
79
- - `--is-default / --no-is-default`: [required]
80
- - `--help`: Show this message and exit.
81
-
82
- ### `canvas auth get-api-key`
83
-
84
- Print the api_key for the given host.
85
-
86
- **Usage**:
87
-
88
- ```console
89
- $ canvas auth get-api-key [OPTIONS] HOST
90
- ```
91
-
92
- **Arguments**:
93
-
94
- - `HOST`: [required]
95
-
96
- **Options**:
97
-
98
- - `--help`: Show this message and exit.
99
-
100
- ### `canvas auth remove-api-key`
101
-
102
- Removes a host from the keychain, and as the default if it's the one.
103
- This method always succeeds, regardless of username existence.
104
-
105
- **Usage**:
106
-
107
- ```console
108
- $ canvas auth remove-api-key [OPTIONS] HOST
109
- ```
110
-
111
- **Arguments**:
112
-
113
- - `HOST`: [required]
114
-
115
- **Options**:
116
-
117
- - `--help`: Show this message and exit.
118
-
119
- ### `canvas auth set-default-host`
120
-
121
- Set the host as the default host in the config file. Validates it exists in the keychain.
122
-
123
- **Usage**:
124
-
125
- ```console
126
- $ canvas auth set-default-host [OPTIONS] HOST
127
- ```
128
-
129
- **Arguments**:
130
-
131
- - `HOST`: [required]
132
-
133
- **Options**:
134
-
135
- - `--help`: Show this message and exit.
136
-
137
- ## `canvas logs`
138
-
139
- Listens and prints log streams from the instance.
140
-
141
- **Usage**:
142
-
143
- ```console
144
- $ canvas logs [OPTIONS]
145
- ```
146
-
147
- **Options**:
148
-
149
- - `--host TEXT`: Canvas instance to connect to
150
- - `--api-key TEXT`: Canvas api-key for the provided host
151
- - `--help`: Show this message and exit.
152
-
153
- ## `canvas plugin`
154
-
155
- Manage plugins in a Canvas instance
156
-
157
- **Usage**:
158
-
159
- ```console
160
- $ canvas plugin [OPTIONS] COMMAND [ARGS]...
161
- ```
162
-
163
- **Options**:
164
-
165
- - `--help`: Show this message and exit.
166
-
167
- **Commands**:
168
-
169
- - `delete`: Delete a disabled plugin from an instance
170
- - `init`: Create a plugin from a template using Cookiecutter
171
- - `install`: Installs a given Python package into a running Canvas instance
172
- - `list`: Lists all plugins from the instance
173
- - `update`: Updates a plugin from an instance
174
-
175
- ### `canvas plugin delete`
176
-
177
- Delete a disabled plugin from an instance.
178
-
179
- **Usage**:
180
-
181
- ```console
182
- $ canvas plugin delete [OPTIONS] NAME
183
- ```
184
-
185
- **Arguments**:
186
-
187
- - `NAME`: Plugin name to delete [required]
188
-
189
- **Options**:
190
-
191
- - `--host TEXT`: Canvas instance to connect to
192
- - `--api-key TEXT`: Canvas api-key for the provided host
193
- - `--help`: Show this message and exit.
194
-
195
- ### `canvas plugin init`
196
-
197
- Create a plugin from a template using Cookiecutter.
198
-
199
- **Usage**:
200
-
201
- ```console
202
- $ canvas plugin init [OPTIONS] [TEMPLATE]
203
- ```
204
-
205
- **Arguments**:
206
-
207
- - `[TEMPLATE]`: [default: (dynamic)]
208
-
209
- **Options**:
210
-
211
- - `--no-input`: Don't prompt the user at command line
212
- - `--help`: Show this message and exit.
213
-
214
- ### `canvas plugin install`
215
-
216
- Installs a given Python package into a running Canvas instance.
217
-
218
- **Usage**:
219
-
220
- ```console
221
- $ canvas plugin install [OPTIONS] PACKAGE
222
- ```
223
-
224
- **Arguments**:
225
-
226
- - `PACKAGE`: Path to either a dir or wheel or sdist file containing the python package to install [required]
227
-
228
- **Options**:
229
-
230
- - `--host TEXT`: Canvas instance to connect to
231
- - `--api-key TEXT`: Canvas api-key for the provided host
232
- - `--help`: Show this message and exit.
233
-
234
- ### `canvas plugin list`
235
-
236
- Lists all plugins from the instance.
237
-
238
- **Usage**:
239
-
240
- ```console
241
- $ canvas plugin list [OPTIONS]
242
- ```
243
-
244
- **Options**:
245
-
246
- - `--host TEXT`: Canvas instance to connect to
247
- - `--api-key TEXT`: Canvas api-key for the provided host
248
- - `--help`: Show this message and exit.
249
-
250
- ### `canvas plugin update`
251
-
252
- Updates a plugin from an instance.
253
-
254
- **Usage**:
255
-
256
- ```console
257
- $ canvas plugin update [OPTIONS] NAME
258
- ```
259
-
260
- **Arguments**:
261
-
262
- - `NAME`: Plugin name to update [required]
263
-
264
- **Options**:
265
-
266
- - `--package PATH`: Path to a wheel or sdist file containing the python package to install
267
- - `--enable / --disable`: Enable/disable the plugin
268
- - `--host TEXT`: Canvas instance to connect to
269
- - `--api-key TEXT`: Canvas api-key for the provided host
270
- - `--help`: Show this message and exit.
271
-
272
- ## `canvas print-config`
273
-
274
- Simple command to print the config and exit.
275
-
276
- **Usage**:
277
-
278
- ```console
279
- $ canvas print-config [OPTIONS]
280
- ```
281
-
282
- **Options**:
283
-
284
- - `--help`: Show this message and exit.
285
-
@@ -1,6 +0,0 @@
1
- canvas/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- canvas/main.py,sha256=UPjM6iDT_aI30Ur0LHIt3tTiHlalVRn6OEquJhoZVc0,635
3
- canvas-0.1.4.dist-info/METADATA,sha256=6Jkv5-BiulGddkusL68Gu_Q3xrZVWLvdPJt3q17GzaY,5801
4
- canvas-0.1.4.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
5
- canvas-0.1.4.dist-info/entry_points.txt,sha256=hsTDoLuwUTBak71S0KIxgSq-SVzf89Gh56UpbNwz5V8,42
6
- canvas-0.1.4.dist-info/RECORD,,
@@ -1,3 +0,0 @@
1
- [console_scripts]
2
- canvas=canvas.main:app
3
-
File without changes