-
Notifications
You must be signed in to change notification settings - Fork 7
test model dump and fix, add tests to pr workflow #101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
87dbc18
7af59ee
752a7b8
bfea19b
cd9665b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
name: "Setup Python" | ||
description: "Setup Python and dependencies" | ||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Setup Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: '>=3.11' | ||
|
||
- name: Install dependencies | ||
shell: bash | ||
run: pip install -r requirements.txt |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: Pull Request Test Update Workflow | ||
on: | ||
pull_request: | ||
types: | ||
- opened | ||
- synchronize | ||
- reopened | ||
|
||
jobs: | ||
test_run: | ||
name: Test that update contributions workflow runs | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout sources | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Python | ||
uses: ./.github/actions/setup | ||
|
||
- name: run unit tests | ||
run: pytest | ||
|
||
- name: fetch updates on contributions | ||
run: python -u scripts/fetch_updates.py | ||
|
||
- name: write contribs.txt file | ||
run: python -u scripts/to_contribs_txt.py | ||
|
||
- name: write source json files | ||
run: python -u scripts/to_sources_jsons.py |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
import pathlib | ||
import shutil | ||
from collections import defaultdict | ||
from typing import List | ||
|
||
from utils import get_valid_contributions | ||
|
||
|
@@ -45,6 +46,40 @@ def read_contribs_text(filepath): | |
return contribs_list | ||
|
||
|
||
def preprocess_contributions() -> List: | ||
all_contributions = get_valid_contributions() | ||
|
||
# sort contributions list by type | ||
def sort_key(d): | ||
return type_list.index(d['type']) | ||
all_contributions = sorted(all_contributions, key=sort_key) | ||
|
||
return all_contributions | ||
|
||
|
||
def write_contribs(all_contributions, fh): | ||
for contribution in all_contributions: | ||
fh.write(contribution['type'] + '\n') | ||
for field in contribs_fields_list: | ||
if field in contribution: | ||
if field == 'id': | ||
fh.write(f'{field}={contribution[field]:03}\n') | ||
elif field == 'categories': | ||
if contribution['type'] == 'library': | ||
fh.write(f'{field}={",".join(contribution[field]) if contribution[field] else ""}\n') | ||
else: | ||
# categories are only relevant for libraries, except for examples with "Books" as category | ||
if contribution[field] and 'Books' in contribution[field]: | ||
fh.write(f'{field}={",".join(contribution[field]) if contribution[field] else ""}\n') | ||
else: | ||
fh.write(f'{field}=\n') | ||
elif field == 'compatibleModesList': | ||
fh.write(f'modes={contribution[field]}\n') | ||
else: | ||
fh.write(f'{field}={"" if contribution[field] is None else contribution[field]}\n') | ||
Comment on lines
+64
to
+79
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think using a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, I'll put this comment into an issue, as a possible future improvement to the code. |
||
fh.write('\n') | ||
|
||
|
||
if __name__ == "__main__": | ||
pde_folder = pathlib.Path(__file__).parent.parent / 'pde/' | ||
# remove sources folder if it already exists | ||
|
@@ -54,34 +89,10 @@ def read_contribs_text(filepath): | |
|
||
contribs_text_file = pde_folder / 'contribs.txt' | ||
|
||
contributions_list = get_valid_contributions() | ||
|
||
# sort contributions list by type | ||
def sort_key(d): | ||
return type_list.index(d['type']) | ||
contributions_list = sorted(contributions_list, key=sort_key) | ||
contributions_list = preprocess_contributions() | ||
|
||
# write contribs.txt file | ||
with open(contribs_text_file, 'w+') as f: | ||
for contribution in contributions_list: | ||
f.write(contribution['type']+'\n') | ||
for field in contribs_fields_list: | ||
if field in contribution: | ||
if field == 'id': | ||
f.write(f'{field}={contribution[field]:03}\n') | ||
elif field == 'categories': | ||
if contribution['type'] == 'library': | ||
f.write(f'{field}={",".join(contribution[field]) if contribution[field] else ""}\n') | ||
else: | ||
# categories are only relevant for libraries, except for examples with "Books" as category | ||
if contribution[field] and 'Books' in contribution[field]: | ||
f.write(f'{field}={",".join(contribution[field]) if contribution[field] else ""}\n') | ||
else: | ||
f.write(f'{field}=\n') | ||
elif field == 'compatibleModesList': | ||
f.write(f'modes={contribution[field]}\n') | ||
else: | ||
f.write(f'{field}={"" if contribution[field] is None else contribution[field]}\n') | ||
f.write('\n') | ||
write_contribs(contributions_list, f) | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.