revisit 0.0.19__tar.gz → 0.0.20__tar.gz

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