# HG changeset patch
# User Vincent Hatakeyama <vincent.hatakeyama@xcg-consulting.fr>
# Date 1623835132 -7200
#      Wed Jun 16 11:18:52 2021 +0200
# Node ID 40f1da7486da3901dca45c8604b10c9940290387
# Parent  2d95ef77d13fd4c0a0cd7f964ac3d8705cbe1d52
📝 Fix issues with documentation generation (incompatibility with expand)

diff --git a/NEWS.rst b/NEWS.rst
--- a/NEWS.rst
+++ b/NEWS.rst
@@ -7,6 +7,8 @@
 
 Add install option to do_tests, allowing to override installed modules.
 
+Fix issues with documentation generation (incompatibility with expand)
+
 8.0.1
 -----
 
diff --git a/common b/common
--- a/common
+++ b/common
@@ -23,6 +23,7 @@
 OK="[${GREEN} OK${RESET}  ]"
 RED="${esc}[31m"
 KO="[${esc}[41m${esc}[37m KO  ${RESET}]"
+WHITE_BOLD="${esc}[1;37m"
 
 function read_configuration_key () {
     # Read a configuration key from any ini file
diff --git a/create_documentation b/create_documentation
--- a/create_documentation
+++ b/create_documentation
@@ -8,11 +8,10 @@
 #
 
 # Version 8.0.1
+here=$(dirname $0)
+source $here/common
 
-# assume we are called from the project home
-project_home=$PWD
-project_name_from_home=$(basename $project_home)
-project_name=${DOC_PROJECT_NAME:-${CI_PROJECT_NAME:-${DRONE_REPO_NAME:-$project_name_from_home}}}
+project_name=${DOC_PROJECT_NAME:-${CI_PROJECT_NAME:-${DRONE_REPO_NAME:-project_name}}}
 languages=(${LANGUAGES:-en})
 
 format=html
@@ -21,22 +20,27 @@
 module_error=0
 error=0
 
-# color stuff
-autoload colors && colors
-for COLOR in RED GREEN YELLOW BLUE MAGENTA CYAN BLACK WHITE; do
-    eval $COLOR='$fg_no_bold[${(L)COLOR}]'
-    eval BOLD_$COLOR='$fg_bold[${(L)COLOR}]'
-done
-eval RESET='$reset_color'
+typeset -a odoo_modules
+odoo_modules=("${(@s/ /)$(read_odoo_scripts_expandable_configuration_key modules " ")}")
 
 pushd $project_home
 
-if type "python3" > /dev/null;
-then
-    odoo_modules="$(python3 -B -c "import configparser ; c = configparser.ConfigParser() ; c.read('${project_home}/setup.cfg') ; print (c.has_option('odoo_scripts', 'modules') and ' '.join(c.get('odoo_scripts', 'modules').split()) or '')")"
-else
-    odoo_modules="$(python2 -B -c "import ConfigParser ; c = ConfigParser.SafeConfigParser() ; c.read('${project_home}/setup.cfg') ; print (c.has_option('odoo_scripts', 'modules') and ' '.join(c.get('odoo_scripts', 'modules').split()) or '')")"
-fi
+# set addons path
+typeset -a addons_path
+addons_path=()
+for module_path in $odoo_modules ;
+do
+    module_dir=$(dirname $module_path)
+    if (($addons_path[(Ie)$module_dir]));
+    then
+        # already in
+    else
+        addons_path+=($module_dir)
+    fi
+    unset module_dir
+done
+export ODOO_ADDONS_PATH=${(j:,:)addons_path}
+unset addons_path
 
 # search where to copy modules documentation
 for doc_dir in doc docs; do
@@ -47,11 +51,11 @@
 done
 
 # Generate all modules documentation
-for module_path in $(eval echo $odoo_modules) ;
+for module_path in $odoo_modules ;
 do
     if [[ -d "$module_path" ]] ; then
         echo ""
-        echo "${YELLOW}INFO${RESET}  - Documentation for ${BOLD_WHITE}$module_path${RESET}"
+        echo "${INFO} Documentation for ${BOLD_WHITE}$module_path${RESET}"
         pushd $module_path
         module=$(basename $module_path)
         has_doc=""
@@ -60,14 +64,14 @@
         elif [ -e ".hg" ]; then
             branch="$(hg identify --branch)"
         else
-            echo "${RED}WARN${RESET}  - Branch name not found"
+            echo "${WARN} Branch name not found"
             branch="default"
         fi
         for doc_dir in doc docs ; do
             if [[ -d $doc_dir && -e $doc_dir/Makefile ]]; then
-                echo "${YELLOW}INFO ${RESET} - Branch name: $branch"
+                echo "${INFO} Branch name: $branch"
                 has_doc=True
-                echo ${YELLOW}INFO ${RESET} - Makefile found in $module_path/$doc_dir
+                echo ${INFO} Makefile found in $module_path/$doc_dir
                 pushd $doc_dir
                 # TODO read languages value from Makefile (at least available ones)
                 for language in $languages ; do
@@ -78,15 +82,15 @@
                         mkdir -p $dest_dir
                         if [[ -d "_build/$format/$language" ]];
                         then
-                            echo "${YELLOW}INFO ${RESET} - found _build/$format/$language/, copying from there"
+                            echo "${INFO} found _build/$format/$language/, copying from there"
                             cp --archive --recursive "_build/$format/$language/." "$dest_dir"
                         else
-                            # this is only because some modules Makefile is not up to date
-                            echo "${YELLOW}INFO ${RESET} - no _build/$format/$language/ found, copying from _build/$format/"
+                            # this is only because some modules Makefile are not up to date
+                            echo "${INFO} no _build/$format/$language/ found, copying from _build/$format/"
                             cp --archive --recursive "_build/$format/." "$dest_dir"
                         fi
                     else
-                        echo ${RED}ERROR${RESET} - Documentation generation failed for $module_path/$doc_dir
+                        echo ${WARN} Documentation generation failed for $module_path/$doc_dir
                         ((module_error++))
                     fi
                 done
@@ -95,7 +99,7 @@
                 rsync --recursive --copy-links --perms --times --group --owner $doc_dir/ "$superproject_modules_doc/$module"
                 # generate autotodo for each module (to update pathes)
                 if [[ -e $doc_dir/autotodo.py ]] ; then
-                    echo "${YELLOW}INFO ${RESET} - running autotodo again from different path $superproject_modules_doc/$module for ${project_home}/${module_path}"
+                    echo "${INFO} running autotodo again from different path $superproject_modules_doc/$module for ${project_home}/${module_path}"
                     pushd "$superproject_modules_doc/$module"
                     ./autotodo.py $(realpath --relative-to="." "${project_home}/${module_path}") .py TODO,FIXME,XXX
                     popd
@@ -104,7 +108,7 @@
             fi
         done
         if [[ -z "$has_doc" ]] ; then
-            echo ${RED}WARN${RESET}  - Missing documentation for $module_path
+            echo ${WARN}  - Missing documentation for $module_path
         fi
         popd
     fi
@@ -112,7 +116,7 @@
 
 # Generate super project documentation
 echo ""
-echo "${YELLOW}INFO ${RESET} - ${WHITE_BOLD}Super project${RESET} documentation generation"
+echo "${INFO} ${WHITE_BOLD}Super project${RESET} documentation generation"
 
 # determine branch name
 if [ -n "$DRONE_BRANCH" ]; then
@@ -122,10 +126,10 @@
 elif [ -e ".hg" ]; then
     branch="$(hg id -b)"
 else
-    echo "${RED}WARN${RESET} - Super project branch name not found, using default"
+    echo "${WARN} Super project branch name not found, using default"
     branch="default"
 fi
-echo "${YELLOW}INFO ${RESET} - Super project branch name: $branch"
+echo "${INFO} Super project branch name: $branch"
 
 for doc_dir in doc docs; do
     if [[ -d "$doc_dir" ]] ; then
@@ -136,11 +140,11 @@
             make $format LANGUAGE=${language} BUILDDIR=_build SPHINXOPTS="-w _build/warnings.out"
             if [[ $? -eq 0 ]] ; then
                 dest_dir=$out_dir/$project_name/$language/$branch
-                echo "${YELLOW}INFO ${RESET} - Documentation generation done for $doc_dir (superproject), copy to $dest_dir"
+                echo "${INFO} Documentation generation done for $doc_dir (superproject), copy to $dest_dir"
                 mkdir -p $dest_dir
                 cp --recursive --archive _build/$format/$language/. $dest_dir
             else
-                echo "${RED}FATAL${RESET} - Documentation generation failed for $doc_dir (superproject)"
+                echo "${FATAL} Documentation generation failed for $doc_dir (superproject)"
                 ((error++))
             fi
         done
@@ -151,7 +155,7 @@
 popd
 
 if [[ $module_error -gt 0 ]]; then
-    echo "${RED}ERROR${RESET} - $module_error module(s) with errors"
+    echo "${WARN} $module_error module(s) with errors"
 fi
 # create a metrics file
 if [[ "$CI" = "true" ]]; then