Skip to content

Commit c5a6eee

Browse files
MNT: update update_zenodo.py script (#3042)
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.
1 parent c3c6895 commit c5a6eee

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

.maint/update_zenodo.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,36 @@ def get_git_lines(fname='line-contributors.txt'):
8585
return [' '.join(line.strip().split()[1:-1]) for line in lines if '%' in line]
8686

8787

88+
def loads_table_from_markdown(s):
89+
"""Read the first table from a Markdown text."""
90+
table = []
91+
header = None
92+
for line in s.splitlines():
93+
if line.startswith("|"):
94+
if not header:
95+
# read header and strip bold
96+
header = [item.strip("* ") for item in line.split('|')[1:-1]]
97+
else:
98+
values = [item.strip() for item in line.split('|')[1:-1]]
99+
if any(any(c != "-" for c in item) for item in values):
100+
table.append(dict(zip(header, values)))
101+
elif header:
102+
# we have already seen a table, we're past the end of that table
103+
break
104+
return table
105+
106+
107+
def loads_contributors(s):
108+
"""Reformat contributors read from the Markdown table."""
109+
return [
110+
{
111+
"affiliation": contributor["Affiliation"],
112+
"name": "{}, {}".format(contributor["Lastname"], contributor["Name"]),
113+
"orcid": contributor["ORCID"],
114+
} for contributor in loads_table_from_markdown(s)
115+
]
116+
117+
88118
if __name__ == '__main__':
89119
data = get_git_lines()
90120

@@ -96,7 +126,7 @@ def get_git_lines(fname='line-contributors.txt'):
96126
creators, data,
97127
exclude=json.loads(Path('.maint/former.json').read_text()),
98128
last=CREATORS_LAST)
99-
contributors = json.loads(Path('.maint/contributors.json').read_text())
129+
contributors = loads_contributors(Path('.maint/CONTRIBUTORS.md').read_text())
100130
zen_contributors, miss_contributors = sort_contributors(
101131
contributors, data,
102132
exclude=json.loads(Path('.maint/former.json').read_text()),

0 commit comments

Comments
 (0)