Skip to content

Commit

Permalink
MNT: Update prep_zenodo blacklist, run blue
Browse files Browse the repository at this point in the history
  • Loading branch information
effigies committed Nov 7, 2022
1 parent e4d0868 commit d0ab64b
Showing 1 changed file with 31 additions and 15 deletions.
46 changes: 31 additions & 15 deletions tools/prep_zenodo.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,18 @@
def decommify(name):
return ' '.join(name.split(', ')[::-1])


# Users who have asked not to be cited at this time
# XXX We should add a shortlog since the most recent tag and explicitly note
# that a blacklisted user has contributed again recently, and verify they still
# do not want to be cited.
blacklist = {'Cecile Madjar', 'Matthew Wardrop', 'Peter Van Dyken', 'github-actions[bot]'}
blacklist = {
'Cecile Madjar',
'Matthew Wardrop',
'Peter Van Dyken',
'github-actions[bot]',
'dependabot[bot]',
}

# List of repositories whose commits should be counted as contributions
codependents = [('https://github.com/grabbles/grabbit.git', '0.2.6')]
Expand All @@ -27,12 +34,16 @@ def decommify(name):
zenodo = json.loads(zenodo_file.read_text()) if zenodo_file.exists() else {}

orig_creators = zenodo.get('creators', [])
creator_map = {decommify(creator['name']): creator
for creator in orig_creators}
creator_map = {
decommify(creator['name']): creator for creator in orig_creators
}

shortlog = run(['git', 'shortlog', '-ns', f'{origin_commit}..'], stdout=PIPE)
counts = [line.split('\t', 1)[::-1]
for line in shortlog.stdout.decode().split('\n') if line]
counts = [
line.split('\t', 1)[::-1]
for line in shortlog.stdout.decode().split('\n')
if line
]

# Get additional commit counts from dependencies
with TemporaryDirectory() as tmpdir:
Expand All @@ -46,19 +57,21 @@ def decommify(name):
try:
clone = run(['git', 'clone', '-q', repo, repo_dir], check=True)
except CalledProcessError as err:
raise RuntimeError("Could not clone {}".format(repo)) from err
raise RuntimeError(f'Could not clone {repo}') from err

if ref is None:
tag = run(['git', '-C', repo_dir, 'tag'], stdout=PIPE)
# latest tag
ref = tag.stdout.decode().strip().rsplit('\n', 1)[1]

dep_shortlog = run(
['git', '-C', repo_dir, 'shortlog', '-ns', ref],
stdout=PIPE)
counts.extend(line.split('\t', 1)[::-1]
for line in dep_shortlog.stdout.decode().split('\n')
if line)
['git', '-C', repo_dir, 'shortlog', '-ns', ref], stdout=PIPE
)
counts.extend(
line.split('\t', 1)[::-1]
for line in dep_shortlog.stdout.decode().split('\n')
if line
)

commit_counts = {}
for committer, commits in counts:
Expand All @@ -67,9 +80,12 @@ def decommify(name):
# Stable sort:
# Number of commits in reverse order
# Ties broken by alphabetical order of first name
committers = [committer
for committer, _ in sorted(commit_counts.items(),
key=lambda x: (-x[1], x[0]))]
committers = [
committer
for committer, _ in sorted(
commit_counts.items(), key=lambda x: (-x[1], x[0])
)
]

# Tal to the top
first_author = 'Tal Yarkoni'
Expand All @@ -81,7 +97,7 @@ def decommify(name):
creator_map.get(committer, {'name': committer})
for committer in committers
if committer not in blacklist
]
]

zenodo['creators'] = creators
zenodo_file.write_text(json.dumps(zenodo, indent=2, ensure_ascii=False) + '\n')

0 comments on commit d0ab64b

Please sign in to comment.