Skip to content

Commit 38b5ebd

Browse files
Merge branch 'main' into use-name-full
2 parents 56557f6 + 8f5eca5 commit 38b5ebd

20 files changed

+688
-300
lines changed

.github/workflows/alkiln_tests.yml

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ on:
88
description: 'Optional. Use a "tag expression" specify which tagged tests to run. See https://cucumber.io/docs/cucumber/api/#tag-expressions for syntax.'
99
default: ''
1010
required: false
11+
show_docker_output:
12+
required: false
13+
default: false
14+
type: boolean
15+
description: 'Show the docker logs while building the GitHub server container. It will also save the docker log artifact. This might show sensitive config information.'
1116
# To run your tests on a schedule, delete the first "#" symbol at the beginning of each line below.
1217
## Also see https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#schedule
1318
## Also see https://crontab.guru/examples.html
@@ -20,12 +25,22 @@ jobs:
2025
name: Run end-to-end tests
2126
steps:
2227
- uses: actions/checkout@v3
23-
- name: Use ALKiln to run end-to-end tests
28+
- name: "ALKiln - Start the isolated temporary docassemble server on GitHub"
29+
id: github_server
30+
uses: suffolkLITLab/ALKiln/action_for_github_server@v5
31+
with:
32+
SHOW_DOCKER_OUTPUT: "${{ github.event.inputs.show_docker_output }}"
33+
- run: echo "ALKiln finished starting the isolated GitHub docassemble server"
34+
- name: Use ALKiln to run tests
2435
uses: SuffolkLITLab/ALKiln@v5
36+
env:
37+
ALKILN_TAG_EXPRESSION: "${{ (github.event.inputs.tags && format('{0}', github.event.inputs.tags)) }}"
2538
with:
26-
SERVER_URL: "${{ secrets.SERVER_URL }}"
27-
DOCASSEMBLE_DEVELOPER_API_KEY: "${{ secrets.DOCASSEMBLE_DEVELOPER_API_KEY }}"
28-
SERVER_RELOAD_TIMEOUT_SECONDS: 120
39+
SERVER_URL: "${{ steps.github_server.outputs.SERVER_URL }}"
40+
DOCASSEMBLE_DEVELOPER_API_KEY: "${{ steps.github_server.outputs.DOCASSEMBLE_DEVELOPER_API_KEY }}"
41+
INSTALL_METHOD: "server"
42+
# To learn more, see https://assemblyline.suffolklitlab.org/docs/alkiln/writing/#optional-inputs
43+
ALKILN_TAG_EXPRESSION: "${{ env.ALKILN_TAG_EXPRESSION }}"
2944
- run: echo "Finished running ALKiln end-to-end tests"
3045

3146
## To make a new issue in your repository when a test fails,

.github/workflows/da_build.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: DA Build
2+
on:
3+
push:
4+
branches: [ main, master ]
5+
pull_request:
6+
branches: [ main, master ]
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
- uses: SuffolkLITLab/ALActions/da_build@main

.github/workflows/valid_jinja2.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: Valid Jinja2
2+
on:
3+
push:
4+
branches:
5+
- "**"
6+
jobs:
7+
validate:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v4
11+
- uses: SuffolkLITLab/ALActions/valid_jinja2@main

.github/workflows/word_diff.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: Word Diff
2+
on:
3+
pull_request:
4+
jobs:
5+
diff:
6+
runs-on: ubuntu-latest
7+
steps:
8+
- uses: actions/checkout@v4
9+
- uses: SuffolkLITLab/ALActions/word_diff@main

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ docassemble/assemblylinewizard/docassemble*
44
.vscode/
55
.hypothesis/
66
*.egg-info
7+
.code/
78

89
# alkiln testing
910
tests/chromedriver

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
# CHANGELOG
1+
# CHANGELOG (Deprecated)
22

3-
## For revisions after v1.9.0, see https://github.com/SuffolkLITLab/docassemble-ALWeaver/releases/
3+
## For releases after v1.9.0 (i.e. anything after 2023), see https://github.com/SuffolkLITLab/docassemble-ALWeaver/releases/
44

55
## Version v1.9.0
66

7+
May 15th, 2023.
8+
79
### New
810

911
* Radio buttons in weaver by @BryceStevenWilley in [PR 754](https://github.com/SuffolkLITLab/docassemble-ALWeaver/pull/754)

docassemble/ALWeaver/custom_values.py

Lines changed: 55 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from typing import Any, Dict, List, Union, Optional
2-
from pathlib import Path
1+
from typing import Any, Dict, List, Optional, Union
2+
33
import ruamel.yaml as yaml
44
from docassemble.base.util import log, DADict, DAList, DAStore, path_and_mimetype
55
from packaging.version import Version
@@ -21,6 +21,16 @@
2121
]
2222

2323

