summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 0fa692ca3279920cf62bb43588a198d6c1b51187 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# Contributor: Marcell Meszaros < marcell.meszaros AT runbox.eu >
# Contributor: moormaster < user on aur.archlinux.org >
# Contributor: juliosueiras <juliosueiras [at] gmail [dot] com>
# Contributor: dmrz < user on aur.archlinux.org >

_reponame='ansible'
pkgname="${_reponame}-docs-git"
pkgdesc='HTML documentation of Ansible'
pkgver=2.11.0b4.r1444.g3fa377387e0
pkgrel=1
epoch=1
arch=('any')
url="https://github.com/${_reponame}/${_reponame}"
license=('GPL3')

makedepends=(
    'git'
    'python'
)

# # Not using repo or AUR packages because the needed versions can change rapidly
# # or be too new or too old compared to the versions provided there.
# makedepends+=(
#     'python-aiofiles'
#     'python-aiohttp'
#     'python-aiosignal'
#     'python-async-timeout'
#     'python-attrs'
#     'python-babel'
#     'python-certifi'
#     'python-charset-normalizer'
#     'python-click'
#     'python-frozenlist'
#     'python-imagesize'
#     'python-markupsafe'
#     'python-multidict'
#     'python-packaging'
#     'python-pydantic'
#     'python-pygments'
#     'python-pyparsing'
#     'python-pytz'
#     'python-requests'
#     'python-semantic-version'
#     'python-sh'
#     'python-snowballstemmer'
#     'python-sphinx'
#     'python-sphinx_rtd_theme'
#     'python-sphinxcontrib-applehelp'
#     'python-sphinxcontrib-devhelp'
#     'python-sphinxcontrib-htmlhelp'
#     'python-sphinxcontrib-jsmath'
#     'python-sphinxcontrib-qthelp'
#     'python-sphinxcontrib-serializinghtml'
#     'python-straight.plugin'
#     'python-typing_extensions'
#     'python-urllib3'
#     'python-wheel'
#     'python-yaml'
#     'python-yarl'
# )
# # makedepends+=('rstcheck') # Repo version too new, also buggy (lacks mandatory depends 'types-docutils')
# 
# # The following "hidden" makedepends are not in Arch repos as of this commit,
# # so I'm adding them here as a reference.
# _makedepends_nonrepo=(
#     'python-alabaster'
#     'python-ansible-pygments'
#     'python-antsibull-core'
#     'python-antsibull-docs'
#     'python-asyncio-pool'
#     'python-jinja2'
#     'python-perky'
#     'python-sphinx-ansible-theme'
#     'python-sphinx-notfound-page'
#     'python-sphinx-intl'
#     'python-twiggy'
# )
# # Exposing the missing or AUR-only makedepends as optdepends. If they are present at
# # build-time, they will be used instead of letting pip download them from PyPI.
# optdepends=(
#     "${_makedepends_nonrepo[@]/%/: use this installed package during (the next) build}"
# )

provides=("${pkgname%-git}=${pkgver}")
options=('!strip')
source=("git+${url}.git")
b2sums=('SKIP')
_py_venv_dir=("venv-${pkgname%-git}")

pkgver() {
    cd "${_reponame}"

    # Generate git tag based version. Count only proper (v)#.#* [#=number] tags.
    local _gitversion=$(git describe --long --tags --match '[v0-9][0-9.][0-9.]*' | sed -e 's|^v||' | tr '[:upper:]' '[:lower:]') 

    # Format git-based version for pkgver
    # Expected format: e.g. 2.11.0b4.r1444.g3fa377387e0
    echo "${_gitversion}" | sed \
        -e 's|^\([0-9][0-9.]*\)-\([a-zA-Z]\+\)|\1\2|' \
        -e 's|\([0-9]\+-g\)|r\1|' \
        -e 's|-|.|g'
}

prepare() {
    cd "${_reponame}"

    echo "Setting up Python venv dir: ${srcdir}/${_py_venv_dir}"
    echo '# We need this because Arch and AUR are missing a lot of needed makedepends.'
    # Disabled venv option: --system-site-packages, because Arch/AUR packages likely mismatch
    # too much compared to the versions needed by build's actual requirements.
    python -m 'venv' \
        --upgrade-deps \
        "${srcdir}/${_py_venv_dir}"

    echo "Activating Python venv in dir: ${srcdir}/${_py_venv_dir}"
    source "${srcdir}/${_py_venv_dir}/bin/activate"

    echo "Installing Python modules missing from root to venv dir \"${_py_venv_dir}\"..."
    pip install wheel       # this needs to be installed first
    pip install \
        --compile \
        --require-virtualenv \
        --upgrade \
        --upgrade-strategy eager \
        --requirement 'docs/docsite/requirements.txt' \
        'types-docutils'    # seems it is not declared but needed

    echo "Deactivating Python venv in dir: ${srcdir}/${_py_venv_dir}"
    deactivate
}

build() {
    cd "${_reponame}"

    echo "Activating Python venv in dir: ${srcdir}/${_py_venv_dir}"
    source "${srcdir}/${_py_venv_dir}/bin/activate"

    local templates="${srcdir}/tmp"
    echo "Creating template stubs in ${templates}"
    mkdir -p ${templates}
    touch "${templates}/version_chooser.html"

    echo "Building ${pkgname%-git} from source..."
    local cleanup_flags="\
      -D templates_path=${templates}\
      -D html_context.version=${pkgver}\
      -D html_theme_options.display_version=1\
      -D html_theme_options.show_rtd_ethical_ads=0\
      -D html_theme_options.hubspot_id=''\
      -D html_theme_options.topbar_links=0\
      -D html_theme_options.satellite_tracking=0\
      -D html_theme_options.swift_id=''\
      -D html_theme_options.tag_manager_id=''\
    "
    make -C 'docs/docsite' 'all' O="${cleanup_flags}" CPUS=1

    echo "Deactivating Python venv in dir: ${srcdir}/${_py_venv_dir}"
    deactivate
}

package() {
    install -dm 755 "${pkgdir}/usr/share/doc/${pkgname}/html"
    cp --recursive --dereference --target-directory="${pkgdir}/usr/share/doc/${pkgname}" "${srcdir}/${_reponame}/docs/docsite/_build/html" 
}