From 0316c61dac7db5bb78403fdd246c1756903578cb Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Wed, 10 Aug 2022 23:28:56 -0400 Subject: [PATCH 01/32] add git-shortlog-authors directive --- deepmodeling_sphinx/__init__.py | 11 ++++++- deepmodeling_sphinx/authors.py | 56 +++++++++++++++++++++++++++++++++ docs/credits.rst | 4 +++ docs/index.rst | 11 +++++++ 4 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 deepmodeling_sphinx/authors.py create mode 100644 docs/credits.rst diff --git a/deepmodeling_sphinx/__init__.py b/deepmodeling_sphinx/__init__.py index b5c4736..974dd6b 100644 --- a/deepmodeling_sphinx/__init__.py +++ b/deepmodeling_sphinx/__init__.py @@ -1,3 +1,12 @@ -from .inject import setup +from typing import Any, Dict +from sphinx.application import Sphinx + +from .inject import setup_inject +from .authors import setup_authors + +def setup(app: Sphinx) -> Dict[str, Any]: + setup_inject(app) + setup_authors(app) + return {'parallel_read_safe': True} __all__ = ['setup'] diff --git a/deepmodeling_sphinx/authors.py b/deepmodeling_sphinx/authors.py new file mode 100644 index 0000000..c2d25bc --- /dev/null +++ b/deepmodeling_sphinx/authors.py @@ -0,0 +1,56 @@ +"""A directive to list all authors from git-shortlog.""" + +import subprocess +from typing import Any, Dict, Iterator + +from docutils import nodes +from docutils.statemachine import StringList +from sphinx.application import Sphinx +from sphinx.util import nested_parse_with_titles +from sphinx.util.docutils import SphinxDirective + + +def git_shortlog() -> str: + """Return git-shortlog output as a string. + + Returns + ------- + str + Git-shortlog output. + """ + return subprocess.check_output(['git', 'shortlog', '-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 = get_authors() + new_content = StringList(authors, source="") + + node = nodes.Element() + nested_parse_with_titles(self.state, new_content, node) + + return node.children + +def setup(app: Sphinx) -> Dict[str, Any]: + app.add_directive(name="git-shortlog-authors", cls=AuthorsDirective) + return {'parallel_read_safe': True} diff --git a/docs/credits.rst b/docs/credits.rst new file mode 100644 index 0000000..f8cfc84 --- /dev/null +++ b/docs/credits.rst @@ -0,0 +1,4 @@ +Authors +======= + +.. git-shortlog-authors:: diff --git a/docs/index.rst b/docs/index.rst index 547901a..b2a4c51 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -1,6 +1,17 @@ .. include:: ../README.md :parser: myst_parser.sphinx_ +.. toctree:: + :hidden: + + Summary + + +.. toctree:: + :titlesonly: + + credits + ------------------ From f2e83c5dd730607f6d872c0c783c1121019538ce Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Wed, 10 Aug 2022 23:31:17 -0400 Subject: [PATCH 02/32] fix typo --- deepmodeling_sphinx/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deepmodeling_sphinx/__init__.py b/deepmodeling_sphinx/__init__.py index 974dd6b..1fe10e2 100644 --- a/deepmodeling_sphinx/__init__.py +++ b/deepmodeling_sphinx/__init__.py @@ -1,8 +1,8 @@ from typing import Any, Dict from sphinx.application import Sphinx -from .inject import setup_inject -from .authors import setup_authors +from .inject import setup as setup_inject +from .authors import setup as setup_authors def setup(app: Sphinx) -> Dict[str, Any]: setup_inject(app) From 5103c837e60e719e9c3d82ac7810fc2ed73719d2 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Wed, 10 Aug 2022 23:32:44 -0400 Subject: [PATCH 03/32] fix errors --- deepmodeling_sphinx/authors.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deepmodeling_sphinx/authors.py b/deepmodeling_sphinx/authors.py index c2d25bc..dbcdf07 100644 --- a/deepmodeling_sphinx/authors.py +++ b/deepmodeling_sphinx/authors.py @@ -43,7 +43,7 @@ class AuthorsDirective(SphinxDirective): def run(self): """Run directive.""" - authors = get_authors() + authors = list(get_authors()) new_content = StringList(authors, source="") node = nodes.Element() From e7878653557942d1ed77c356dcae1b29e07e7f4b Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Thu, 11 Aug 2022 00:04:43 -0400 Subject: [PATCH 04/32] fix errors --- deepmodeling_sphinx/authors.py | 10 +++------- docs/conf.py | 2 +- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/deepmodeling_sphinx/authors.py b/deepmodeling_sphinx/authors.py index dbcdf07..0f78677 100644 --- a/deepmodeling_sphinx/authors.py +++ b/deepmodeling_sphinx/authors.py @@ -43,13 +43,9 @@ class AuthorsDirective(SphinxDirective): def run(self): """Run directive.""" - authors = list(get_authors()) - new_content = StringList(authors, source="") - - node = nodes.Element() - nested_parse_with_titles(self.state, new_content, node) - - return node.children + 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) diff --git a/docs/conf.py b/docs/conf.py index 89c105e..e82aef1 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,6 +1,6 @@ from datetime import date -project = 'DeepModeling' +project = 'deepmodeling_sphinx' copyright = '2022-%d, DeepModeling' % date.today().year author = 'DeepModeling' From e101fe5689d1a2f8928479f7a94a9a6f692bceb3 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Thu, 11 Aug 2022 00:15:16 -0400 Subject: [PATCH 05/32] debug --- deepmodeling_sphinx/authors.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/deepmodeling_sphinx/authors.py b/deepmodeling_sphinx/authors.py index 0f78677..f5ee122 100644 --- a/deepmodeling_sphinx/authors.py +++ b/deepmodeling_sphinx/authors.py @@ -30,6 +30,7 @@ def get_authors() -> Iterator[str]: Author name. """ shortlog_text = git_shortlog() + print(shortlog_text) for line in shortlog_text.splitlines(): yield line.split('\t')[1] @@ -44,6 +45,7 @@ class AuthorsDirective(SphinxDirective): def run(self): """Run directive.""" authors = ["* " + author for author in get_authors()] + print(authors) self.state_machine.insert_input(authors, "") return [] From 6317c6344c5309d9b5c762db22321b9d2c1873a5 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Thu, 11 Aug 2022 00:20:06 -0400 Subject: [PATCH 06/32] debug --- deepmodeling_sphinx/authors.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/deepmodeling_sphinx/authors.py b/deepmodeling_sphinx/authors.py index f5ee122..1faead3 100644 --- a/deepmodeling_sphinx/authors.py +++ b/deepmodeling_sphinx/authors.py @@ -18,6 +18,8 @@ def git_shortlog() -> str: str Git-shortlog output. """ + print("git log", subprocess.check_output(['git', 'log']).decode('utf-8')) + print("git status", subprocess.check_output(['git', 'status']).decode('utf-8')) return subprocess.check_output(['git', 'shortlog', '-s']).decode('utf-8') From b5f4569144eb1a5d39f1b934f9999ecef6a2218c Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Thu, 11 Aug 2022 00:25:37 -0400 Subject: [PATCH 07/32] use git shortlog HEAD --- deepmodeling_sphinx/authors.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deepmodeling_sphinx/authors.py b/deepmodeling_sphinx/authors.py index 1faead3..671920c 100644 --- a/deepmodeling_sphinx/authors.py +++ b/deepmodeling_sphinx/authors.py @@ -20,7 +20,7 @@ def git_shortlog() -> str: """ print("git log", subprocess.check_output(['git', 'log']).decode('utf-8')) print("git status", subprocess.check_output(['git', 'status']).decode('utf-8')) - return subprocess.check_output(['git', 'shortlog', '-s']).decode('utf-8') + return subprocess.check_output(['git', 'shortlog', 'HEAD', '-s']).decode('utf-8') def get_authors() -> Iterator[str]: From a9c765f5174360bec9616aa5b908f5c97812ad17 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Thu, 11 Aug 2022 00:36:31 -0400 Subject: [PATCH 08/32] add docs --- README.md | 11 +++++++++++ docs/index.rst | 3 +++ 2 files changed, 14 insertions(+) diff --git a/README.md b/README.md index af880cf..ca853ef 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,8 @@ 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 @@ -17,3 +19,12 @@ 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:: + +``` diff --git a/docs/index.rst b/docs/index.rst index b2a4c51..5692efc 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -1,6 +1,9 @@ .. include:: ../README.md :parser: myst_parser.sphinx_ +Others +------ + .. toctree:: :hidden: From f851870ca3533bed34c1085a02d9bf097ad9b531 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Thu, 11 Aug 2022 00:58:43 -0400 Subject: [PATCH 09/32] git fetch if unshallow --- deepmodeling_sphinx/authors.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/deepmodeling_sphinx/authors.py b/deepmodeling_sphinx/authors.py index 671920c..e5e2c1b 100644 --- a/deepmodeling_sphinx/authors.py +++ b/deepmodeling_sphinx/authors.py @@ -1,5 +1,6 @@ """A directive to list all authors from git-shortlog.""" +import os import subprocess from typing import Any, Dict, Iterator @@ -18,6 +19,11 @@ def git_shortlog() -> str: str Git-shortlog output. """ + if os.environ.get("READTHEDOCS", None) == "True": + # check if it shallow clone + if subprocess.check_call(["git", "rev-parse", "--is-shallow-repository"]).decode('utf-8') == "true": + o = subprocess.check_call(["git", "fetch", "--unshallow"]) + print(o) print("git log", subprocess.check_output(['git', 'log']).decode('utf-8')) print("git status", subprocess.check_output(['git', 'status']).decode('utf-8')) return subprocess.check_output(['git', 'shortlog', 'HEAD', '-s']).decode('utf-8') From b2a3d897dc64b7327248fa74646ae67d62c3fb8a Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Thu, 11 Aug 2022 00:59:45 -0400 Subject: [PATCH 10/32] empty commit to debug shallow clone From 9dbaac5382ea446d87168e5225661e485f0823a8 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Thu, 11 Aug 2022 00:59:47 -0400 Subject: [PATCH 11/32] empty commit to debug shallow clone From e41bfc50f348960cfbf3b658044a55335eb92cca Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Thu, 11 Aug 2022 00:59:47 -0400 Subject: [PATCH 12/32] empty commit to debug shallow clone From 0f795d68adcc570d1aafe80918fb49c319aaabb2 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Thu, 11 Aug 2022 00:59:48 -0400 Subject: [PATCH 13/32] empty commit to debug shallow clone From 5fc51c501d05d32de4769f12b2cb34ebc62eac0f Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Thu, 11 Aug 2022 00:59:49 -0400 Subject: [PATCH 14/32] empty commit to debug shallow clone From d5d7eb016cb6a152b2f6e1d583586d559ffa3d7a Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Thu, 11 Aug 2022 00:59:49 -0400 Subject: [PATCH 15/32] empty commit to debug shallow clone From d87f65990c3d0489c7d59a523e60dfa9fb9be6bb Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Thu, 11 Aug 2022 00:59:50 -0400 Subject: [PATCH 16/32] empty commit to debug shallow clone From 0f087f26f1bf354d6111b0a1596bbbb56f47d74a Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Thu, 11 Aug 2022 00:59:50 -0400 Subject: [PATCH 17/32] empty commit to debug shallow clone From 3868ef2d1ebc66bc9abbb92cac0acaf9d9f81c05 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Thu, 11 Aug 2022 00:59:51 -0400 Subject: [PATCH 18/32] empty commit to debug shallow clone From 3b7da81a69bdc0771b24da4b9e6c2baae045e3ff Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Thu, 11 Aug 2022 00:59:51 -0400 Subject: [PATCH 19/32] empty commit to debug shallow clone From 13118847066e6e1066ae9726794a8f287899c959 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Thu, 11 Aug 2022 00:59:52 -0400 Subject: [PATCH 20/32] empty commit to debug shallow clone From 1e22fa128d7499221c56f91608509e53be74e2f5 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Thu, 11 Aug 2022 00:59:52 -0400 Subject: [PATCH 21/32] empty commit to debug shallow clone From ed6173f21c06eb2f1d2c297ac049a30e8a610686 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Thu, 11 Aug 2022 00:59:53 -0400 Subject: [PATCH 22/32] empty commit to debug shallow clone From 2ca3d97fd29368e573e201c7fca4c8ab3a27d08a Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Thu, 11 Aug 2022 00:59:53 -0400 Subject: [PATCH 23/32] empty commit to debug shallow clone From 4a60d54b10fe09ea59a99965f60bb8b28ade66a4 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Thu, 11 Aug 2022 00:59:54 -0400 Subject: [PATCH 24/32] empty commit to debug shallow clone From 8d1bec046b91e03855c5bac24f1c39121ebf84eb Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Thu, 11 Aug 2022 00:59:54 -0400 Subject: [PATCH 25/32] empty commit to debug shallow clone From ad647a9d6f12b64bbeb668df9b76bcee36f43b37 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Thu, 11 Aug 2022 00:59:55 -0400 Subject: [PATCH 26/32] empty commit to debug shallow clone From 1a092a721d7b01d41c3ef47f7ddf6137e8ccf74e Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Thu, 11 Aug 2022 00:59:55 -0400 Subject: [PATCH 27/32] empty commit to debug shallow clone From 6f90969a8de1bc251688cbde985224d01df1f6ba Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Thu, 11 Aug 2022 00:59:56 -0400 Subject: [PATCH 28/32] empty commit to debug shallow clone From 4e057de541004084a818fffe3e8ac677eb83ed91 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Thu, 11 Aug 2022 00:59:56 -0400 Subject: [PATCH 29/32] empty commit to debug shallow clone From 60db64ed1f3d2885439236927988062cc7cb7078 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Thu, 11 Aug 2022 01:00:49 -0400 Subject: [PATCH 30/32] fix typo --- deepmodeling_sphinx/authors.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deepmodeling_sphinx/authors.py b/deepmodeling_sphinx/authors.py index e5e2c1b..ff3ffa5 100644 --- a/deepmodeling_sphinx/authors.py +++ b/deepmodeling_sphinx/authors.py @@ -21,8 +21,8 @@ def git_shortlog() -> str: """ if os.environ.get("READTHEDOCS", None) == "True": # check if it shallow clone - if subprocess.check_call(["git", "rev-parse", "--is-shallow-repository"]).decode('utf-8') == "true": - o = subprocess.check_call(["git", "fetch", "--unshallow"]) + if subprocess.check_output(["git", "rev-parse", "--is-shallow-repository"]).decode('utf-8') == "true": + o = subprocess.check_output(["git", "fetch", "--unshallow"]) print(o) print("git log", subprocess.check_output(['git', 'log']).decode('utf-8')) print("git status", subprocess.check_output(['git', 'status']).decode('utf-8')) From b94808c9c135d3e0dbec17d6d63595ade9d0c641 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Thu, 11 Aug 2022 01:02:51 -0400 Subject: [PATCH 31/32] debug output_git_rev_parse --- deepmodeling_sphinx/authors.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/deepmodeling_sphinx/authors.py b/deepmodeling_sphinx/authors.py index ff3ffa5..788c4aa 100644 --- a/deepmodeling_sphinx/authors.py +++ b/deepmodeling_sphinx/authors.py @@ -21,7 +21,9 @@ def git_shortlog() -> str: """ if os.environ.get("READTHEDOCS", None) == "True": # check if it shallow clone - if subprocess.check_output(["git", "rev-parse", "--is-shallow-repository"]).decode('utf-8') == "true": + output_git_rev_parse = subprocess.check_output(["git", "rev-parse", "--is-shallow-repository"]).decode('utf-8').strip() + print(output_git_rev_parse) + if output_git_rev_parse == "true": o = subprocess.check_output(["git", "fetch", "--unshallow"]) print(o) print("git log", subprocess.check_output(['git', 'log']).decode('utf-8')) From aba7c32357283e4378780cf12e8340c4e011b620 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Thu, 11 Aug 2022 01:14:33 -0400 Subject: [PATCH 32/32] remove debug lines --- deepmodeling_sphinx/authors.py | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/deepmodeling_sphinx/authors.py b/deepmodeling_sphinx/authors.py index 788c4aa..1d650d7 100644 --- a/deepmodeling_sphinx/authors.py +++ b/deepmodeling_sphinx/authors.py @@ -4,10 +4,7 @@ import subprocess from typing import Any, Dict, Iterator -from docutils import nodes -from docutils.statemachine import StringList from sphinx.application import Sphinx -from sphinx.util import nested_parse_with_titles from sphinx.util.docutils import SphinxDirective @@ -22,12 +19,9 @@ def git_shortlog() -> str: 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() - print(output_git_rev_parse) if output_git_rev_parse == "true": - o = subprocess.check_output(["git", "fetch", "--unshallow"]) - print(o) - print("git log", subprocess.check_output(['git', 'log']).decode('utf-8')) - print("git status", subprocess.check_output(['git', 'status']).decode('utf-8')) + # fetch full history + subprocess.check_output(["git", "fetch", "--unshallow"]) return subprocess.check_output(['git', 'shortlog', 'HEAD', '-s']).decode('utf-8') @@ -40,7 +34,6 @@ def get_authors() -> Iterator[str]: Author name. """ shortlog_text = git_shortlog() - print(shortlog_text) for line in shortlog_text.splitlines(): yield line.split('\t')[1] @@ -55,7 +48,6 @@ class AuthorsDirective(SphinxDirective): def run(self): """Run directive.""" authors = ["* " + author for author in get_authors()] - print(authors) self.state_machine.insert_input(authors, "") return []