Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
46 changes: 28 additions & 18 deletions sphinx_gitstamp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
import os
import sys

from sphinx import errors
from sphinx.util.logging import getLogger

__version__ = "0.4.0"

logger = getLogger(__name__)

# Gets the datestamp of the latest commit on the given file
# Converts the datestamp into something more readable
# Skips files whose datestamp we can't parse.
Expand Down Expand Up @@ -58,15 +60,18 @@ def page_context_handler(app, pagename, templatename, context, doctree):
)
except git.exc.GitCommandError:
# File doesn't exist or something else went wrong.
raise errors.ExtensionError(
"Can't fetch git history for %s.rst." % fullpagename
logger.warning(
"sphinx-gitstamp: Can't fetch git history for {:s}.rst.".format(pagename),
type="gitstamp",
subtype="file",
)
except ValueError:
# Datestamp can't be parsed.
app.info(
"%s: Can't parse datestamp () %s ) for gitstamp, output \
won't have last updated time."
% (pagename, updated)
logger.warning(
"sphinx-gitstamp: Can't parse datestamp ({:s}), output on {:s} won't have last updated"
"time.".format(updated, pagename),
type="gitstamp",
subtype="datestamp",
)
pass

Expand All @@ -79,23 +84,28 @@ def what_build_am_i(app):

try:
import git
except ImportError as e:
raise errors.ExtensionError(
f"""Unable to import gitpython. \
Required to generate html. You may need to run: pip install gitpython.

The error was: {e}
"""
except ImportError:
logger.warning(
"sphinx-gitstamp: gitpython not found. Please ensure it is installed.",
type="gitstamp",
subtype="dependency",
)
return

try:
global g
g = git.Git(".")
except BaseException:
app.info(sys.exc_info()[0])
app.warn(
"gitstamp extension enabled, but no git repository found. No \
git datestamps will be generated."
logger.info(
sys.exc_info()[0],
type="gitstamp",
subtype="info",
)
logger.warning(
"sphinx-gitstamp: No git repository found. No git datestamps will be"
"generated.",
type="gitstamp",
subtype="repo",
)
else:
app.connect("html-page-context", page_context_handler)
Expand Down
1 change: 1 addition & 0 deletions tests/test_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
confoverrides={"gitstamp_fmt": "%b %d, %Y"},
)
def test_simple(app, status, warning):
app.warningiserror = True
app.build()
assert "bar.html" in app.outdir.listdir()