Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
0316c61
add git-shortlog-authors directive
njzjz Aug 11, 2022
f2e83c5
fix typo
njzjz Aug 11, 2022
5103c83
fix errors
njzjz Aug 11, 2022
e787865
fix errors
njzjz Aug 11, 2022
e101fe5
debug
njzjz Aug 11, 2022
6317c63
debug
njzjz Aug 11, 2022
b5f4569
use git shortlog HEAD
njzjz Aug 11, 2022
a9c765f
add docs
njzjz Aug 11, 2022
f851870
git fetch if unshallow
njzjz Aug 11, 2022
b2a3d89
empty commit to debug shallow clone
njzjz Aug 11, 2022
9dbaac5
empty commit to debug shallow clone
njzjz Aug 11, 2022
e41bfc5
empty commit to debug shallow clone
njzjz Aug 11, 2022
0f795d6
empty commit to debug shallow clone
njzjz Aug 11, 2022
5fc51c5
empty commit to debug shallow clone
njzjz Aug 11, 2022
d5d7eb0
empty commit to debug shallow clone
njzjz Aug 11, 2022
d87f659
empty commit to debug shallow clone
njzjz Aug 11, 2022
0f087f2
empty commit to debug shallow clone
njzjz Aug 11, 2022
3868ef2
empty commit to debug shallow clone
njzjz Aug 11, 2022
3b7da81
empty commit to debug shallow clone
njzjz Aug 11, 2022
1311884
empty commit to debug shallow clone
njzjz Aug 11, 2022
1e22fa1
empty commit to debug shallow clone
njzjz Aug 11, 2022
ed6173f
empty commit to debug shallow clone
njzjz Aug 11, 2022
2ca3d97
empty commit to debug shallow clone
njzjz Aug 11, 2022
4a60d54
empty commit to debug shallow clone
njzjz Aug 11, 2022
8d1bec0
empty commit to debug shallow clone
njzjz Aug 11, 2022
ad647a9
empty commit to debug shallow clone
njzjz Aug 11, 2022
1a092a7
empty commit to debug shallow clone
njzjz Aug 11, 2022
6f90969
empty commit to debug shallow clone
njzjz Aug 11, 2022
4e057de
empty commit to debug shallow clone
njzjz Aug 11, 2022
60db64e
fix typo
njzjz Aug 11, 2022
b94808c
debug output_git_rev_parse
njzjz Aug 11, 2022
aba7c32
remove debug lines
njzjz Aug 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,21 @@ This package should be used in all sphinx projects under the [@deepmodeling](htt

## How to use it

### Setup

Add `deepmodeling_sphinx` to the requirements, as well as the `extensions` of `conf.py`:

```py
extensions = [
'deepmodeling_sphinx',
]
```

### Render list of authors

The following directive can be used to render list of authors from `git shortlog`:

```rst
.. git-shortlog-authors::

```
11 changes: 10 additions & 1 deletion deepmodeling_sphinx/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
from .inject import setup
from typing import Any, Dict
from sphinx.application import Sphinx

from .inject import setup as setup_inject
from .authors import setup as setup_authors

def setup(app: Sphinx) -> Dict[str, Any]:
setup_inject(app)
setup_authors(app)
return {'parallel_read_safe': True}

__all__ = ['setup']
56 changes: 56 additions & 0 deletions deepmodeling_sphinx/authors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""A directive to list all authors from git-shortlog."""

import os
import subprocess
from typing import Any, Dict, Iterator

from sphinx.application import Sphinx
from sphinx.util.docutils import SphinxDirective


def git_shortlog() -> str:
"""Return git-shortlog output as a string.

Returns
-------
str
Git-shortlog output.
"""
if os.environ.get("READTHEDOCS", None) == "True":
# check if it shallow clone
output_git_rev_parse = subprocess.check_output(["git", "rev-parse", "--is-shallow-repository"]).decode('utf-8').strip()
if output_git_rev_parse == "true":
# fetch full history
subprocess.check_output(["git", "fetch", "--unshallow"])
return subprocess.check_output(['git', 'shortlog', 'HEAD', '-s']).decode('utf-8')


def get_authors() -> Iterator[str]:
"""Yields authors from git-shortlog.

Yields
------
str
Author name.
"""
shortlog_text = git_shortlog()
for line in shortlog_text.splitlines():
yield line.split('\t')[1]


class AuthorsDirective(SphinxDirective):
"""authors directive."""
has_content = False
option_spec = dict(
)


def run(self):
"""Run directive."""
authors = ["* " + author for author in get_authors()]
self.state_machine.insert_input(authors, "")
return []

def setup(app: Sphinx) -> Dict[str, Any]:
app.add_directive(name="git-shortlog-authors", cls=AuthorsDirective)
return {'parallel_read_safe': True}
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from datetime import date

project = 'DeepModeling'
project = 'deepmodeling_sphinx'
copyright = '2022-%d, DeepModeling' % date.today().year
author = 'DeepModeling'

Expand Down
4 changes: 4 additions & 0 deletions docs/credits.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Authors
=======

.. git-shortlog-authors::
14 changes: 14 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
.. include:: ../README.md
:parser: myst_parser.sphinx_

Others
------

.. toctree::
:hidden:

Summary <self>


.. toctree::
:titlesonly:

credits

------------------


Expand Down