public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] [PATCH 2/2] docs.eclass: support initializing git
@ 2022-11-10 11:29 Andrew Ammerlaan
  0 siblings, 0 replies; only message in thread
From: Andrew Ammerlaan @ 2022-11-10 11:29 UTC (permalink / raw
  To: gentoo-dev

diff --git 
a/dev-python/mkdocs-git-revision-date-localized-plugin/mkdocs-git-revision-date-localized-plugin-1.1.0.ebuild 
b/dev-python/mkdocs-git-revision-date-localized-plugin/mkdocs-git-revision-date-localized-plugin-1.1.0.ebuild
index 38f0810143e..9c5d2c4bf0c 100644
--- 
a/dev-python/mkdocs-git-revision-date-localized-plugin/mkdocs-git-revision-date-localized-plugin-1.1.0.ebuild
+++ 
b/dev-python/mkdocs-git-revision-date-localized-plugin/mkdocs-git-revision-date-localized-plugin-1.1.0.ebuild
@@ -13,6 +13,7 @@ DOCS_DEPEND="
  	dev-python/mkdocs-git-authors-plugin
  	dev-python/mkdocs-git-revision-date-localized-plugin
  "
+DOCS_INITIALIZE_GIT=1

  inherit distutils-r1 docs

@@ -39,20 +40,12 @@ BDEPEND="
  		dev-python/mkdocs-i18n[${PYTHON_USEDEP}]
  		dev-vcs/git
  	)
-	doc? ( dev-vcs/git )
  "

  distutils_enable_tests pytest

  python_prepare_all() {
-	# mkdocs-git-revision-date-localized-plugin's tests need git repo
-	if use test || use doc; then
-		git init -q || die
-		git config --global user.email "you@example.com" || die
-		git config --global user.name "Your Name" || die
-		git add . || die
-		git commit -qm 'init' || die
-	fi
+	use test && initialize_git_repo

  	distutils-r1_python_prepare_all
  }


diff --git a/eclass/docs.eclass b/eclass/docs.eclass
index f7a82939a53..0bd5cedd93b 100644
--- a/eclass/docs.eclass
+++ b/eclass/docs.eclass
@@ -143,6 +143,15 @@ esac
  #
  # Defaults to Doxyfile for doxygen

+# @ECLASS_VARIABLE: DOCS_INITIALIZE_GIT
+# @DEFAULT_UNSET
+# @PRE_INHERIT
+# @DESCRIPTION:
+# Sometimes building the documentation will fail if this is not done
+# inside a git repository. If this variable is set the compile functions
+# will initialize a dummy git repository before compiling. A dependency
+# on dev-vcs/git is automatically added.
+
  if [[ ! ${_DOCS} ]]; then

  # For the python based DOCS_BUILDERS we need to inherit any python eclass
@@ -164,6 +173,26 @@ case ${DOCS_BUILDER} in
  		;;
  esac

+
+# @FUNCTION: initialize_git_repo
+# @DESCRIPTION:
+# Initializes a dummy git repository. This function is called by the
+# documentation compile functions if DOCS_INITIALIZE_GIT is set. It can
+# also be called manually.
+initialize_git_repo() {
+	# Only initialize if we are not already in a git repository
+	local git_is_initialized="$(git rev-parse --is-inside-work-tree 2> 
/dev/null)"
+	if [[ ! "${git_is_initialized}" ]]; then
+		git init -q || die
+		git config --global user.email "larry@gentoo.org" || die
+		git config --global user.name "Larry the Cow" || die
+		git add . || die
+		git commit -qm "init" || die
+		git tag -a "${PV}" -m "${PN} version ${PV}" || die
+	fi
+}
+
+
  # @FUNCTION: python_append_deps
  # @INTERNAL
  # @DESCRIPTION:
@@ -216,6 +245,8 @@ sphinx_compile() {
  	: ${DOCS_DIR:="${S}"}
  	: ${DOCS_OUTDIR:="${S}/_build/html/sphinx"}

+	[[ ${DOCS_INITIALIZE_GIT} ]] && initialize_git_repo
+
  	local confpy=${DOCS_DIR}/conf.py
  	[[ -f ${confpy} ]] ||
  		die "${FUNCNAME}: ${confpy} not found, DOCS_DIR=${DOCS_DIR} call wrong"
@@ -277,6 +308,8 @@ mkdocs_compile() {
  	: ${DOCS_DIR:="${S}"}
  	: ${DOCS_OUTDIR:="${S}/_build/html/mkdocs"}

+	[[ ${DOCS_INITIALIZE_GIT} ]] && initialize_git_repo
+
  	local mkdocsyml=${DOCS_DIR}/mkdocs.yml
  	[[ -f ${mkdocsyml} ]] ||
  		die "${FUNCNAME}: ${mkdocsyml} not found, DOCS_DIR=${DOCS_DIR} wrong"
@@ -320,6 +353,8 @@ doxygen_compile() {
  	: ${DOCS_DIR:="${S}"}
  	: ${DOCS_OUTDIR:="${S}/_build/html/doxygen"}

+	[[ ${DOCS_INITIALIZE_GIT} ]] && initialize_git_repo
+
  	local doxyfile=${DOCS_DIR}/${DOCS_CONFIG_NAME}
  	[[ -f ${doxyfile} ]] ||
  		die "${FUNCNAME}: ${doxyfile} not found, DOCS_DIR=${DOCS_DIR} or 
DOCS_CONFIG_NAME=${DOCS_CONFIG_NAME} wrong"
@@ -388,6 +423,8 @@ case ${DOCS_BUILDER} in
  		;;
  esac

+[[ ${DOCS_INITIALIZE_GIT} ]] && DOCS_DEPEND+=" dev-vcs/git "
+
  if [[ ${EAPI} != 6 ]]; then
  	BDEPEND+=" doc? ( ${DOCS_DEPEND} )"
  else


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2022-11-10 11:29 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-10 11:29 [gentoo-dev] [PATCH 2/2] docs.eclass: support initializing git Andrew Ammerlaan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox