Skip to content

Commit

Permalink
MNT: update update_zenodo.py script (#3042)
Browse files Browse the repository at this point in the history
This is an attempt to update script `.maint/update_zenodo.py`.

- File `contributors.json` appears to have been replaced by a table in
Markdown file `CONTRIBUTORS.md`.
- Files `former.json` and `FORMER.md` luckily point to the same person.
I haven't changed anything here: still reading from `former.json`.

Note that some contributors have two affiliations, and convey that using
a JSON/Python array inside the Markdown array.
```
| Frederick         | Blaise B.    |  | 0000-0001-5832-5279 | ['McLean Hospital Brain Imaging Center, MA, USA', 'Consolidated Department of Psychiatry, Harvard Medical School, MA, USA']                  |
```
```
| Ghosh             | Satrajit S.  |  | 0000-0002-5312-6729 | ['McGovern Institute for Brain Research, MIT, MA, USA', 'Department of Otolaryngology, Harvard Medical School, MA, USA']                     |
```
Would it be preferable to revert 059b59c use a JSON `contributors.json`
file and have a script update `CONTRIBUTORS.md`?

Alternatively, I can use the “ugly” solution of separating affiliations
in the Markdown table with **`<br/>`**. Probably uglier, I could also
interpret the JSON/Python arrays inside the Markdown table.
  • Loading branch information
DimitriPapadopoulos committed Jun 17, 2023
1 parent c3c6895 commit c5a6eee
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion .maint/update_zenodo.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,36 @@ def get_git_lines(fname='line-contributors.txt'):
return [' '.join(line.strip().split()[1:-1]) for line in lines if '%' in line]


def loads_table_from_markdown(s):
"""Read the first table from a Markdown text."""
table = []
header = None
for line in s.splitlines():
if line.startswith("|"):
if not header:
# read header and strip bold
header = [item.strip("* ") for item in line.split('|')[1:-1]]
else:
values = [item.strip() for item in line.split('|')[1:-1]]
if any(any(c != "-" for c in item) for item in values):
table.append(dict(zip(header, values)))
elif header:
# we have already seen a table, we're past the end of that table
break
return table


def loads_contributors(s):
"""Reformat contributors read from the Markdown table."""
return [
{
"affiliation": contributor["Affiliation"],
"name": "{}, {}".format(contributor["Lastname"], contributor["Name"]),
"orcid": contributor["ORCID"],
} for contributor in loads_table_from_markdown(s)
]


if __name__ == '__main__':
data = get_git_lines()

Expand All @@ -96,7 +126,7 @@ def get_git_lines(fname='line-contributors.txt'):
creators, data,
exclude=json.loads(Path('.maint/former.json').read_text()),
last=CREATORS_LAST)
contributors = json.loads(Path('.maint/contributors.json').read_text())
contributors = loads_contributors(Path('.maint/CONTRIBUTORS.md').read_text())
zen_contributors, miss_contributors = sort_contributors(
contributors, data,
exclude=json.loads(Path('.maint/former.json').read_text()),
Expand Down

0 comments on commit c5a6eee

Please sign in to comment.