-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better organization
- Loading branch information
Showing
12 changed files
with
255 additions
and
203 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
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,7 @@ | ||
The ``sphinx_github_style.utils.git`` submodule | ||
================================================ | ||
|
||
.. automodule:: sphinx_github_style.utils.git | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: |
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,7 @@ | ||
The ``sphinx_github_style.utils.linkcode`` submodule | ||
===================================================== | ||
|
||
.. automodule:: sphinx_github_style.utils.linkcode | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: |
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,7 @@ | ||
The ``sphinx_github_style.utils.sphinx`` submodule | ||
=================================================== | ||
|
||
.. automodule:: sphinx_github_style.utils.sphinx | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: |
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,17 @@ | ||
The ``sphinx_github_style.utils`` subpackage | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
.. automodule:: sphinx_github_style.utils | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
The ``sphinx_github_style.utils`` subpackage contains a variety of helper functions | ||
|
||
.. toctree:: | ||
:maxdepth: 3 | ||
:titlesonly: | ||
|
||
git | ||
linkcode | ||
sphinx |
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
Empty file.
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,55 @@ | ||
import subprocess | ||
from pathlib import Path | ||
from sphinx.errors import ExtensionError | ||
|
||
|
||
def get_head() -> str: | ||
"""Gets the most recent commit hash or tag | ||
:return: The SHA or tag name of the most recent commit, or "master" if the call to git fails. | ||
""" | ||
cmd = "git log -n1 --pretty=%H" | ||
try: | ||
# get most recent commit hash | ||
head = subprocess.check_output(cmd.split()).strip().decode('utf-8') | ||
|
||
# if head is a tag, use tag as reference | ||
cmd = "git describe --exact-match --tags " + head | ||
try: | ||
tag = subprocess.check_output(cmd.split(" ")).strip().decode('utf-8') | ||
return tag | ||
|
||
except subprocess.CalledProcessError: | ||
return head | ||
|
||
except subprocess.CalledProcessError: | ||
print("Failed to get head") # so no head? | ||
return "master" | ||
|
||
|
||
def get_last_tag() -> str: | ||
"""Get the most recent commit tag on the currently checked out branch | ||
:raises ExtensionError: if no tags exist on the branch | ||
""" | ||
try: | ||
cmd = "git describe --tags --abbrev=0" | ||
return subprocess.check_output(cmd.split(" ")).strip().decode('utf-8') | ||
|
||
except subprocess.CalledProcessError: | ||
raise ExtensionError("``sphinx-github-style``: no tags found on current branch") | ||
|
||
|
||
def get_repo_dir() -> Path: | ||
"""Returns the root directory of the repository | ||
:return: A Path object representing the working directory of the repository. | ||
""" | ||
try: | ||
cmd = "git rev-parse --show-toplevel" | ||
repo_dir = Path(subprocess.check_output(cmd.split(" ")).strip().decode('utf-8')) | ||
|
||
except subprocess.CalledProcessError as e: | ||
raise RuntimeError("Unable to determine the repository directory") from e | ||
|
||
return repo_dir |
Oops, something went wrong.