From 248a2cdd6d9c2da0d69dedba9e01906f217211cd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr>
Date: Thu, 1 Dec 2022 10:07:35 +0100
Subject: [PATCH] refactor(doc): mkdocs2pdf.py: add variable for general build
 directory

refs #578
---
 mkdocs2pdf.py | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/mkdocs2pdf.py b/mkdocs2pdf.py
index a4f15b0dc..f66b301a9 100644
--- a/mkdocs2pdf.py
+++ b/mkdocs2pdf.py
@@ -20,13 +20,14 @@ import yaml
 import re
 import shutil
 
-baseDir = os.getcwd();
+baseDir = os.getcwd()
+buildDir = os.path.join(baseDir, 'build')
 latexSourceDir = os.path.join(baseDir, 'docs/latex')
-buildDir = os.path.join(baseDir, 'build/pdf_build')
+pdfBuildDir = os.path.join(buildDir, 'pdf_build')
 outputDir = os.path.join(baseDir, 'dist/assets/docs/pdf')
 
 latexModelDir = 'latex_models'
-modelDir = os.path.join(buildDir, latexModelDir)
+modelDir = os.path.join(pdfBuildDir, latexModelDir)
 
 mergedDocFilenamePrefix = 'cassiopee_doc_contents_'
 filenamePrefix = 'cassiopee_doc_'
@@ -128,7 +129,7 @@ def convertMdToTex(filePath):
 
 def getLatexModel():
     # Clone Git repository
-    os.chdir(buildDir)
+    os.chdir(pdfBuildDir)
     runCommand(
         'git clone {} {}'.format(latexModelRepository, latexModelDir)
     )
@@ -185,7 +186,7 @@ def buildPDF(lang):
     outputPdfFile = filenamePrefix + lang + '.pdf'
 
     # copy Cassiopée version LateX file
-    cvt = os.path.join( baseDir, 'build', 'cassiopee_version.tex')
+    cvt = os.path.join(buildDir, 'cassiopee_version.tex')
     shutil.copy(cvt, modelDir)
 
     os.system(
@@ -200,7 +201,7 @@ def buildPDF(lang):
 def buildDocForLang(lang):
 
     # Prepare temporary build directory
-    os.makedirs(buildDir, exist_ok=True)
+    os.makedirs(pdfBuildDir, exist_ok=True)
     # Prepare output directory
     os.makedirs(outputDir, exist_ok=True)
 
@@ -212,7 +213,7 @@ def buildDocForLang(lang):
     s = exploreAndMerge(dMkdocsYaml['docs_dir'], dMkdocsYaml['nav'])
     # Save the merged .md file
     mergedDocFilename = mergedDocFilenamePrefix + lang
-    mergedDocOutputPath = os.path.join(buildDir, mergedDocFilename)
+    mergedDocOutputPath = os.path.join(pdfBuildDir, mergedDocFilename)
     # remove internal links @TODO convert them to hyperref ?
     s = re.sub(r'\[([^/]+)\]\([^ ]+\.md\)', r'\1', s)
     with open('{}.md'.format(mergedDocOutputPath), 'w') as f:
@@ -229,7 +230,7 @@ def buildDocForLang(lang):
     buildPDF(lang)
 
     # Clean build dir
-    shutil.rmtree(buildDir)
+    shutil.rmtree(pdfBuildDir)
 
 
 if __name__ == '__main__':
-- 
GitLab