Skip to content

Commit

Permalink
contrib: add per-chapter authors
Browse files Browse the repository at this point in the history
  • Loading branch information
casperdcl committed Sep 8, 2023
1 parent 1ca2197 commit 7236d00
Show file tree
Hide file tree
Showing 14 changed files with 124 additions and 0 deletions.
1 change: 1 addition & 0 deletions .mailmap
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Biswaroop Bhattacharjee <[email protected]>
1 change: 1 addition & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ sphinx:
extra_extensions:
- sphinxemoji.sphinxemoji
- sphinx_last_updated_by_git
- committers
config:
html_js_files:
- [https://analytics.prem.ninja/js/script.js, {defer: defer, data-domain: book.premai.io}]
Expand Down
89 changes: 89 additions & 0 deletions committers.py
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}
3 changes: 3 additions & 0 deletions desktop-apps.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ See also:
## GPT4All UI

{{ comments }}

```{committers} desktop-apps.md
```
3 changes: 3 additions & 0 deletions eval-datasets.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ probably put short definition in [](glossary)?
## Reinforcement Learning for a Chat-based LLM

{{ comments }}

```{committers} eval-datasets.md
```
3 changes: 3 additions & 0 deletions fine-tuning.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,6 @@ Falcon |
## Code Generators

{{ comments }}

```{committers} fine-tuning.md
```
3 changes: 3 additions & 0 deletions hardware.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ See also:
+ LLM-specific advice: https://gpus.llm-utils.org/cloud-gpu-guide/#which-gpu-cloud-should-i-use

{{ comments }}

```{committers} hardware.md
```
3 changes: 3 additions & 0 deletions licences.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,6 @@ In the long term, we look forward to the outcomes of the US cases and EU proposa
(licences-comments)=

{{ comments }}

```{committers} licences.md
```
3 changes: 3 additions & 0 deletions mlops-engines.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ See also https://onnxruntime.ai/docs/execution-providers
### Apache TVM

{{ comments }}

```{committers} mlops-engines.md
```
3 changes: 3 additions & 0 deletions model-formats.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ See also:
## TVM

{{ comments }}

```{committers} model-formats.md
```
3 changes: 3 additions & 0 deletions models.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ See also:
- {cite}`golden-age-os-end`

{{ comments }}

```{committers} models.md
```
3 changes: 3 additions & 0 deletions sdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ See also: https://github.com/huggingface/transformers/blob/main/awesome-transfor
## Haystack

{{ comments }}

```{committers} sdk.md
```
3 changes: 3 additions & 0 deletions uncensored-models.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ FraudGPT, PoisonGPT
"Cybercriminals train AI chatbots for phishing, malware attacks" (WormGPT: ChatGPT clone trained on malware-focused data, new: FraudGPT, coming soon: Bard-based version) https://www.bleepingcomputer.com/news/security/cybercriminals-train-ai-chatbots-for-phishing-malware-attacks

{{ comments }}

```{committers} uncensored-models.md
```
3 changes: 3 additions & 0 deletions vector-stores.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@
## Chroma

{{ comments }}

```{committers} vector-stores.md
```

0 comments on commit 7236d00

Please sign in to comment.