Pass tox context

Allow passing tox context via env var and content meta.
This makes certian contitional build steps easier for
users to maintain.

Change-Id: I578ac6e7ed758cee04f7e2985a14065ffc99177d
Signed-off-by: Ron Stone <ronald.stone@windriver.com>
This commit is contained in:
Ron Stone 2024-10-23 15:07:37 +00:00
parent 2d657c520f
commit e07f8a6be2
3 changed files with 102 additions and 1 deletions

View File

@ -10,6 +10,8 @@ confirmation () { message $GR$@$NC; }
warn () { message $OG$@$NC; }
error () { message $RED$0:$?: $@$NC; exit 1; }
declare meta_ver=":MM(.)mm:"
# Check for and exit if file dependancies are not met. Takes a list of full or
# relative paths.
check_file_deps () {
@ -17,6 +19,7 @@ check_file_deps () {
do
if [ ! -f "${filereq}" ] && [ ! -L "${filereq}" ]; then error "${filereq} not found. Quiting."; exit 1; fi
done
return 0
}
# Check for and exit if command dependancies are not met. Takes a list of
@ -111,4 +114,91 @@ check_abbr_dups () {
}
declare utils_loaded=1
# Return this product version
#
# Finds and echos out this-ver value from _this.txt
# Calling context is responsible for parsing major and
# minor numbers into vars (g_YY and g_MM by convention)
get_this_version() {
local this_file="_this.txt"
local ver_file=$(find doc* -name $this_file)
[[ ! -f ${ver_file} ]] && \
error "$this_file not found. Quiting."
local _ver
local regex_ver="\.\.\s+\|this-ver\|\s+replace::\s+([0-9]{2}\.[0-9]{2})\s*"
local _this=$(grep this-ver $ver_file)
if [[ "${_this}" =~ $regex_ver ]]
then
_ver="${BASH_REMATCH[1]}"
else
error "Can't find local product version"
fi
echo $_ver
}
# List hash of separator characters used in ":MM<char>mm:" style
# placeholders
#
# Takes path to the file to scan.
# Sets global hash 'spacers'. Note that BRE special characters will be escaped.
get_version_spacers() {
local _sep
check_file_deps $1 && \
local _f=$1
spacers=()
while read l; do
_sep=''
if [[ $l =~ ${meta_ver} ]]; then
[[ ${BASH_REMATCH[1]} == [\$\*\.\\\[\]] ]] && \
_sep="\\${BASH_REMATCH[1]}" || \
_sep="${BASH_REMATCH[1]}"
spacers["${_sep}"]=0
fi
done < $_f
}
# Replace ":MM<char>mm:" placeholders in a target file.
#
# Takes path to file to manipulate and overwrites on disk
# Returns 0 on success
# Note: global hash 'spacers' must be set; see get_version_spacers
replace_version_placeholders() {
check_file_deps $1 && \
local _f=$1
local _rs
for sp in "${!spacers[@]}"; do
[[ $sp == '^' ]] && _rs="" || _rs=$sp
sed -i "s/:MM${sp}mm:/${g_YY}$_rs${g_MM}/g" $_f
done
return 0
}
# Return the name of the current default branch
get_this_branch() {
local _regex_br="defaultbranch=(.*)\s*$"
local _config="$PWD/.gitreview"
if [[ $(cat $_config) =~ $_regex_br ]]; then
echo "${BASH_REMATCH[1]}"
else
error "$PWD is not a branch"
fi
}
declare utils_loaded=1

View File

@ -1,10 +1,20 @@
import sys
import os
from bs4 import BeautifulSoup
BUILD_CONTEXT=os.environ.get('DOCS_BUILD_CONTEXT')
def remove_column_from_tables(file_path):
with open(file_path, 'r', encoding='utf-8') as file:
soup = BeautifulSoup(file, 'lxml')
if BUILD_CONTEXT:
context_tag = soup.find('meta', attrs={'name': 'docs-build-context'})
if context_tag:
if context_tag.get('content') != BUILD_CONTEXT:
print("Not in", context_tag.get('content'), "- skipping", file_path)
return
# Find column to delete
column_tag = soup.find('meta', attrs={'name': 'remove-column-from-html-table'})
if column_tag:

View File

@ -10,6 +10,7 @@ setenv = VIRTUAL_ENV={envdir}
OS_STDERR_CAPTURE=1
OS_TEST_TIMEOUT=60
LC_ALL=C
DOCS_BUILD_CONTEXT=starlingx
deps = -r{toxinidir}/test-requirements.txt
[testenv:prebuild-docs]