From 57e1e31433d374ef968c98c39243377e8ff02c60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Baranx=20=28bar=29?= Date: Wed, 24 Nov 2021 09:44:48 +0000 Subject: [PATCH] [FIX] conf.py: check odoo_dir is a real Odoo sources dir In `conf.py`, we try to find a Odoo sources folder among `odoo` and `../odoo` directories without really checking that they really are Odoo sources folders, leading to doc generation error if it's not the case. So, to improve that, this commit checks that the selected Odoo sources folder contains `odoo-bin`. While we're at it, the logging is also improved to always display the matching odoo sources' folder and version. closes odoo/documentation#1340 X-original-commit: f72e557f2cc8b624798f8590f458db8cdcc32a41 Signed-off-by: Antoine Vandevenne (anv) Co-authored-by: Antoine Vandevenne --- conf.py | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/conf.py b/conf.py index 296e98a76..8143c5835 100644 --- a/conf.py +++ b/conf.py @@ -58,39 +58,44 @@ extension_dir = Path('extensions') sys.path.insert(0, str(extension_dir.absolute())) # Search for the directory of odoo sources to know whether autodoc should be used on the dev doc -odoo_dir = Path('odoo') +odoo_sources_candidate_dirs = (Path('odoo'), Path('../odoo')) +odoo_sources_dirs = [ + d for d in odoo_sources_candidate_dirs if d.is_dir() and (d / 'odoo-bin').exists() +] odoo_dir_in_path = False -if not odoo_dir.is_dir(): - parent_odoo_dir = Path('../odoo') - if parent_odoo_dir.is_dir(): - _logger.info('Using parent dir to find odoo sources') - odoo_dir = parent_odoo_dir -if not odoo_dir.is_dir(): + +if not odoo_sources_dirs: _logger.warning( - f"Could not find Odoo sources directory at {odoo_dir.absolute()}.\n" - f"The 'Developer' documentation will be built but autodoc directives will be skipped.\n" - f"In order to fully build the 'Developer' documentation, clone the repository with " - f"`git clone https://github.com/odoo/odoo` or create a symbolic link." + "Could not find Odoo sources directory in neither of the following folders:\n" + "%(dir_list)s\n" + "The 'Developer' documentation will be built but autodoc directives will be skipped.\n" + "In order to fully build the 'Developer' documentation, clone the repository with " + "`git clone https://github.com/odoo/odoo` or create a symbolic link.", + {'dir_list': '\n'.join([f'\t- {d.resolve()}' for d in odoo_sources_candidate_dirs])}, ) else: - sys.path.insert(0, str(odoo_dir.absolute())) - if sys.version_info < (3, 7) and sys.version_info > (3, 6): - # running odoo needs python 3.7 min but monkey patch version_info to be - # able to build the doc in python 3.6 + odoo_dir = odoo_sources_dirs[0].resolve() + sys.path.insert(0, str(odoo_dir)) + if (3, 6) < sys.version_info < (3, 7): + # Running odoo needs python 3.7 min but monkey patch version_info to be compatible with 3.6 sys.version_info = (3, 7, 0) from odoo import release as odoo_release # Don't collide with Sphinx's 'release' config option odoo_version = odoo_release.version.replace('~', '-') \ if 'alpha' not in odoo_release.version else 'master' if release != odoo_version: _logger.warning( - f"Found Odoo sources directory but with version '{odoo_version}' incompatible with " - f"documentation version '{version}'.\n" - f"The 'Developer' documentation will be built but autodoc directives will be skipped.\n" - f"In order to fully build the 'Developer' documentation, checkout the matching branch " - f"with `cd odoo && git checkout {version}`." + "Found Odoo sources in %(directory)s but with version '%(odoo_version)s' incompatible " + "with documentation version '%(doc_version)s'.\n" + "The 'Developer' documentation will be built but autodoc directives will be skipped.\n" + "In order to fully build the 'Developer' documentation, checkout the matching branch" + " with `cd odoo && git checkout %(doc_version)s`.", + {'directory': odoo_dir, 'odoo_version': odoo_version, 'doc_version': version}, ) else: - _logger.info(f"Found Odoo sources directory matching documentation version {release}.") + _logger.info( + "Found Odoo sources in %(directory)s matching documentation version '%(version)s'.", + {'directory': odoo_dir, 'version': release}, + ) odoo_dir_in_path = True # The Sphinx extensions to use, as module names.