24+
_CAPABILITY_LOAD_DEFAULTS: Dict[str, Any] = {
25+
"base": "docassemble.ALWeaver",
26+
"minimum_version": "1.5",
27+
"include_playground": False,
28+
}
29+
30+
31+
_capability_cache: Optional[Dict[str, Any]] = None
32+
33+
2434
def _package_name(package_name: Optional[str] = None):
2535
"""Get package name without the name of the current module, like: docassemble.ALWeaver instead of
2636
docassemble.ALWeaver.advertise_capabilities"""
@@ -49,8 +59,10 @@ def __str__(self):
4959

5060

5161
def load_capabilities(
52-
base: str = "docassemble.ALWeaver", minimum_version="1.5", include_playground=False
53-
):
62+
base: str = "docassemble.ALWeaver",
63+
minimum_version: str = "1.5",
64+
include_playground: bool = False,
65+
) -> Dict[str, Any]:
5466
"""
5567
Load and return a dictionary containing all advertised capabilities matching
5668
the specified minimum version, and optionally include capabilities that were
@@ -67,10 +79,9 @@ def load_capabilities(
6779
weaverdata.get("published_configuration_capabilities") or {}
6880
)
6981
try:
82+
yaml_loader = yaml.YAML(typ="safe", pure=True)
7083
with open(this_yaml) as f:
71-
this_yaml_contents = f.read()
72-
73-
first_file = list(yaml.safe_load_all(this_yaml_contents))[0]
84+
first_file = yaml_loader.load(f)
7485

7586
capabilities = {"Default configuration": first_file}
7687
except:
@@ -96,41 +107,45 @@ def load_capabilities(
96107
f"{package_name}:data/sources/{published_configuration_capabilities[package_name][0]}"
97108
)[0]
98109
try:
110+
yaml_loader = yaml.YAML(typ="safe", pure=True)
99111
with open(path) as f:
100-
yaml_contents = f.read()
101-
capabilities[package_name] = list(yaml.safe_load_all(yaml_contents))[0]
112+
capabilities[package_name] = yaml_loader.load(f)
102113
except:
103114
log(f"Unable to load published Weaver configuration file {path}")
104115

105116
return capabilities
106117

107118

108-
_al_weaver_capabilities = load_capabilities()
119+
def _get_capabilities(refresh: bool = False) -> Dict[str, Any]:
120+
"""Return cached capabilities, optionally refreshing from the datastore."""
121+
122+
global _capability_cache
123+
if refresh or _capability_cache is None:
124+
_capability_cache = load_capabilities(**_CAPABILITY_LOAD_DEFAULTS)
125+
return _capability_cache
109126

110127

111128
def get_possible_deps_as_choices(dep_category=None):
112129
"""Gets the possible yml files that the generated interview will depend on"""
113130

114131
dep_choices = []
115132

133+
capabilities = _get_capabilities()
134+
116135
# TODO: do we want to prefix the choice with the package name?
117-
for capability in _al_weaver_capabilities:
136+
for capability in capabilities:
118137
if dep_category == "organization":
119138
dep_choices.extend(
120139
[
121140
{item.get("include_name"): item.get("description")}
122-
for item in _al_weaver_capabilities[capability].get(
123-
"organization_choices", []
124-
)
141+
for item in capabilities[capability].get("organization_choices", [])
125142
]
126143
)
127144
elif dep_category == "jurisdiction":
128145
dep_choices.extend(
129146
[
130147
{item.get("include_name"): item.get("description")}
131-
for item in _al_weaver_capabilities[capability].get(
132-
"jurisdiction_choices", []
133-
)
148+
for item in capabilities[capability].get("jurisdiction_choices", [])
134149
]
135150
)
136151

@@ -146,14 +161,14 @@ def get_pypi_deps_from_choices(choices: Union[List[str], DADict]):
146161
else: # List
147162
choice_list = choices
148163

149-
for capability in _al_weaver_capabilities:
164+
capabilities = _get_capabilities()
165+
166+
for capability in capabilities:
150167
pypi_deps.extend(
151168
[
152169
choice.get("dependency")
153-
for choice in _al_weaver_capabilities[capability].get(
154-
"organization_choices", []
155-
)
156-
+ _al_weaver_capabilities[capability].get("jurisdiction_choices", [])
170+
for choice in capabilities[capability].get("organization_choices", [])
171+
+ capabilities[capability].get("jurisdiction_choices", [])
157172
if choice.get("dependency")
158173
and choice.get("include_name") in choice_list
159174
]
@@ -178,16 +193,14 @@ def get_full_dep_details(dep_category: Optional[str] = None) -> List:
178193
filtered and used as needed."""
179194
dep_choices = []
180195

