-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Biswaroop Bhattacharjee <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
"""Print list of Git committer names. | ||
Example MyST usage (HTML only): | ||
```{committers} file_path.md | ||
``` | ||
""" | ||
import json | ||
import os | ||
import re | ||
import subprocess | ||
from collections import Counter | ||
from datetime import timedelta | ||
from functools import cache | ||
from time import ctime, time | ||
|
||
from docutils import nodes | ||
from docutils.parsers.rst import Directive, directives | ||
from sphinx.application import Sphinx | ||
|
||
__version__ = '0.0.0' | ||
|
||
|
||
@cache | ||
def gh_user(email) -> str | None: | ||
headers = [ | ||
'--header', 'Accept: application/vnd.github+json', | ||
'--header', 'X-GitHub-Api-Version: 2022-11-28'] | ||
if (token := os.environ.get("GITHUB_TOKEN", os.environ.get("GH_TOKEN", ""))): | ||
headers.extend(['--header', f'Authorization: Bearer {token}']) | ||
for cmd in ( | ||
['gh', 'api'] + headers + [f'search/users?q={email}+in:email'], | ||
['curl'] + headers + ['-fsSL', f'https://api.github.com/search/users?q={email}+in:email'], | ||
['wget'] + headers + ['-qO', '-', f'https://api.github.com/search/users?q={email}+in:email'] | ||
): | ||
try: | ||
user_info = subprocess.check_output(cmd).decode('utf-8').strip() | ||
except (subprocess.CalledProcessError, FileNotFoundError): | ||
pass | ||
else: | ||
try: | ||
return json.loads(user_info)['items'][0]['login'] | ||
except (KeyError, IndexError): | ||
return | ||
|
||
|
||
class committers_node(nodes.General, nodes.Element): | ||
pass | ||
|
||
|
||
def visit_committers_html(self, node): | ||
self.body.append(self.starttag(node, 'div')) | ||
self.body.append("Authors: ") | ||
self.body.append(", ".join(f'<a href="{href}">{name}</a>' for name, href in node['authors'])) | ||
|
||
|
||
def depart_committers_html(self, node): | ||
self.body.append('</div>') | ||
|
||
|
||
class Committers(Directive): | ||
has_content = True | ||
required_arguments = 1 | ||
optional_arguments = 0 | ||
final_argument_whitespace = True | ||
option_spec = {'class': directives.class_option, 'name': directives.unchanged} | ||
_node = None | ||
|
||
def run(self): | ||
blame = subprocess.check_output([ | ||
'git', 'blame', '--line-porcelain', '-C2', '-M2', '--'] + self.arguments | ||
).decode('utf-8').strip() | ||
authors = Counter(re.findall("^author (.*)\nauthor-mail <(.*)>", blame, flags=re.MULTILINE)) | ||
total_loc = authors.total() | ||
auths = [] | ||
for (name, email), loc in authors.most_common(): | ||
if loc / total_loc < 0.05: | ||
break | ||
if (user := gh_user(email)): | ||
auths.append((name, f"https://github.com/{user}")) | ||
else: | ||
auths.append((name, f"mailto:{email}")) | ||
return [committers_node(authors=auths)] | ||
|
||
|
||
def setup(app: Sphinx): | ||
app.add_node(committers_node, html=(visit_committers_html, depart_committers_html)) | ||
app.add_directive("committers", Committers) | ||
return {'version': __version__, 'parallel_read_safe': True} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,6 @@ See also: | |
## GPT4All UI | ||
|
||
{{ comments }} | ||
|
||
```{committers} desktop-apps.md | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,3 +55,6 @@ Falcon | | |
## Code Generators | ||
|
||
{{ comments }} | ||
|
||
```{committers} fine-tuning.md | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,6 @@ See also: | |
## TVM | ||
|
||
{{ comments }} | ||
|
||
```{committers} model-formats.md | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,6 @@ See also: | |
- {cite}`golden-age-os-end` | ||
|
||
{{ comments }} | ||
|
||
```{committers} models.md | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,6 @@ | |
## Chroma | ||
|
||
{{ comments }} | ||
|
||
```{committers} vector-stores.md | ||
``` |