prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Update prep_zenodo.py to only count commits in grabbit up to 0.2.6
  With #369, we're dropping the grabbit dependency, so changes there will no longer contribute to pybids.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `tools/prep_zenodo.py`
  Content:
  ```
  1 #!/usr/bin/env python3
  2 import git
  3 import json
  4 from subprocess import run, PIPE, CalledProcessError
  5 from pathlib import Path
  6 from tempfile import TemporaryDirectory
  7 
  8 
  9 def decommify(name):
  10     return ' '.join(name.split(', ')[::-1])
  11 
  12 
  13 # List of repositories whose commits should be counted as contributions
  14 codependents = ['https://github.com/grabbles/grabbit.git']
  15 
  16 # Last shablona commit
  17 origin_commit = 'd72caaf5933907ed699d57faddaec7bfc836ce6f'
  18 
  19 git_root = Path(git.Repo('.', search_parent_directories=True).working_dir)
  20 zenodo_file = git_root / '.zenodo.json'
  21 
  22 zenodo = json.loads(zenodo_file.read_text()) if zenodo_file.exists() else {}
  23 
  24 orig_creators = zenodo.get('creators', [])
  25 creator_map = {decommify(creator['name']): creator
  26                for creator in orig_creators}
  27 
  28 shortlog = run(['git', 'shortlog', '-ns', f'{origin_commit}..'], stdout=PIPE)
  29 counts = [line.split('\t', 1)[::-1]
  30           for line in shortlog.stdout.decode().split('\n') if line]
  31 
  32 # Get additional commit counts from dependencies
  33 with TemporaryDirectory() as tmpdir:
  34     tmppath = Path(tmpdir)
  35     for repo in codependents:
  36         repo_dir = str(tmppath / repo.rsplit('/', 1)[1].split('.', 1)[0])
  37         try:
  38             clone = run(['git', 'clone', repo, repo_dir], check=True)
  39         except CalledProcessError as err:
  40             raise RuntimeError("Could not clone {}".format(repo)) from err
  41         tag = run(['git', '-C', repo_dir, 'tag'], stdout=PIPE)
  42         latest_tag = tag.stdout.decode().strip().rsplit('\n', 1)[1]
  43         dep_shortlog = run(
  44             ['git', '-C', repo_dir, 'shortlog', '-ns', latest_tag],
  45             stdout=PIPE)
  46         counts.extend(line.split('\t', 1)[::-1]
  47                       for line in dep_shortlog.stdout.decode().split('\n')
  48                       if line)
  49 
  50 commit_counts = {}
  51 for committer, commits in counts:
  52     commit_counts[committer] = commit_counts.get(committer, 0) + int(commits)
  53 
  54 # Stable sort:
  55 # Number of commits in reverse order
  56 # Ties broken by alphabetical order of first name
  57 committers = [committer
  58               for committer, _ in sorted(commit_counts.items(),
  59                                          key=lambda x: (-x[1], x[0]))]
  60 
  61 # Tal to the top
  62 first_author = 'Tal Yarkoni'
  63 if committers[0] != first_author:
  64     committers.remove(first_author)
  65     committers.insert(0, first_author)
  66 
  67 creators = [
  68     creator_map.get(committer, {'name': committer})
  69     for committer in committers
  70     ]
  71 
  72 zenodo['creators'] = creators
  73 zenodo_file.write_text(json.dumps(zenodo, indent=2, sort_keys=True) + '\n')
  74
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/tools/prep_zenodo.py b/tools/prep_zenodo.py
  --- a/tools/prep_zenodo.py
  +++ b/tools/prep_zenodo.py
  @@ -11,7 +11,7 @@
   
   
   # List of repositories whose commits should be counted as contributions
  -codependents = ['https://github.com/grabbles/grabbit.git']
  +codependents = [('https://github.com/grabbles/grabbit.git', '0.2.6')]
   
   # Last shablona commit
   origin_commit = 'd72caaf5933907ed699d57faddaec7bfc836ce6f'
  @@ -33,15 +33,23 @@
   with TemporaryDirectory() as tmpdir:
       tmppath = Path(tmpdir)
       for repo in codependents:
  +        try:
  +            repo, ref = repo
  +        except (TypeError, ValueError):
  +            ref = None
           repo_dir = str(tmppath / repo.rsplit('/', 1)[1].split('.', 1)[0])
           try:
  -            clone = run(['git', 'clone', repo, repo_dir], check=True)
  +            clone = run(['git', 'clone', '-q', repo, repo_dir], check=True)
           except CalledProcessError as err:
               raise RuntimeError("Could not clone {}".format(repo)) from err
  -        tag = run(['git', '-C', repo_dir, 'tag'], stdout=PIPE)
  -        latest_tag = tag.stdout.decode().strip().rsplit('\n', 1)[1]
  +
  +        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', latest_tag],
  +            ['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')
  
verification_info: {"golden_diff": "diff --git a/tools/prep_zenodo.py b/tools/prep_zenodo.py\n--- a/tools/prep_zenodo.py\n+++ b/tools/prep_zenodo.py\n@@ -11,7 +11,7 @@\n \n \n # List of repositories whose commits should be counted as contributions\n-codependents = ['https://github.com/grabbles/grabbit.git']\n+codependents = [('https://github.com/grabbles/grabbit.git', '0.2.6')]\n \n # Last shablona commit\n origin_commit = 'd72caaf5933907ed699d57faddaec7bfc836ce6f'\n@@ -33,15 +33,23 @@\n with TemporaryDirectory() as tmpdir:\n     tmppath = Path(tmpdir)\n     for repo in codependents:\n+        try:\n+            repo, ref = repo\n+        except (TypeError, ValueError):\n+            ref = None\n         repo_dir = str(tmppath / repo.rsplit('/', 1)[1].split('.', 1)[0])\n         try:\n-            clone = run(['git', 'clone', repo, repo_dir], check=True)\n+            clone = run(['git', 'clone', '-q', repo, repo_dir], check=True)\n         except CalledProcessError as err:\n             raise RuntimeError(\"Could not clone {}\".format(repo)) from err\n-        tag = run(['git', '-C', repo_dir, 'tag'], stdout=PIPE)\n-        latest_tag = tag.stdout.decode().strip().rsplit('\\n', 1)[1]\n+\n+        if ref is None:\n+            tag = run(['git', '-C', repo_dir, 'tag'], stdout=PIPE)\n+            # latest tag\n+            ref = tag.stdout.decode().strip().rsplit('\\n', 1)[1]\n+\n         dep_shortlog = run(\n-            ['git', '-C', repo_dir, 'shortlog', '-ns', latest_tag],\n+            ['git', '-C', repo_dir, 'shortlog', '-ns', ref],\n             stdout=PIPE)\n         counts.extend(line.split('\\t', 1)[::-1]\n                       for line in dep_shortlog.stdout.decode().split('\\n')\n", "issue": "Update prep_zenodo.py to only count commits in grabbit up to 0.2.6\nWith #369, we're dropping the grabbit dependency, so changes there will no longer contribute to pybids.\n", "before_files": [{"content": "#!/usr/bin/env python3\nimport git\nimport json\nfrom subprocess import run, PIPE, CalledProcessError\nfrom pathlib import Path\nfrom tempfile import TemporaryDirectory\n\n\ndef decommify(name):\n    return ' '.join(name.split(', ')[::-1])\n\n\n# List of repositories whose commits should be counted as contributions\ncodependents = ['https://github.com/grabbles/grabbit.git']\n\n# Last shablona commit\norigin_commit = 'd72caaf5933907ed699d57faddaec7bfc836ce6f'\n\ngit_root = Path(git.Repo('.', search_parent_directories=True).working_dir)\nzenodo_file = git_root / '.zenodo.json'\n\nzenodo = json.loads(zenodo_file.read_text()) if zenodo_file.exists() else {}\n\norig_creators = zenodo.get('creators', [])\ncreator_map = {decommify(creator['name']): creator\n               for creator in orig_creators}\n\nshortlog = run(['git', 'shortlog', '-ns', f'{origin_commit}..'], stdout=PIPE)\ncounts = [line.split('\\t', 1)[::-1]\n          for line in shortlog.stdout.decode().split('\\n') if line]\n\n# Get additional commit counts from dependencies\nwith TemporaryDirectory() as tmpdir:\n    tmppath = Path(tmpdir)\n    for repo in codependents:\n        repo_dir = str(tmppath / repo.rsplit('/', 1)[1].split('.', 1)[0])\n        try:\n            clone = run(['git', 'clone', repo, repo_dir], check=True)\n        except CalledProcessError as err:\n            raise RuntimeError(\"Could not clone {}\".format(repo)) from err\n        tag = run(['git', '-C', repo_dir, 'tag'], stdout=PIPE)\n        latest_tag = tag.stdout.decode().strip().rsplit('\\n', 1)[1]\n        dep_shortlog = run(\n            ['git', '-C', repo_dir, 'shortlog', '-ns', latest_tag],\n            stdout=PIPE)\n        counts.extend(line.split('\\t', 1)[::-1]\n                      for line in dep_shortlog.stdout.decode().split('\\n')\n                      if line)\n\ncommit_counts = {}\nfor committer, commits in counts:\n    commit_counts[committer] = commit_counts.get(committer, 0) + int(commits)\n\n# Stable sort:\n# Number of commits in reverse order\n# Ties broken by alphabetical order of first name\ncommitters = [committer\n              for committer, _ in sorted(commit_counts.items(),\n                                         key=lambda x: (-x[1], x[0]))]\n\n# Tal to the top\nfirst_author = 'Tal Yarkoni'\nif committers[0] != first_author:\n    committers.remove(first_author)\n    committers.insert(0, first_author)\n\ncreators = [\n    creator_map.get(committer, {'name': committer})\n    for committer in committers\n    ]\n\nzenodo['creators'] = creators\nzenodo_file.write_text(json.dumps(zenodo, indent=2, sort_keys=True) + '\\n')\n", "path": "tools/prep_zenodo.py"}], "after_files": [{"content": "#!/usr/bin/env python3\nimport git\nimport json\nfrom subprocess import run, PIPE, CalledProcessError\nfrom pathlib import Path\nfrom tempfile import TemporaryDirectory\n\n\ndef decommify(name):\n    return ' '.join(name.split(', ')[::-1])\n\n\n# List of repositories whose commits should be counted as contributions\ncodependents = [('https://github.com/grabbles/grabbit.git', '0.2.6')]\n\n# Last shablona commit\norigin_commit = 'd72caaf5933907ed699d57faddaec7bfc836ce6f'\n\ngit_root = Path(git.Repo('.', search_parent_directories=True).working_dir)\nzenodo_file = git_root / '.zenodo.json'\n\nzenodo = json.loads(zenodo_file.read_text()) if zenodo_file.exists() else {}\n\norig_creators = zenodo.get('creators', [])\ncreator_map = {decommify(creator['name']): creator\n               for creator in orig_creators}\n\nshortlog = run(['git', 'shortlog', '-ns', f'{origin_commit}..'], stdout=PIPE)\ncounts = [line.split('\\t', 1)[::-1]\n          for line in shortlog.stdout.decode().split('\\n') if line]\n\n# Get additional commit counts from dependencies\nwith TemporaryDirectory() as tmpdir:\n    tmppath = Path(tmpdir)\n    for repo in codependents:\n        try:\n            repo, ref = repo\n        except (TypeError, ValueError):\n            ref = None\n        repo_dir = str(tmppath / repo.rsplit('/', 1)[1].split('.', 1)[0])\n        try:\n            clone = run(['git', 'clone', '-q', repo, repo_dir], check=True)\n        except CalledProcessError as err:\n            raise RuntimeError(\"Could not clone {}\".format(repo)) from err\n\n        if ref is None:\n            tag = run(['git', '-C', repo_dir, 'tag'], stdout=PIPE)\n            # latest tag\n            ref = tag.stdout.decode().strip().rsplit('\\n', 1)[1]\n\n        dep_shortlog = run(\n            ['git', '-C', repo_dir, 'shortlog', '-ns', ref],\n            stdout=PIPE)\n        counts.extend(line.split('\\t', 1)[::-1]\n                      for line in dep_shortlog.stdout.decode().split('\\n')\n                      if line)\n\ncommit_counts = {}\nfor committer, commits in counts:\n    commit_counts[committer] = commit_counts.get(committer, 0) + int(commits)\n\n# Stable sort:\n# Number of commits in reverse order\n# Ties broken by alphabetical order of first name\ncommitters = [committer\n              for committer, _ in sorted(commit_counts.items(),\n                                         key=lambda x: (-x[1], x[0]))]\n\n# Tal to the top\nfirst_author = 'Tal Yarkoni'\nif committers[0] != first_author:\n    committers.remove(first_author)\n    committers.insert(0, first_author)\n\ncreators = [\n    creator_map.get(committer, {'name': committer})\n    for committer in committers\n    ]\n\nzenodo['creators'] = creators\nzenodo_file.write_text(json.dumps(zenodo, indent=2, sort_keys=True) + '\\n')\n", "path": "tools/prep_zenodo.py"}]}