Gentoo Archives: gentoo-dev

From: Andrew Ammerlaan <andrewammerlaan@g.o>
To: gentoo-dev@l.g.o
Subject: [gentoo-dev] [PATCH 2/2] docs.eclass: support initializing git
Date: Thu, 10 Nov 2022 11:29:45
Message-Id: 6a53e521-0627-910c-01ec-d8869b9c7f35@gentoo.org
1 diff --git
2 a/dev-python/mkdocs-git-revision-date-localized-plugin/mkdocs-git-revision-date-localized-plugin-1.1.0.ebuild
3 b/dev-python/mkdocs-git-revision-date-localized-plugin/mkdocs-git-revision-date-localized-plugin-1.1.0.ebuild
4 index 38f0810143e..9c5d2c4bf0c 100644
5 ---
6 a/dev-python/mkdocs-git-revision-date-localized-plugin/mkdocs-git-revision-date-localized-plugin-1.1.0.ebuild
7 +++
8 b/dev-python/mkdocs-git-revision-date-localized-plugin/mkdocs-git-revision-date-localized-plugin-1.1.0.ebuild
9 @@ -13,6 +13,7 @@ DOCS_DEPEND="
10 dev-python/mkdocs-git-authors-plugin
11 dev-python/mkdocs-git-revision-date-localized-plugin
12 "
13 +DOCS_INITIALIZE_GIT=1
14
15 inherit distutils-r1 docs
16
17 @@ -39,20 +40,12 @@ BDEPEND="
18 dev-python/mkdocs-i18n[${PYTHON_USEDEP}]
19 dev-vcs/git
20 )
21 - doc? ( dev-vcs/git )
22 "
23
24 distutils_enable_tests pytest
25
26 python_prepare_all() {
27 - # mkdocs-git-revision-date-localized-plugin's tests need git repo
28 - if use test || use doc; then
29 - git init -q || die
30 - git config --global user.email "you@×××××××.com" || die
31 - git config --global user.name "Your Name" || die
32 - git add . || die
33 - git commit -qm 'init' || die
34 - fi
35 + use test && initialize_git_repo
36
37 distutils-r1_python_prepare_all
38 }
39
40
41 diff --git a/eclass/docs.eclass b/eclass/docs.eclass
42 index f7a82939a53..0bd5cedd93b 100644
43 --- a/eclass/docs.eclass
44 +++ b/eclass/docs.eclass
45 @@ -143,6 +143,15 @@ esac
46 #
47 # Defaults to Doxyfile for doxygen
48
49 +# @ECLASS_VARIABLE: DOCS_INITIALIZE_GIT
50 +# @DEFAULT_UNSET
51 +# @PRE_INHERIT
52 +# @DESCRIPTION:
53 +# Sometimes building the documentation will fail if this is not done
54 +# inside a git repository. If this variable is set the compile functions
55 +# will initialize a dummy git repository before compiling. A dependency
56 +# on dev-vcs/git is automatically added.
57 +
58 if [[ ! ${_DOCS} ]]; then
59
60 # For the python based DOCS_BUILDERS we need to inherit any python eclass
61 @@ -164,6 +173,26 @@ case ${DOCS_BUILDER} in
62 ;;
63 esac
64
65 +
66 +# @FUNCTION: initialize_git_repo
67 +# @DESCRIPTION:
68 +# Initializes a dummy git repository. This function is called by the
69 +# documentation compile functions if DOCS_INITIALIZE_GIT is set. It can
70 +# also be called manually.
71 +initialize_git_repo() {
72 + # Only initialize if we are not already in a git repository
73 + local git_is_initialized="$(git rev-parse --is-inside-work-tree 2>
74 /dev/null)"
75 + if [[ ! "${git_is_initialized}" ]]; then
76 + git init -q || die
77 + git config --global user.email "larry@g.o" || die
78 + git config --global user.name "Larry the Cow" || die
79 + git add . || die
80 + git commit -qm "init" || die
81 + git tag -a "${PV}" -m "${PN} version ${PV}" || die
82 + fi
83 +}
84 +
85 +
86 # @FUNCTION: python_append_deps
87 # @INTERNAL
88 # @DESCRIPTION:
89 @@ -216,6 +245,8 @@ sphinx_compile() {
90 : ${DOCS_DIR:="${S}"}
91 : ${DOCS_OUTDIR:="${S}/_build/html/sphinx"}
92
93 + [[ ${DOCS_INITIALIZE_GIT} ]] && initialize_git_repo
94 +
95 local confpy=${DOCS_DIR}/conf.py
96 [[ -f ${confpy} ]] ||
97 die "${FUNCNAME}: ${confpy} not found, DOCS_DIR=${DOCS_DIR} call wrong"
98 @@ -277,6 +308,8 @@ mkdocs_compile() {
99 : ${DOCS_DIR:="${S}"}
100 : ${DOCS_OUTDIR:="${S}/_build/html/mkdocs"}
101
102 + [[ ${DOCS_INITIALIZE_GIT} ]] && initialize_git_repo
103 +
104 local mkdocsyml=${DOCS_DIR}/mkdocs.yml
105 [[ -f ${mkdocsyml} ]] ||
106 die "${FUNCNAME}: ${mkdocsyml} not found, DOCS_DIR=${DOCS_DIR} wrong"
107 @@ -320,6 +353,8 @@ doxygen_compile() {
108 : ${DOCS_DIR:="${S}"}
109 : ${DOCS_OUTDIR:="${S}/_build/html/doxygen"}
110
111 + [[ ${DOCS_INITIALIZE_GIT} ]] && initialize_git_repo
112 +
113 local doxyfile=${DOCS_DIR}/${DOCS_CONFIG_NAME}
114 [[ -f ${doxyfile} ]] ||
115 die "${FUNCNAME}: ${doxyfile} not found, DOCS_DIR=${DOCS_DIR} or
116 DOCS_CONFIG_NAME=${DOCS_CONFIG_NAME} wrong"
117 @@ -388,6 +423,8 @@ case ${DOCS_BUILDER} in
118 ;;
119 esac
120
121 +[[ ${DOCS_INITIALIZE_GIT} ]] && DOCS_DEPEND+=" dev-vcs/git "
122 +
123 if [[ ${EAPI} != 6 ]]; then
124 BDEPEND+=" doc? ( ${DOCS_DEPEND} )"
125 else