Skip to content

Commit fcb624c

Browse files
authored
build: update generate-docs to support monorepo (#289)
* build: update generate-docs to support monorepo * build: update Dockerfile build: update jinja version build: update Docker image to py310 build: specify Sphinx version in the package installtion build: use py3.9 instead build: update setup.py * build: fix typo * build: update to concatenate string var
1 parent a1005f2 commit fcb624c

File tree

6 files changed

+125
-24
lines changed

6 files changed

+125
-24
lines changed

packages/gcp-sphinx-docfx-yaml/.kokoro/docker/docs/Dockerfile

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ RUN apt-get update \
4040
libssl-dev \
4141
libsqlite3-dev \
4242
portaudio19-dev \
43-
python3 \
44-
python3-pip \
4543
redis-server \
4644
software-properties-common \
4745
ssh \
@@ -61,6 +59,50 @@ RUN apt-get update \
6159
&& rm -rf /var/lib/apt/lists/* \
6260
&& rm -f /var/cache/apt/archives/*.deb
6361

62+
COPY fetch_gpg_keys.sh /tmp
63+
# Install the desired versions of Python.
64+
RUN set -ex \
65+
&& export GNUPGHOME="$(mktemp -d)" \
66+
&& echo "disable-ipv6" >> "${GNUPGHOME}/dirmngr.conf" \
67+
&& /tmp/fetch_gpg_keys.sh \
68+
&& for PYTHON_VERSION in 3.9.13; do \
69+
wget --no-check-certificate -O python-${PYTHON_VERSION}.tar.xz "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" \
70+
&& wget --no-check-certificate -O python-${PYTHON_VERSION}.tar.xz.asc "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" \
71+
&& gpg --batch --verify python-${PYTHON_VERSION}.tar.xz.asc python-${PYTHON_VERSION}.tar.xz \
72+
&& rm -r python-${PYTHON_VERSION}.tar.xz.asc \
73+
&& mkdir -p /usr/src/python-${PYTHON_VERSION} \
74+
&& tar -xJC /usr/src/python-${PYTHON_VERSION} --strip-components=1 -f python-${PYTHON_VERSION}.tar.xz \
75+
&& rm python-${PYTHON_VERSION}.tar.xz \
76+
&& cd /usr/src/python-${PYTHON_VERSION} \
77+
&& ./configure \
78+
--enable-shared \
79+
# This works only on Python 2.7 and throws a warning on every other
80+
# version, but seems otherwise harmless.
81+
--enable-unicode=ucs4 \
82+
--with-system-ffi \
83+
--without-ensurepip \
84+
&& make -j$(nproc) \
85+
&& make install \
86+
&& ldconfig \
87+
; done \
88+
&& rm -rf "${GNUPGHOME}" \
89+
&& rm -rf /usr/src/python* \
90+
&& rm -rf ~/.cache/
91+
92+
# Install pip on Python 3.9 only.
93+
# If the environment variable is called "PIP_VERSION", pip explodes with
94+
# "ValueError: invalid truth value '<VERSION>'"
95+
ENV PYTHON_PIP_VERSION 23.0
96+
RUN wget --no-check-certificate -O /tmp/get-pip.py 'https://bootstrap.pypa.io/get-pip.py' \
97+
&& python3.9 /tmp/get-pip.py "pip==$PYTHON_PIP_VERSION" \
98+
# we use "--force-reinstall" for the case where the version of pip we're trying to install is the same as the version bundled with Python
99+
# ("Requirement already up-to-date: pip==8.1.2 in /usr/local/lib/python3.10/site-packages")
100+
# https://github.com/docker-library/python/pull/143#issuecomment-241032683
101+
&& pip3 install --no-cache-dir --upgrade --force-reinstall "pip==$PYTHON_PIP_VERSION" \
102+
# then we use "pip list" to ensure we don't have more than one pip version installed
103+
# https://github.com/docker-library/python/pull/100
104+
&& [ "$(pip list |tac|tac| awk -F '[ ()]+' '$1 == "pip" { print $2; exit }')" = "$PYTHON_PIP_VERSION" ]
105+
64106
# Install Google Cloud SDK
65107
RUN echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] http://packages.cloud.google.com/apt cloud-sdk main" | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list && curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key --keyring /usr/share/keyrings/cloud.google.gpg add - && apt-get update -y && apt-get install google-cloud-sdk -y
66108

packages/gcp-sphinx-docfx-yaml/.kokoro/docker/docs/fetch_gpg_keys.sh

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,25 @@
1515

1616
# A script to fetch gpg keys with retry.
1717
# Avoid jinja parsing the file.
18-
#
18+
#
1919

2020
function retry {
2121
if [[ "${#}" -le 1 ]]; then
22-
echo "Usage: ${0} retry_count commands.."
23-
exit 1
22+
echo "Usage: ${0} retry_count commands.."
23+
exit 1
2424
fi
2525
local retries=${1}
2626
local command="${@:2}"
2727
until [[ "${retries}" -le 0 ]]; do
28-
$command && return 0
29-
if [[ $? -ne 0 ]]; then
30-
echo "command failed, retrying"
31-
((retries--))
32-
fi
28+
$command && return 0
29+
if [[ $? -ne 0 ]]; then
30+
echo "command failed, retrying"
31+
((retries--))
32+
fi
3333
done
3434
return 1
3535
}
3636

37-
# 3.6.9, 3.7.5 (Ned Deily)
38-
retry 3 gpg --keyserver ha.pool.sks-keyservers.net --recv-keys \
39-
0D96DF4D4110E5C43FBFB17F2D347EA6AA65421D
40-
41-
# 3.8.0 (Łukasz Langa)
42-
retry 3 gpg --keyserver ha.pool.sks-keyservers.net --recv-keys \
37+
# 3.8.0, 3.9.0 (Łukasz Langa)
38+
retry 3 gpg --keyserver keyserver.ubuntu.com --recv-keys \
4339
E3FF2839C048B25C084DEBE9B26995E310250568
44-
45-
#

packages/gcp-sphinx-docfx-yaml/.kokoro/generate-docs.sh

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ python3 -m pip install -e .
3636
python_bucket_items=$(gsutil ls "gs://docs-staging-v2/docfx-python*")
3737
# Store empty tarballs that did not produce any content to check later.
3838
empty_packages=""
39+
# Store monorepo packages to process later
40+
monorepo_packages=""
3941
# Retrieve unique repositories to regenerate the YAML with.
4042
for package in $(echo "${python_bucket_items}" | cut -d "-" -f 5- | rev | cut -d "-" -f 2- | rev | uniq); do
4143

@@ -55,6 +57,15 @@ for package in $(echo "${python_bucket_items}" | cut -d "-" -f 5- | rev | cut -d
5557
tar -zxvf ${tarball}
5658
repo=$(cat docs.metadata | grep "github_repository:" | cut -d "\"" -f 2 | cut -d "/" -f 2)
5759

60+
# If the pacakage is part of the monorepo, we'll process this later.
61+
if [[ "${repo}" == "google-cloud-python" ]]; then
62+
# Add an extra whitespace at the end to be used as a natural separator.
63+
monorepo_packages+="$(cat docs.metadata | grep "distribution_name" | cut -d "\"" -f 2) "
64+
cd ..
65+
rm -rf ${tarball}
66+
continue
67+
fi
68+
5869
# Clean up the tarball content.
5970
cd ..
6071
rm -rf ${tarball}
@@ -152,7 +163,57 @@ for package in $(echo "${python_bucket_items}" | cut -d "-" -f 5- | rev | cut -d
152163
rm "noxfile.py"
153164
done
154165

155-
if [ ! ${empty_packages} ]; then
166+
# Build documentation for monorepo packages
167+
if [ -n "${monorepo_packages}" ]; then
168+
echo "Processing monorepo packages"
169+
git clone "https://github.com/googleapis/google-cloud-python.git"
170+
cd google-cloud-python/packages
171+
172+
# TODO (https://github.com/googleapis/sphinx-docfx-yaml/issues/287): support
173+
# multi-version build for the monorepo.
174+
for monorepo_package in $(echo ${monorepo_packages}); do
175+
cd ${monorepo_package}
176+
177+
# Test running with the plugin version locally.
178+
if [[ "${TEST_PLUGIN}" == "true" ]]; then
179+
# --no-use-pep517 is required for django-spanner install issue: see https://github.com/pypa/pip/issues/7953
180+
python3 -m pip install --user --no-use-pep517 -e .[all]
181+
sphinx-build -T -N -D extensions=sphinx.ext.autodoc,sphinx.ext.autosummary,docfx_yaml.extension,sphinx.ext.intersphinx,sphinx.ext.coverage,sphinx.ext.napoleon,sphinx.ext.todo,sphinx.ext.viewcode,recommonmark -b html -d docs/_build/doctrees/ docs/ docs/_build/html/
182+
continue
183+
fi
184+
185+
# Build YAML tarballs for Cloud-RAD.
186+
nox -s docfx
187+
188+
# Check that documentation is produced. If not, log and continue.
189+
if [ ! "$(ls docs/_build/html/docfx_yaml/)" ]; then
190+
empty_packages="${monorepo_package} ${empty_packages}"
191+
continue
192+
fi
193+
194+
python3 -m docuploader create-metadata \
195+
--name=$(jq --raw-output '.name // empty' .repo-metadata.json) \
196+
--version=$(python3 setup.py --version) \
197+
--language=$(jq --raw-output '.language // empty' .repo-metadata.json) \
198+
--distribution-name=$(python3 setup.py --name) \
199+
--product-page=$(jq --raw-output '.product_documentation // empty' .repo-metadata.json) \
200+
--github-repository=$(jq --raw-output '.repo // empty' .repo-metadata.json) \
201+
--issue-tracker=$(jq --raw-output '.issue_tracker // empty' .repo-metadata.json)
202+
203+
cat docs.metadata
204+
205+
# upload docs
206+
python3 -m docuploader upload docs/_build/html/docfx_yaml --metadata-file docs.metadata --destination-prefix docfx --staging-bucket "${V2_STAGING_BUCKET}"
207+
208+
# Clean up the package to make room.
209+
cd ../
210+
rm -rf ${monorepo_package}
211+
done
212+
cd ../../
213+
rm -rf google-cloud-python
214+
fi
215+
216+
if [ ! "${empty_packages}" ]; then
156217
exit
157218
fi
158219

packages/gcp-sphinx-docfx-yaml/.kokoro/requirements.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ google-cloud-aiplatform[prediction]
66
googleapis-common-protos==1.58.0 # pinned for conflict in range specifier.
77
grpcio-status==1.48.2 # must be pinned due to protobuf compatibility.
88
ipython
9+
jinja2<=3.0.3
910

1011
# General installations.
1112
gcp-docuploader

packages/gcp-sphinx-docfx-yaml/.kokoro/requirements.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -430,10 +430,12 @@ jeepney==0.8.0 \
430430
# via
431431
# keyring
432432
# secretstorage
433-
jinja2==3.1.2 \
434-
--hash=sha256:31351a702a408a9e7595a8fc6150fc3f43bb6bf7e319770cbc0db9df9437e852 \
435-
--hash=sha256:6088930bfe239f0e6710546ab9c19c9ef35e29792895fed6e6e31a023a182a61
436-
# via gcp-releasetool
433+
jinja2==3.0.3 \
434+
--hash=sha256:077ce6014f7b40d03b47d1f1ca4b0fc8328a692bd284016f806ed0eaca390ad8 \
435+
--hash=sha256:611bb273cd68f3b993fabdc4064fc858c5b47a973cb5aa7999ec1ba405c87cd7
436+
# via
437+
# -r requirements.in
438+
# gcp-releasetool
437439
keyring==23.9.0 \
438440
--hash=sha256:4c32a31174faaee48f43a7e2c7e9c3216ec5e95acf22a2bebfb4a1d05056ee44 \
439441
--hash=sha256:98f060ec95ada2ab910c195a2d4317be6ef87936a766b239c46aa3c7aac4f0db

packages/gcp-sphinx-docfx-yaml/setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
'black',
2323
'gcp-docuploader',
2424
'PyYAML',
25-
'sphinx',
25+
'recommonmark',
26+
'sphinx==4.5.0',
2627
'sphinx-markdown-builder',
2728
'sphinxcontrib.napoleon',
2829
'unidecode',

0 commit comments

Comments
 (0)