Skip to content

Commit

Permalink
Merge branch 'main' into plot_carpet
Browse files Browse the repository at this point in the history
  • Loading branch information
effigies authored May 16, 2024
2 parents 2e1be1d + 60fd854 commit be2df83
Show file tree
Hide file tree
Showing 39 changed files with 457 additions and 396 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/contrib.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Contribution checks
on: [push, pull_request]

defaults:
run:
shell: bash

jobs:
stable:
name: Run ruff
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0
- name: Set up Python 3
uses: actions/setup-python@v5
with:
python-version: 3

- name: Install and run pre-commit hooks
uses: pre-commit/[email protected]
4 changes: 2 additions & 2 deletions .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ Christopher J. Markiewicz <[email protected]>
Christopher J. Markiewicz <[email protected]> <[email protected]>
Christopher J. Markiewicz <[email protected]> <[email protected]>
Conrad Ma <[email protected]>
Conrad Ma <[email protected]> Conrad
Conrad Ma <[email protected]> 394822740
Conrad Ma <[email protected]> Conrad
Conrad Ma <[email protected]> 394822740
Conrad Ma <[email protected]> <[email protected]>
Conrad Ma <[email protected]> <[email protected]>
Dylan Nielson <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion .maint/PIs.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ If you are participating because of your affiliation with another organization (
| **Lastname** | **Name** | **Handle** | **ORCID** | **Affiliation** | **Position** |
| --- | --- | --- | --- | --- | --- |
| Esteban | Oscar | @oesteban | 0000-0001-8435-6191 | Department of Radiology, Lausanne University Hospital and University of Lausanne | -1 |
| Poldrack | Russell A. | @poldrack | 0000-0001-6755-0259 | Department of Psychology, Stanford University, CA, USA | -2 |
| Poldrack | Russell A. | @poldrack | 0000-0001-6755-0259 | Department of Psychology, Stanford University, CA, USA | -2 |
2 changes: 1 addition & 1 deletion .maint/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
click
fuzzywuzzy
fuzzywuzzy
111 changes: 57 additions & 54 deletions .maint/update_authors.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/usr/bin/env python3
"""Update and sort the creators list of the zenodo record."""

import json
import sys
from pathlib import Path
import json

import click
from fuzzywuzzy import fuzz, process

Expand Down Expand Up @@ -36,10 +38,7 @@ def read_md_table(md_text):
retval = []
for line in md_text.splitlines():
if line.strip().startswith("| --- |"):
keys = (
k.replace("*", "").strip()
for k in prev.split("|")
)
keys = (k.replace("*", "").strip() for k in prev.split("|"))
keys = [k.lower() for k in keys if k]
continue
elif not keys:
Expand All @@ -50,29 +49,16 @@ def read_md_table(md_text):
break

values = [v.strip() or None for v in line.split("|")][1:-1]
retval.append({k: v for k, v in zip(keys, values) if v})
retval.append({k: v for k, v in zip(keys, values, strict=True) if v})

return retval


def sort_contributors(entries, git_lines, exclude=None, last=None):
"""Return a list of author dictionaries, ordered by contribution."""
last = last or []
sorted_authors = sorted(entries, key=lambda i: i["name"])

first_last = [
" ".join(val["name"].split(",")[::-1]).strip() for val in sorted_authors
]
first_last_excl = [
" ".join(val["name"].split(",")[::-1]).strip() for val in exclude or []
]

def _extract_git_contributor_matches(git_lines, sorted_authors, first_last, first_last_excl):
unmatched = []
author_matches = []
for ele in git_lines:
matches = process.extract(
ele, first_last, scorer=fuzz.token_sort_ratio, limit=2
)
matches = process.extract(ele, first_last, scorer=fuzz.token_sort_ratio, limit=2)
# matches is a list [('First match', % Match), ('Second match', % Match)]
if matches[0][1] > 80:
val = sorted_authors[first_last.index(matches[0][0])]
Expand All @@ -85,18 +71,39 @@ def sort_contributors(entries, git_lines, exclude=None, last=None):
if val not in author_matches:
author_matches.append(val)

names = {" ".join(val["name"].split(",")[::-1]).strip() for val in author_matches}
for missing_name in first_last:
if missing_name not in names:
missing = sorted_authors[first_last.index(missing_name)]
author_matches.append(missing)
return author_matches, unmatched


def _get_position_matches(author_matches):
position_matches = []
for i, item in enumerate(author_matches):
pos = item.pop("position", None)
if pos is not None:
position_matches.append((i, int(pos)))

return position_matches


def sort_contributors(entries, git_lines, exclude=None, last=None):
"""Return a list of author dictionaries, ordered by contribution."""
last = last or []
sorted_authors = sorted(entries, key=lambda i: i["name"])

first_last = [" ".join(val["name"].split(",")[::-1]).strip() for val in sorted_authors]
first_last_excl = [" ".join(val["name"].split(",")[::-1]).strip() for val in exclude or []]

author_matches, unmatched = _extract_git_contributor_matches(
git_lines, sorted_authors, first_last, first_last_excl
)

names = {" ".join(val["name"].split(",")[::-1]).strip() for val in author_matches}
for missing_name in first_last:
if missing_name not in names:
missing = sorted_authors[first_last.index(missing_name)]
author_matches.append(missing)

position_matches = _get_position_matches(author_matches)

for i, pos in position_matches:
if pos < 0:
pos += len(author_matches) + 1
Expand All @@ -121,7 +128,7 @@ def get_git_lines(fname="line-contributors.txt"):
if not lines and git_line_summary_path:
print("Running git-line-summary on repo")
lines = sp.check_output([git_line_summary_path]).decode().splitlines()
lines = [l for l in lines if "Not Committed Yet" not in l]
lines = [ele for ele in lines if "Not Committed Yet" not in ele]
contrib_file.write_text("\n".join(lines))

if not lines:
Expand Down Expand Up @@ -152,8 +159,12 @@ def cli():
@cli.command()
@click.option("-z", "--zenodo-file", type=click.Path(exists=True), default=".zenodo.json")
@click.option("-m", "--maintainers", type=click.Path(exists=True), default=".maint/MAINTAINERS.md")
@click.option("-c", "--contributors", type=click.Path(exists=True),
default=".maint/CONTRIBUTORS.md")
@click.option(
"-c",
"--contributors",
type=click.Path(exists=True),
default=".maint/CONTRIBUTORS.md",
)
@click.option("--pi", type=click.Path(exists=True), default=".maint/PIs.md")
@click.option("-f", "--former-file", type=click.Path(exists=True), default=".maint/FORMER.md")
def zenodo(
Expand All @@ -176,15 +187,13 @@ def zenodo(
)

zen_contributors, miss_contributors = sort_contributors(
_namelast(read_md_table(Path(contributors).read_text())),
data,
exclude=former
_namelast(read_md_table(Path(contributors).read_text())), data, exclude=former
)

zen_pi = _namelast(
sorted(
read_md_table(Path(pi).read_text()),
key=lambda v: (int(v.get("position", -1)), v.get("lastname"))
key=lambda v: (int(v.get("position", -1)), v.get("lastname")),
)
)

Expand All @@ -194,8 +203,7 @@ def zenodo(
misses = set(miss_creators).intersection(miss_contributors)
if misses:
print(
"Some people made commits, but are missing in .maint/ "
f"files: {', '.join(misses)}",
"Some people made commits, but are missing in .maint/ " f"files: {', '.join(misses)}",
file=sys.stderr,
)

Expand All @@ -214,15 +222,17 @@ def zenodo(
if isinstance(creator["affiliation"], list):
creator["affiliation"] = creator["affiliation"][0]

Path(zenodo_file).write_text(
"%s\n" % json.dumps(zenodo, indent=2)
)
Path(zenodo_file).write_text("%s\n" % json.dumps(zenodo, indent=2))


@cli.command()
@click.option("-m", "--maintainers", type=click.Path(exists=True), default=".maint/MAINTAINERS.md")
@click.option("-c", "--contributors", type=click.Path(exists=True),
default=".maint/CONTRIBUTORS.md")
@click.option(
"-c",
"--contributors",
type=click.Path(exists=True),
default=".maint/CONTRIBUTORS.md",
)
@click.option("--pi", type=click.Path(exists=True), default=".maint/PIs.md")
@click.option("-f", "--former-file", type=click.Path(exists=True), default=".maint/FORMER.md")
def publication(
Expand All @@ -232,9 +242,8 @@ def publication(
former_file,
):
"""Generate the list of authors and affiliations for papers."""
members = (
_namelast(read_md_table(Path(maintainers).read_text()))
+ _namelast(read_md_table(Path(contributors).read_text()))
members = _namelast(read_md_table(Path(maintainers).read_text())) + _namelast(
read_md_table(Path(contributors).read_text())
)

hits, misses = sort_contributors(
Expand All @@ -246,15 +255,12 @@ def publication(
pi_hits = _namelast(
sorted(
read_md_table(Path(pi).read_text()),
key=lambda v: (int(v.get("position", -1)), v.get("lastname"))
key=lambda v: (int(v.get("position", -1)), v.get("lastname")),
)
)

pi_names = [pi["name"] for pi in pi_hits]
hits = [
hit for hit in hits
if hit["name"] not in pi_names
] + pi_hits
hits = [hit for hit in hits if hit["name"] not in pi_names] + pi_hits

def _aslist(value):
if isinstance(value, (list, tuple)):
Expand All @@ -281,8 +287,7 @@ def _aslist(value):

if misses:
print(
"Some people made commits, but are missing in .maint/ "
f"files: {', '.join(misses)}",
"Some people made commits, but are missing in .maint/ " f"files: {', '.join(misses)}",
file=sys.stderr,
)

Expand All @@ -292,16 +297,14 @@ def _aslist(value):
% "; ".join(
[
"%s \\ :sup:`%s`\\ " % (i["name"], idx)
for i, idx in zip(hits, aff_indexes)
for i, idx in zip(hits, aff_indexes, strict=True)
]
)
)

print(
"\n\nAffiliations:\n%s"
% "\n".join(
["{0: >2}. {1}".format(i + 1, a) for i, a in enumerate(affiliations)]
)
% "\n".join(["{0: >2}. {1}".format(i + 1, a) for i, a in enumerate(affiliations)])
)


Expand Down
51 changes: 31 additions & 20 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
# To install the git pre-commit hook run:
# pre-commit install
# To update the pre-commit hooks run:
# pre-commit install-hooks

exclude: |
(?x)^(
docs/_static/.*|
nireports/tests/data/.*|
nireports/assembler/data/tests/work/.*|
nireports/assembler/data/tests/crashfile.txt|
nireports/assembler/data/.*\.tpl
)$
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-json
- id: check-toml
- id: check-case-conflict
- id: check-docstring-first
- id: check-merge-conflict
- id: check-vcs-permalinks
- id: pretty-format-json
args: ['--autofix']
- repo: https://github.com/psf/black
rev: 22.3.0
- id: trailing-whitespace
- id: end-of-file-fixer
- id: debug-statements
- id: check-yaml
- id: check-json
- id: check-toml
- id: check-case-conflict
- id: check-docstring-first
- id: check-merge-conflict
- id: check-vcs-permalinks
- id: pretty-format-json
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.4
hooks:
- id: black
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
- id: ruff
args: [ --fix ]
- id: ruff-format
Loading

0 comments on commit be2df83

Please sign in to comment.