revisit 0.0.19__tar.gz → 0.0.21__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {revisit-0.0.19 → revisit-0.0.21}/PKG-INFO +7 -6
- {revisit-0.0.19 → revisit-0.0.21}/pyproject.toml +6 -3
- revisit-0.0.21/setup.cfg +4 -0
- {revisit-0.0.19 → revisit-0.0.21}/src/revisit/revisit.py +1 -1
- revisit-0.0.21/src/revisit.egg-info/PKG-INFO +289 -0
- revisit-0.0.21/src/revisit.egg-info/SOURCES.txt +12 -0
- revisit-0.0.21/src/revisit.egg-info/dependency_links.txt +1 -0
- revisit-0.0.21/src/revisit.egg-info/requires.txt +7 -0
- revisit-0.0.21/src/revisit.egg-info/top_level.txt +1 -0
- revisit-0.0.21/tests/test_module_one.py +53 -0
- revisit-0.0.19/.gitignore +0 -10
- revisit-0.0.19/src/revisit/StudyConfigSchema.json +0 -2130
- revisit-0.0.19/src/revisit/static/widget.css +0 -2
- revisit-0.0.19/src/revisit/static/widget.js +0 -56
- {revisit-0.0.19 → revisit-0.0.21}/README.md +0 -0
- {revisit-0.0.19 → revisit-0.0.21}/src/revisit/__init__.py +0 -0
- {revisit-0.0.19 → revisit-0.0.21}/src/revisit/models.py +0 -0
- {revisit-0.0.19 → revisit-0.0.21}/src/revisit/widget.py +0 -0
@@ -1,12 +1,13 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.2
|
2
2
|
Name: revisit
|
3
|
-
Version: 0.0.
|
3
|
+
Version: 0.0.21
|
4
|
+
Description-Content-Type: text/markdown
|
4
5
|
Requires-Dist: anywidget
|
5
6
|
Requires-Dist: pydantic>=2.10.5
|
7
|
+
Requires-Dist: ipykernel>=6.29.5
|
6
8
|
Provides-Extra: dev
|
7
|
-
Requires-Dist:
|
8
|
-
Requires-Dist:
|
9
|
-
Description-Content-Type: text/markdown
|
9
|
+
Requires-Dist: watchfiles; extra == "dev"
|
10
|
+
Requires-Dist: jupyterlab; extra == "dev"
|
10
11
|
|
11
12
|
# revisit
|
12
13
|
|
@@ -285,4 +286,4 @@ datamodel-codegen --input src/revisit/StudyConfigSchema.json --output src/revisi
|
|
285
286
|
```bash
|
286
287
|
cd revisit-py
|
287
288
|
python -m unittest tests.test_module_one
|
288
|
-
```
|
289
|
+
```
|
@@ -1,13 +1,14 @@
|
|
1
1
|
[build-system]
|
2
|
-
requires = ["
|
3
|
-
build-backend = "
|
2
|
+
requires = ["setuptools", "wheel"] # Use setuptools for builds
|
3
|
+
build-backend = "setuptools.build_meta"
|
4
4
|
|
5
5
|
[project]
|
6
6
|
name = "revisit"
|
7
|
-
version = "0.0.
|
7
|
+
version = "0.0.21"
|
8
8
|
dependencies = [
|
9
9
|
"anywidget",
|
10
10
|
"pydantic>=2.10.5",
|
11
|
+
"ipykernel>=6.29.5",
|
11
12
|
]
|
12
13
|
readme = "README.md"
|
13
14
|
|
@@ -26,6 +27,8 @@ dev = ["watchfiles", "jupyterlab"]
|
|
26
27
|
[tool.hatch.build]
|
27
28
|
only-packages = true
|
28
29
|
artifacts = ["src/revisit/static/*"]
|
30
|
+
exclude = ["tests", "js"]
|
31
|
+
|
29
32
|
|
30
33
|
[tool.hatch.build.hooks.jupyter-builder]
|
31
34
|
build-function = "hatch_jupyter_builder.npm_builder"
|
revisit-0.0.21/setup.cfg
ADDED
@@ -176,7 +176,7 @@ class _WrappedComponentBlock(_JSONableBaseModel):
|
|
176
176
|
self = self + __component__(type='questionnaire', component_name__='place-holder-component')
|
177
177
|
# If there only exists one component (either existing one or placeholder),
|
178
178
|
# do not create the first component blocks.
|
179
|
-
if len(self.component_objects__)
|
179
|
+
if len(self.component_objects__) == 1:
|
180
180
|
make_comp_block = False
|
181
181
|
|
182
182
|
# Convert to JSON
|
@@ -0,0 +1,289 @@
|
|
1
|
+
Metadata-Version: 2.2
|
2
|
+
Name: revisit
|
3
|
+
Version: 0.0.21
|
4
|
+
Description-Content-Type: text/markdown
|
5
|
+
Requires-Dist: anywidget
|
6
|
+
Requires-Dist: pydantic>=2.10.5
|
7
|
+
Requires-Dist: ipykernel>=6.29.5
|
8
|
+
Provides-Extra: dev
|
9
|
+
Requires-Dist: watchfiles; extra == "dev"
|
10
|
+
Requires-Dist: jupyterlab; extra == "dev"
|
11
|
+
|
12
|
+
# revisit
|
13
|
+
|
14
|
+
## Installation
|
15
|
+
|
16
|
+
```sh
|
17
|
+
pip install revisit
|
18
|
+
```
|
19
|
+
|
20
|
+
or with [uv](https://github.com/astral-sh/uv):
|
21
|
+
|
22
|
+
```sh
|
23
|
+
uv add revisit
|
24
|
+
```
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
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.
|
29
|
+
|
30
|
+
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.
|
31
|
+
|
32
|
+
### Functions
|
33
|
+
|
34
|
+
#### `component(component_name__: str, base__: Optional[component], **kwargs: dict) -> Component`
|
35
|
+
|
36
|
+
**Description**:
|
37
|
+
|
38
|
+
Instantiates a Component class with the given input parameters.
|
39
|
+
|
40
|
+
#### **Parameters**:
|
41
|
+
| Parameter | Type | Description | Default Value |
|
42
|
+
|-----------|--------|---------------------------------|---------------|
|
43
|
+
| `component_name__` | `str` | Names the component for use in the final configuration file. | _None_ |
|
44
|
+
| `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_ |
|
45
|
+
| `**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_ |
|
46
|
+
|
47
|
+
#### **Returns**:
|
48
|
+
- `Component`: Returns an instantiation of the Component class.
|
49
|
+
|
50
|
+
#### **Raises**:
|
51
|
+
- `RevisitError`: If the required properties are not specified, and exception will be raised.
|
52
|
+
|
53
|
+
#### **Example**:
|
54
|
+
```python
|
55
|
+
import revisit as rvt
|
56
|
+
|
57
|
+
# Initializing a markdown component with an empty response list.
|
58
|
+
my_component = rvt.component(
|
59
|
+
component_name__='my-component',
|
60
|
+
response=[],
|
61
|
+
type='markdown',
|
62
|
+
path='./assets/my-markdown-file.md'
|
63
|
+
)
|
64
|
+
|
65
|
+
# Instantiating a component with the base as "my_component".
|
66
|
+
my_other_component = rvt.component(
|
67
|
+
component_name__='my-other-component',
|
68
|
+
base__=my_component,
|
69
|
+
path='./assets/my-other-markdown-file.md'
|
70
|
+
)
|
71
|
+
```
|
72
|
+
|
73
|
+
|
74
|
+
#### `response(**kwargs: dict) -> Response`
|
75
|
+
|
76
|
+
**Description**:
|
77
|
+
|
78
|
+
Instantiates a Response class with the given input parameters.
|
79
|
+
|
80
|
+
#### **Parameters**:
|
81
|
+
| Parameter | Type | Description | Default Value |
|
82
|
+
|-----------|--------|---------------------------------|---------------|
|
83
|
+
| `**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_ |
|
84
|
+
|
85
|
+
#### **Returns**:
|
86
|
+
- `Response`: Returns an instantiation of the Response class.
|
87
|
+
|
88
|
+
#### **Raises**:
|
89
|
+
- `RevisitError`: If the required properties are not specified, and exception will be raised.
|
90
|
+
|
91
|
+
#### **Example**:
|
92
|
+
```python
|
93
|
+
import revisit as rvt
|
94
|
+
|
95
|
+
# Initializing a matrix radio response
|
96
|
+
my_response = rvt.response(
|
97
|
+
type='matrix-radio',
|
98
|
+
answerOptions='likely5',
|
99
|
+
questionOptions=['Question 1', 'Question 2', 'Question 3'],
|
100
|
+
required=True,
|
101
|
+
location='sidebar'
|
102
|
+
)
|
103
|
+
```
|
104
|
+
|
105
|
+
### Classes
|
106
|
+
|
107
|
+
#### `Component`
|
108
|
+
|
109
|
+
**Description**:
|
110
|
+
A brief summary of the class's purpose and functionality.
|
111
|
+
|
112
|
+
#### **Attributes**:
|
113
|
+
| Attribute | Type | Description | Default Value |
|
114
|
+
|-------------|----------|-------------------------------------|---------------|
|
115
|
+
| `component_name__` | `type` | Description of attribute 1. | `default` |
|
116
|
+
| `base__` | `type` | Description of attribute 2. | _None_ |
|
117
|
+
|
118
|
+
|
119
|
+
#### **Methods**:
|
120
|
+
##### `responses(responses: List[Response]) -> self`
|
121
|
+
|
122
|
+
**Description**:
|
123
|
+
Sets responses for the component
|
124
|
+
|
125
|
+
**Parameters**:
|
126
|
+
| Parameter | Type | Description | Default Value |
|
127
|
+
|-------------|----------|-------------------------------------|---------------|
|
128
|
+
| `responses` | `List[Response]` | Valid list of responses. | _None_ |
|
129
|
+
|
130
|
+
**Returns**:
|
131
|
+
- `self`: Returns self for method chaining.
|
132
|
+
|
133
|
+
**Raises**:
|
134
|
+
- `RevisitError`: If the list is not a valid list of responses, raises and exception.
|
135
|
+
|
136
|
+
#### **Example**:
|
137
|
+
```python
|
138
|
+
my_response=rvt.response(
|
139
|
+
id='my_response',
|
140
|
+
type='dropdown',
|
141
|
+
options=['Option 1', 'Option 2']
|
142
|
+
)
|
143
|
+
|
144
|
+
my_component = rvt.component(
|
145
|
+
component_name__='my_component',
|
146
|
+
type='markdown',
|
147
|
+
path='assets/my-markdown-file.md'
|
148
|
+
).responses([
|
149
|
+
my_response
|
150
|
+
])
|
151
|
+
```
|
152
|
+
|
153
|
+
#### `get_response(id: str) -> Response | None`
|
154
|
+
|
155
|
+
**Description**:
|
156
|
+
Returns the response of the component with the given ID. If the Response does not exist, returns `None`.
|
157
|
+
|
158
|
+
**Parameters**:
|
159
|
+
| Parameter | Type | Description | Default Value |
|
160
|
+
|-------------|----------|-------------------------------------|---------------|
|
161
|
+
| `id` | `str` | ID of Response | _None_ |
|
162
|
+
|
163
|
+
**Returns**:
|
164
|
+
- `Response`: The response with the given ID.
|
165
|
+
|
166
|
+
#### **Examples**:
|
167
|
+
```python
|
168
|
+
the_response = my_component.get_response(id='the_response')
|
169
|
+
|
170
|
+
if the_response is not None:
|
171
|
+
print(the_response)
|
172
|
+
```
|
173
|
+
|
174
|
+
#### `edit_response(id: str, **kwargs: dict) -> self`
|
175
|
+
|
176
|
+
**Description**:
|
177
|
+
Edits the Response in the Component with the given ID. This is done by creating a new copy of the existing Response.
|
178
|
+
|
179
|
+
**Parameters**:
|
180
|
+
| Parameter | Type | Description | Default Value |
|
181
|
+
|-------------|----------|-------------------------------------|---------------|
|
182
|
+
| `id` | `str` | ID of Response | _None_ |
|
183
|
+
|
184
|
+
**Returns**:
|
185
|
+
- `self`: Returns self for method chaining.
|
186
|
+
|
187
|
+
#### **Examples**:
|
188
|
+
```python
|
189
|
+
test_response = rvt.response(
|
190
|
+
id='test_response',
|
191
|
+
type='shortText',
|
192
|
+
prompt='Original Prompt:',
|
193
|
+
required=True
|
194
|
+
)
|
195
|
+
|
196
|
+
component_one = rvt.component(
|
197
|
+
component_name__='component_one',
|
198
|
+
type='questionnaire',
|
199
|
+
response=[test_response]
|
200
|
+
)
|
201
|
+
|
202
|
+
component_two = rvt.component(
|
203
|
+
component_name__='component_two',
|
204
|
+
type='questionnaire',
|
205
|
+
response=[test_response]
|
206
|
+
).edit_response(id='test_response', prompt='New Prompt', required=False)
|
207
|
+
|
208
|
+
print(component_one)
|
209
|
+
'''
|
210
|
+
Expected Output:
|
211
|
+
{
|
212
|
+
"response": [
|
213
|
+
{
|
214
|
+
"id": "test_response",
|
215
|
+
"prompt": "Original Prompt:",
|
216
|
+
"required": true,
|
217
|
+
"type": "shortText"
|
218
|
+
}
|
219
|
+
],
|
220
|
+
"type": "questionnaire"
|
221
|
+
}
|
222
|
+
'''
|
223
|
+
print(component_two)
|
224
|
+
'''
|
225
|
+
{
|
226
|
+
"response": [
|
227
|
+
{
|
228
|
+
"id": "test_response",
|
229
|
+
"prompt": "New Prompt",
|
230
|
+
"required": false,
|
231
|
+
"type": "shortText"
|
232
|
+
}
|
233
|
+
],
|
234
|
+
"type": "questionnaire"
|
235
|
+
}
|
236
|
+
'''
|
237
|
+
```
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
## Development
|
242
|
+
|
243
|
+
We recommend using [uv](https://github.com/astral-sh/uv) for development.
|
244
|
+
It will automatically manage virtual environments and dependencies for you.
|
245
|
+
|
246
|
+
```sh
|
247
|
+
uv run jupyter lab example.ipynb
|
248
|
+
```
|
249
|
+
|
250
|
+
Alternatively, create and manage your own virtual environment:
|
251
|
+
|
252
|
+
```sh
|
253
|
+
python -m venv .venv
|
254
|
+
source .venv/bin/activate
|
255
|
+
pip install -e ".[dev]"
|
256
|
+
jupyter lab example.ipynb
|
257
|
+
```
|
258
|
+
|
259
|
+
The widget front-end code bundles it's JavaScript dependencies. After setting up Python,
|
260
|
+
make sure to install these dependencies locally:
|
261
|
+
|
262
|
+
```sh
|
263
|
+
yarn install
|
264
|
+
```
|
265
|
+
|
266
|
+
While developing, you can run the following in a separate terminal to automatically
|
267
|
+
rebuild JavaScript as you make changes:
|
268
|
+
|
269
|
+
```sh
|
270
|
+
yarn run dev
|
271
|
+
```
|
272
|
+
|
273
|
+
Open `example.ipynb` in JupyterLab, VS Code, or your favorite editor
|
274
|
+
to start developing. Changes made in `js/` will be reflected
|
275
|
+
in the notebook.
|
276
|
+
|
277
|
+
|
278
|
+
## CODE GEN
|
279
|
+
|
280
|
+
```bash
|
281
|
+
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
|
282
|
+
```
|
283
|
+
|
284
|
+
## TESTS
|
285
|
+
|
286
|
+
```bash
|
287
|
+
cd revisit-py
|
288
|
+
python -m unittest tests.test_module_one
|
289
|
+
```
|
@@ -0,0 +1,12 @@
|
|
1
|
+
README.md
|
2
|
+
pyproject.toml
|
3
|
+
src/revisit/__init__.py
|
4
|
+
src/revisit/models.py
|
5
|
+
src/revisit/revisit.py
|
6
|
+
src/revisit/widget.py
|
7
|
+
src/revisit.egg-info/PKG-INFO
|
8
|
+
src/revisit.egg-info/SOURCES.txt
|
9
|
+
src/revisit.egg-info/dependency_links.txt
|
10
|
+
src/revisit.egg-info/requires.txt
|
11
|
+
src/revisit.egg-info/top_level.txt
|
12
|
+
tests/test_module_one.py
|
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
revisit
|
@@ -0,0 +1,53 @@
|
|
1
|
+
import src.revisit.revisit as rvt
|
2
|
+
import unittest
|
3
|
+
import json
|
4
|
+
|
5
|
+
|
6
|
+
class TestComponentsAndResponses(unittest.TestCase):
|
7
|
+
def test_markdown_component(self):
|
8
|
+
comp_one = rvt.component(
|
9
|
+
type='markdown',
|
10
|
+
path='./assets/test-path',
|
11
|
+
response=[],
|
12
|
+
component_name__='Base_Test'
|
13
|
+
)
|
14
|
+
|
15
|
+
self.assertEqual(
|
16
|
+
json.loads(comp_one.__str__()),
|
17
|
+
{
|
18
|
+
'path': './assets/test-path',
|
19
|
+
'response': [],
|
20
|
+
'type': 'markdown'
|
21
|
+
}
|
22
|
+
)
|
23
|
+
|
24
|
+
def test_response_getter(self):
|
25
|
+
comp_two = rvt.component(
|
26
|
+
type='questionnaire',
|
27
|
+
response=[],
|
28
|
+
component_name__='Base_Test'
|
29
|
+
).responses([
|
30
|
+
rvt.response(
|
31
|
+
id='first-response',
|
32
|
+
type='matrix-checkbox',
|
33
|
+
answerOptions='likely-7',
|
34
|
+
required=True,
|
35
|
+
prompt='Fake Prompt',
|
36
|
+
questionOptions=[
|
37
|
+
'Question One',
|
38
|
+
'Question Two',
|
39
|
+
'Question Three'
|
40
|
+
]
|
41
|
+
)
|
42
|
+
])
|
43
|
+
|
44
|
+
response_one = comp_two.get_response(id='first-response')
|
45
|
+
|
46
|
+
self.assertEqual(
|
47
|
+
json.loads(response_one.__str__()),
|
48
|
+
{'answerOptions': 'likely-7', 'id': 'first-response', 'prompt': 'Fake Prompt', 'questionOptions': ['Question One', 'Question Two', 'Question Three'], 'required': True, 'type': 'matrix-checkbox'}
|
49
|
+
)
|
50
|
+
|
51
|
+
|
52
|
+
if __name__ == "__main__":
|
53
|
+
unittest.main()
|