revisit 0.0.11__tar.gz → 0.0.13__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,291 @@
1
+ Metadata-Version: 2.4
2
+ Name: revisit
3
+ Version: 0.0.13
4
+ Requires-Dist: altair[all]>=5.5.0
5
+ Requires-Dist: anywidget
6
+ Requires-Dist: ipykernel>=6.29.5
7
+ Requires-Dist: pandas>=2.2.3
8
+ Requires-Dist: pydantic>=2.10.5
9
+ Provides-Extra: dev
10
+ Requires-Dist: jupyterlab; extra == 'dev'
11
+ Requires-Dist: watchfiles; extra == 'dev'
12
+ Description-Content-Type: text/markdown
13
+
14
+ # revisit
15
+
16
+ ## Installation
17
+
18
+ ```sh
19
+ pip install revisit
20
+ ```
21
+
22
+ or with [uv](https://github.com/astral-sh/uv):
23
+
24
+ ```sh
25
+ uv add revisit
26
+ ```
27
+
28
+ ## Usage
29
+
30
+ The reVISit python package wraps the standard items of the reVISit configuration file with readable, easy-to-use functions. We expose a factory function for each top-level item in the reVISit configuration: `studyMetadata`, `uiConfig`, `components`, `sequence`, and `studyMetadata`. Currently, we do not expose a `baseComponents` function. Instead, base components are still well-defined components and can be passed during the creation of another component. The final configuration will not include base components but will have the expected inherited output.
31
+
32
+ Each factory function takes in the same parameters as the reVISit configuration file. For example, the `studyMetadata` function requires the author, organizations, title, version, and description parameters. Robust error output will help you, the user, understand what is required in each function. For the sake of brevity, we do not list every possible parameter since these are already defined in the current study configuration. Instead, we will show additional required/optional parameters as well as additional methods and other exposed functions.
33
+
34
+ ### Functions
35
+
36
+ #### `component(component_name__: str, base__: Optional[component], **kwargs: dict) -> Component`
37
+
38
+ **Description**:
39
+
40
+ Instantiates a Component class with the given input parameters.
41
+
42
+ #### **Parameters**:
43
+ | Parameter | Type | Description | Default Value |
44
+ |-----------|--------|---------------------------------|---------------|
45
+ | `component_name__` | `str` | Names the component for use in the final configuration file. | _None_ |
46
+ | `base__` | `Optional[component]` | When a base component is passed, all properties of the base are inherited by the component. Any other specified property during input will override base properties. | _None_ |
47
+ | `**kwargs` | `dict` | The component function requires any property that the component already requires, such as "type". Refer to the configuration documentation for required properties. | _None_ |
48
+
49
+ #### **Returns**:
50
+ - `Component`: Returns an instantiation of the Component class.
51
+
52
+ #### **Raises**:
53
+ - `RevisitError`: If the required properties are not specified, and exception will be raised.
54
+
55
+ #### **Example**:
56
+ ```python
57
+ import revisit as rvt
58
+
59
+ # Initializing a markdown component with an empty response list.
60
+ my_component = rvt.component(
61
+ component_name__='my-component',
62
+ response=[],
63
+ type='markdown',
64
+ path='./assets/my-markdown-file.md'
65
+ )
66
+
67
+ # Instantiating a component with the base as "my_component".
68
+ my_other_component = rvt.component(
69
+ component_name__='my-other-component',
70
+ base__=my_component,
71
+ path='./assets/my-other-markdown-file.md'
72
+ )
73
+ ```
74
+
75
+
76
+ #### `response(**kwargs: dict) -> Response`
77
+
78
+ **Description**:
79
+
80
+ Instantiates a Response class with the given input parameters.
81
+
82
+ #### **Parameters**:
83
+ | Parameter | Type | Description | Default Value |
84
+ |-----------|--------|---------------------------------|---------------|
85
+ | `**kwargs` | `dict` | The component function requires any property that the component already requires, such as "type". Refer to the configuration documentation for required properties. | _None_ |
86
+
87
+ #### **Returns**:
88
+ - `Response`: Returns an instantiation of the Response class.
89
+
90
+ #### **Raises**:
91
+ - `RevisitError`: If the required properties are not specified, and exception will be raised.
92
+
93
+ #### **Example**:
94
+ ```python
95
+ import revisit as rvt
96
+
97
+ # Initializing a matrix radio response
98
+ my_response = rvt.response(
99
+ type='matrix-radio',
100
+ answerOptions='likely5',
101
+ questionOptions=['Question 1', 'Question 2', 'Question 3'],
102
+ required=True,
103
+ location='sidebar'
104
+ )
105
+ ```
106
+
107
+ ### Classes
108
+
109
+ #### `Component`
110
+
111
+ **Description**:
112
+ A brief summary of the class's purpose and functionality.
113
+
114
+ #### **Attributes**:
115
+ | Attribute | Type | Description | Default Value |
116
+ |-------------|----------|-------------------------------------|---------------|
117
+ | `component_name__` | `type` | Description of attribute 1. | `default` |
118
+ | `base__` | `type` | Description of attribute 2. | _None_ |
119
+
120
+
121
+ #### **Methods**:
122
+ ##### `responses(responses: List[Response]) -> self`
123
+
124
+ **Description**:
125
+ Sets responses for the component
126
+
127
+ **Parameters**:
128
+ | Parameter | Type | Description | Default Value |
129
+ |-------------|----------|-------------------------------------|---------------|
130
+ | `responses` | `List[Response]` | Valid list of responses. | _None_ |
131
+
132
+ **Returns**:
133
+ - `self`: Returns self for method chaining.
134
+
135
+ **Raises**:
136
+ - `RevisitError`: If the list is not a valid list of responses, raises and exception.
137
+
138
+ #### **Example**:
139
+ ```python
140
+ my_response=rvt.response(
141
+ id='my_response',
142
+ type='dropdown',
143
+ options=['Option 1', 'Option 2']
144
+ )
145
+
146
+ my_component = rvt.component(
147
+ component_name__='my_component',
148
+ type='markdown',
149
+ path='assets/my-markdown-file.md'
150
+ ).responses([
151
+ my_response
152
+ ])
153
+ ```
154
+
155
+ #### `get_response(id: str) -> Response | None`
156
+
157
+ **Description**:
158
+ Returns the response of the component with the given ID. If the Response does not exist, returns `None`.
159
+
160
+ **Parameters**:
161
+ | Parameter | Type | Description | Default Value |
162
+ |-------------|----------|-------------------------------------|---------------|
163
+ | `id` | `str` | ID of Response | _None_ |
164
+
165
+ **Returns**:
166
+ - `Response`: The response with the given ID.
167
+
168
+ #### **Examples**:
169
+ ```python
170
+ the_response = my_component.get_response(id='the_response')
171
+
172
+ if the_response is not None:
173
+ print(the_response)
174
+ ```
175
+
176
+ #### `edit_response(id: str, **kwargs: dict) -> self`
177
+
178
+ **Description**:
179
+ Edits the Response in the Component with the given ID. This is done by creating a new copy of the existing Response.
180
+
181
+ **Parameters**:
182
+ | Parameter | Type | Description | Default Value |
183
+ |-------------|----------|-------------------------------------|---------------|
184
+ | `id` | `str` | ID of Response | _None_ |
185
+
186
+ **Returns**:
187
+ - `self`: Returns self for method chaining.
188
+
189
+ #### **Examples**:
190
+ ```python
191
+ test_response = rvt.response(
192
+ id='test_response',
193
+ type='shortText',
194
+ prompt='Original Prompt:',
195
+ required=True
196
+ )
197
+
198
+ component_one = rvt.component(
199
+ component_name__='component_one',
200
+ type='questionnaire',
201
+ response=[test_response]
202
+ )
203
+
204
+ component_two = rvt.component(
205
+ component_name__='component_two',
206
+ type='questionnaire',
207
+ response=[test_response]
208
+ ).edit_response(id='test_response', prompt='New Prompt', required=False)
209
+
210
+ print(component_one)
211
+ '''
212
+ Expected Output:
213
+ {
214
+ "response": [
215
+ {
216
+ "id": "test_response",
217
+ "prompt": "Original Prompt:",
218
+ "required": true,
219
+ "type": "shortText"
220
+ }
221
+ ],
222
+ "type": "questionnaire"
223
+ }
224
+ '''
225
+ print(component_two)
226
+ '''
227
+ {
228
+ "response": [
229
+ {
230
+ "id": "test_response",
231
+ "prompt": "New Prompt",
232
+ "required": false,
233
+ "type": "shortText"
234
+ }
235
+ ],
236
+ "type": "questionnaire"
237
+ }
238
+ '''
239
+ ```
240
+
241
+
242
+
243
+ ## Development
244
+
245
+ We recommend using [uv](https://github.com/astral-sh/uv) for development.
246
+ It will automatically manage virtual environments and dependencies for you.
247
+
248
+ ```sh
249
+ uv run jupyter lab example.ipynb
250
+ ```
251
+
252
+ Alternatively, create and manage your own virtual environment:
253
+
254
+ ```sh
255
+ python -m venv .venv
256
+ source .venv/bin/activate
257
+ pip install -e ".[dev]"
258
+ jupyter lab example.ipynb
259
+ ```
260
+
261
+ The widget front-end code bundles it's JavaScript dependencies. After setting up Python,
262
+ make sure to install these dependencies locally:
263
+
264
+ ```sh
265
+ yarn install
266
+ ```
267
+
268
+ While developing, you can run the following in a separate terminal to automatically
269
+ rebuild JavaScript as you make changes:
270
+
271
+ ```sh
272
+ yarn run dev
273
+ ```
274
+
275
+ Open `example.ipynb` in JupyterLab, VS Code, or your favorite editor
276
+ to start developing. Changes made in `js/` will be reflected
277
+ in the notebook.
278
+
279
+
280
+ ## CODE GEN
281
+
282
+ ```bash
283
+ datamodel-codegen --input src/revisit/StudyConfigSchema.json --output src/revisit/models.py --custom-template-dir custom_templates --output-model-type pydantic_v2.BaseModel --additional-imports "typing.TypedDict, warnings" --input-file-type jsonschema --special-field-name-prefix we_are_going_to_replace_this && sed -i '' 's/we_are_going_to_replace_this_//g' src/revisit/models.py
284
+ ```
285
+
286
+ ## TESTS
287
+
288
+ ```bash
289
+ cd revisit-py
290
+ python -m unittest tests.test_module_one
291
+ ```
@@ -0,0 +1,278 @@
1
+ # revisit
2
+
3
+ ## Installation
4
+
5
+ ```sh
6
+ pip install revisit
7
+ ```
8
+
9
+ or with [uv](https://github.com/astral-sh/uv):
10
+
11
+ ```sh
12
+ uv add revisit
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ The reVISit python package wraps the standard items of the reVISit configuration file with readable, easy-to-use functions. We expose a factory function for each top-level item in the reVISit configuration: `studyMetadata`, `uiConfig`, `components`, `sequence`, and `studyMetadata`. Currently, we do not expose a `baseComponents` function. Instead, base components are still well-defined components and can be passed during the creation of another component. The final configuration will not include base components but will have the expected inherited output.
18
+
19
+ Each factory function takes in the same parameters as the reVISit configuration file. For example, the `studyMetadata` function requires the author, organizations, title, version, and description parameters. Robust error output will help you, the user, understand what is required in each function. For the sake of brevity, we do not list every possible parameter since these are already defined in the current study configuration. Instead, we will show additional required/optional parameters as well as additional methods and other exposed functions.
20
+
21
+ ### Functions
22
+
23
+ #### `component(component_name__: str, base__: Optional[component], **kwargs: dict) -> Component`
24
+
25
+ **Description**:
26
+
27
+ Instantiates a Component class with the given input parameters.
28
+
29
+ #### **Parameters**:
30
+ | Parameter | Type | Description | Default Value |
31
+ |-----------|--------|---------------------------------|---------------|
32
+ | `component_name__` | `str` | Names the component for use in the final configuration file. | _None_ |
33
+ | `base__` | `Optional[component]` | When a base component is passed, all properties of the base are inherited by the component. Any other specified property during input will override base properties. | _None_ |
34
+ | `**kwargs` | `dict` | The component function requires any property that the component already requires, such as "type". Refer to the configuration documentation for required properties. | _None_ |
35
+
36
+ #### **Returns**:
37
+ - `Component`: Returns an instantiation of the Component class.
38
+
39
+ #### **Raises**:
40
+ - `RevisitError`: If the required properties are not specified, and exception will be raised.
41
+
42
+ #### **Example**:
43
+ ```python
44
+ import revisit as rvt
45
+
46
+ # Initializing a markdown component with an empty response list.
47
+ my_component = rvt.component(
48
+ component_name__='my-component',
49
+ response=[],
50
+ type='markdown',
51
+ path='./assets/my-markdown-file.md'
52
+ )
53
+
54
+ # Instantiating a component with the base as "my_component".
55
+ my_other_component = rvt.component(
56
+ component_name__='my-other-component',
57
+ base__=my_component,
58
+ path='./assets/my-other-markdown-file.md'
59
+ )
60
+ ```
61
+
62
+
63
+ #### `response(**kwargs: dict) -> Response`
64
+
65
+ **Description**:
66
+
67
+ Instantiates a Response class with the given input parameters.
68
+
69
+ #### **Parameters**:
70
+ | Parameter | Type | Description | Default Value |
71
+ |-----------|--------|---------------------------------|---------------|
72
+ | `**kwargs` | `dict` | The component function requires any property that the component already requires, such as "type". Refer to the configuration documentation for required properties. | _None_ |
73
+
74
+ #### **Returns**:
75
+ - `Response`: Returns an instantiation of the Response class.
76
+
77
+ #### **Raises**:
78
+ - `RevisitError`: If the required properties are not specified, and exception will be raised.
79
+
80
+ #### **Example**:
81
+ ```python
82
+ import revisit as rvt
83
+
84
+ # Initializing a matrix radio response
85
+ my_response = rvt.response(
86
+ type='matrix-radio',
87
+ answerOptions='likely5',
88
+ questionOptions=['Question 1', 'Question 2', 'Question 3'],
89
+ required=True,
90
+ location='sidebar'
91
+ )
92
+ ```
93
+
94
+ ### Classes
95
+
96
+ #### `Component`
97
+
98
+ **Description**:
99
+ A brief summary of the class's purpose and functionality.
100
+
101
+ #### **Attributes**:
102
+ | Attribute | Type | Description | Default Value |
103
+ |-------------|----------|-------------------------------------|---------------|
104
+ | `component_name__` | `type` | Description of attribute 1. | `default` |
105
+ | `base__` | `type` | Description of attribute 2. | _None_ |
106
+
107
+
108
+ #### **Methods**:
109
+ ##### `responses(responses: List[Response]) -> self`
110
+
111
+ **Description**:
112
+ Sets responses for the component
113
+
114
+ **Parameters**:
115
+ | Parameter | Type | Description | Default Value |
116
+ |-------------|----------|-------------------------------------|---------------|
117
+ | `responses` | `List[Response]` | Valid list of responses. | _None_ |
118
+
119
+ **Returns**:
120
+ - `self`: Returns self for method chaining.
121
+
122
+ **Raises**:
123
+ - `RevisitError`: If the list is not a valid list of responses, raises and exception.
124
+
125
+ #### **Example**:
126
+ ```python
127
+ my_response=rvt.response(
128
+ id='my_response',
129
+ type='dropdown',
130
+ options=['Option 1', 'Option 2']
131
+ )
132
+
133
+ my_component = rvt.component(
134
+ component_name__='my_component',
135
+ type='markdown',
136
+ path='assets/my-markdown-file.md'
137
+ ).responses([
138
+ my_response
139
+ ])
140
+ ```
141
+
142
+ #### `get_response(id: str) -> Response | None`
143
+
144
+ **Description**:
145
+ Returns the response of the component with the given ID. If the Response does not exist, returns `None`.
146
+
147
+ **Parameters**:
148
+ | Parameter | Type | Description | Default Value |
149
+ |-------------|----------|-------------------------------------|---------------|
150
+ | `id` | `str` | ID of Response | _None_ |
151
+
152
+ **Returns**:
153
+ - `Response`: The response with the given ID.
154
+
155
+ #### **Examples**:
156
+ ```python
157
+ the_response = my_component.get_response(id='the_response')
158
+
159
+ if the_response is not None:
160
+ print(the_response)
161
+ ```
162
+
163
+ #### `edit_response(id: str, **kwargs: dict) -> self`
164
+
165
+ **Description**:
166
+ Edits the Response in the Component with the given ID. This is done by creating a new copy of the existing Response.
167
+
168
+ **Parameters**:
169
+ | Parameter | Type | Description | Default Value |
170
+ |-------------|----------|-------------------------------------|---------------|
171
+ | `id` | `str` | ID of Response | _None_ |
172
+
173
+ **Returns**:
174
+ - `self`: Returns self for method chaining.
175
+
176
+ #### **Examples**:
177
+ ```python
178
+ test_response = rvt.response(
179
+ id='test_response',
180
+ type='shortText',
181
+ prompt='Original Prompt:',
182
+ required=True
183
+ )
184
+
185
+ component_one = rvt.component(
186
+ component_name__='component_one',
187
+ type='questionnaire',
188
+ response=[test_response]
189
+ )
190
+
191
+ component_two = rvt.component(
192
+ component_name__='component_two',
193
+ type='questionnaire',
194
+ response=[test_response]
195
+ ).edit_response(id='test_response', prompt='New Prompt', required=False)
196
+
197
+ print(component_one)
198
+ '''
199
+ Expected Output:
200
+ {
201
+ "response": [
202
+ {
203
+ "id": "test_response",
204
+ "prompt": "Original Prompt:",
205
+ "required": true,
206
+ "type": "shortText"
207
+ }
208
+ ],
209
+ "type": "questionnaire"
210
+ }
211
+ '''
212
+ print(component_two)
213
+ '''
214
+ {
215
+ "response": [
216
+ {
217
+ "id": "test_response",
218
+ "prompt": "New Prompt",
219
+ "required": false,
220
+ "type": "shortText"
221
+ }
222
+ ],
223
+ "type": "questionnaire"
224
+ }
225
+ '''
226
+ ```
227
+
228
+
229
+
230
+ ## Development
231
+
232
+ We recommend using [uv](https://github.com/astral-sh/uv) for development.
233
+ It will automatically manage virtual environments and dependencies for you.
234
+
235
+ ```sh
236
+ uv run jupyter lab example.ipynb
237
+ ```
238
+
239
+ Alternatively, create and manage your own virtual environment:
240
+
241
+ ```sh
242
+ python -m venv .venv
243
+ source .venv/bin/activate
244
+ pip install -e ".[dev]"
245
+ jupyter lab example.ipynb
246
+ ```
247
+
248
+ The widget front-end code bundles it's JavaScript dependencies. After setting up Python,
249
+ make sure to install these dependencies locally:
250
+
251
+ ```sh
252
+ yarn install
253
+ ```
254
+
255
+ While developing, you can run the following in a separate terminal to automatically
256
+ rebuild JavaScript as you make changes:
257
+
258
+ ```sh
259
+ yarn run dev
260
+ ```
261
+
262
+ Open `example.ipynb` in JupyterLab, VS Code, or your favorite editor
263
+ to start developing. Changes made in `js/` will be reflected
264
+ in the notebook.
265
+
266
+
267
+ ## CODE GEN
268
+
269
+ ```bash
270
+ datamodel-codegen --input src/revisit/StudyConfigSchema.json --output src/revisit/models.py --custom-template-dir custom_templates --output-model-type pydantic_v2.BaseModel --additional-imports "typing.TypedDict, warnings" --input-file-type jsonschema --special-field-name-prefix we_are_going_to_replace_this && sed -i '' 's/we_are_going_to_replace_this_//g' src/revisit/models.py
271
+ ```
272
+
273
+ ## TESTS
274
+
275
+ ```bash
276
+ cd revisit-py
277
+ python -m unittest tests.test_module_one
278
+ ```
@@ -4,10 +4,12 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "revisit"
7
- version = "0.0.11"
7
+ version = "0.0.13"
8
8
  dependencies = [
9
+ "altair[all]>=5.5.0",
9
10
  "anywidget",
10
11
  "ipykernel>=6.29.5",
12
+ "pandas>=2.2.3",
11
13
  "pydantic>=2.10.5",
12
14
  ]
13
15
  readme = "README.md"