196+
capabilities = _get_capabilities()
197+
181198
# TODO: do we want to prefix the choice with the package name?
182-
for capability in _al_weaver_capabilities:
199+
for capability in capabilities:
183200
if dep_category == "organization":
184-
dep_choices.extend(
185-
_al_weaver_capabilities[capability].get("organization_choices", [])
186-
)
201+
dep_choices.extend(capabilities[capability].get("organization_choices", []))
187202
elif dep_category == "jurisdiction":
188-
dep_choices.extend(
189-
_al_weaver_capabilities[capability].get("jurisdiction_choices", [])
190-
)
203+
dep_choices.extend(capabilities[capability].get("jurisdiction_choices", []))
191204

192205
return list(unique_everseen(dep_choices))
193206

@@ -200,7 +213,9 @@ def get_matching_deps(
200213
dep_choices = []
201214

202215
# TODO: do we want to prefix the choice with the package name?
203-
for capability in _al_weaver_capabilities.values():
216+
capabilities = _get_capabilities()
217+
218+
for capability in capabilities.values():
204219
if dep_category == "organization":
205220
dep_choices.extend(
206221
[
@@ -234,7 +249,9 @@ def get_output_mako_choices() -> Dict[str, str]:
234249
the interview YAML file. It will be one deep.
235250
"""
236251
choices = {}
237-
for key, capability in _al_weaver_capabilities.items():
252+
capabilities = _get_capabilities()
253+
254+
for key, capability in capabilities.items():
238255
if capability.get("output_mako"):
239256
if isinstance(capability["output_mako"], str):
240257
choices[key] = capability["output_mako"]
@@ -309,3 +326,10 @@ def advertise_capabilities(
309326
weaverdata.set(
310327
"published_configuration_capabilities", published_configuration_capabilities
311328
)
329+
global _CAPABILITY_LOAD_DEFAULTS
330+
_CAPABILITY_LOAD_DEFAULTS = {
331+
**_CAPABILITY_LOAD_DEFAULTS,
332+
"base": base,
333+
"minimum_version": minimum_version,
334+
}
335+
_get_capabilities(refresh=True)

docassemble/ALWeaver/data/questions/assembly_line.yml

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,6 @@ code: |
5959
if yes_recognize_form_fields: # ask to add fields
6060
process_field_recognition
6161
if im_feeling_lucky:
62-
if not formfyxer_available() and user_logged_in() and user_has_privilege(["admin"]) and install_en_core_web_lg:
63-
install_spacy_background_task
64-
if not install_spacy_background_task.ready():
65-
install_spacy_background_waiting_screen
6662
nav.set_sections([
6763
{"nav_generate_interview": "Generate your interview"},
6864
{"nav_review": "Review your answers"},
@@ -1904,20 +1900,6 @@ subquestion: |
19041900
19051901
% endfor
19061902
1907-
% if not formfyxer_available():
1908-
<div class="alert alert-warning" role="alert">
1909-
Automatic field grouping isn't set up. To use it, you need:
1910-
1911-
<ol>
1912-
<li>The `en_core_web_lg` installed, or</li>
1913-
<li>An API token for tools.suffolklitlab.org installed in your configuration.</li>
1914-
</ol>
1915-
1916-
You can still use auto drafting mode but all questions will be
1917-
placed on one screen. You can edit them in your playground later.
1918-
</div>
1919-
% endif
1920-
19211903
fields:
19221904
- Do you want us to draft the interview for you?: im_feeling_lucky
19231905
datatype: radio
@@ -1947,40 +1929,6 @@ fields:
19471929
show if: interview.start_with_json
19481930
accept: |
19491931
"application/json"
1950-
- Try to install the `en_core_web_lg` package before using auto drafting mode: install_en_core_web_lg
1951-
help: |
1952-
Installing `en_core_web_lg` will allow you to use automatic field
1953-
grouping but it may use more memory on your server.
1954-
1955-
If you are a nonprofit, you can request an API token to use
1956-
auto field grouping without installing `en_core_web_lg`.
1957-
datatype: yesnoradio
1958-
show if:
1959-
variable: im_feeling_lucky
1960-
is: True
1961-
code: |
1962-
not formfyxer_available() and user_logged_in() and user_has_privilege(["admin"])
1963-
---
1964-
code: |
1965-
install_spacy_background_task = background_action("install_spacy_background_action")
1966-
---
1967-
code: |
1968-
install_spacy_model()
1969-
background_response()
1970-
install_spacy_background_action = True
1971-
---
1972-
event: install_spacy_background_waiting_screen
1973-
id: waiting screen
1974-
question: |
1975-
Installing `en_core_web_lg`
1976-
subquestion: |
1977-
Please wait while we install `en_core_web_lg`. This can take a
1978-
few minutes to complete.
1979-
1980-
<div class="spinner-border" role="status">
1981-
<span class="visually-hidden">Loading...</span>
1982-
</div>
1983-
reload: True
19841932
---
19851933
template: explain_auto_drafting
19861934
subject: |

0 commit comments

Comments
 (0)