-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbdx_r.sh
More file actions
executable file
·67 lines (53 loc) · 1.94 KB
/
bdx_r.sh
File metadata and controls
executable file
·67 lines (53 loc) · 1.94 KB
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
#!/bin/bash
set -e # Exit on error
set -u # Treat unset variables as errors
# Get source directory
export BDX_R_DOC_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
# Extract the Python executable
extract_python_exe() {
local python_exe=""
# Check if using Conda
if [[ -n "${CONDA_PREFIX:-}" ]]; then
python_exe="${CONDA_PREFIX}/bin/python"
fi
# Fallback to system Python if Conda Python not found
if [[ -z "${python_exe}" || ! -f "${python_exe}" ]]; then
if command -v python3 &> /dev/null; then
python_exe="$(which python3)"
elif command -v python &> /dev/null; then
python_exe="$(which python)"
fi
fi
# Ensure a valid Python executable is found
if [[ -z "${python_exe}" || ! -f "${python_exe}" ]]; then
echo -e "[ERROR] Unable to find a valid Python executable." >&2
echo -e "\tPossible reasons:\n\t1. Conda environment is not activated.\n\t2. Python is not installed.\n\t3. Only 'python3' is available but not 'python'." >&2
exit 1
fi
# Return the result
echo "${python_exe}"
}
echo "[INFO] Building documentation..."
# Retrieve the Python executable
python_exe=$(extract_python_exe)
echo "${python_exe}"
# # Ensure documentation directory exists
if [ ! -d "${BDX_R_DOC_PATH}/docs" ]; then
echo "[ERROR] Documentation directory not found: ${BDX_R_DOC_PATH}/docs" >&2
exit 1
fi
# # Install pip packages
cd "${BDX_R_DOC_PATH}/docs"
${python_exe} -m pip install -r requirements.txt > /dev/null
# # Build the documentation
${python_exe} -m sphinx -b html -d _build/doctrees . _build/current
# # Open the documentation in the default browser
echo -e "[INFO] To open documentation, run:"
echo -e "\n\t\txdg-open $(pwd)/_build/current/index.html\n"
if [[ "$OSTYPE" == "darwin"* ]]; then
open "$(pwd)/_build/current/index.html"
else
xdg-open "$(pwd)/_build/current/index.html"
fi
# # Exit neatly
cd - > /dev/null