Skip to content

Commit a4a5c9d

Browse files
committed
[IMP] conf.py: strip module path from upgrade utils
The full module path in upgrade utils docs causes confusion for users. See issues odoo/upgrade-util#272 and odoo/upgrade-util#175. All utils we document online should be used via the top-level module --i.e. `util.name` instead of `util.submodule.name` Stripping the module path can be achieved in the configuration with [`add_module_name=False`](https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-add_module_names) Unfortunately this is a global setting that could affect other parts of Odoo documentation. Thus in current patch we strip the module path from the signature of `odoo.upgrade.util` functions and classes. Technical links: https://www.sphinx-doc.org/en/master/extdev/event_callbacks.html#event-object-description-transform https://www.sphinx-doc.org/en/master/extdev/nodes.html#sphinx.addnodes.desc_signature https://github.com/sphinx-doc/sphinx/blob/v4.3.2/sphinx/domains/python.py#L512 https://sphinx-docutils.readthedocs.io/en/latest/docutils.nodes.html#docutils.nodes closes #13547 X-original-commit: fa506a6 Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com> Signed-off-by: Alvaro Fuentes Suarez (afu) <afu@odoo.com>
1 parent 2870bb0 commit a4a5c9d

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

conf.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,16 @@ def source_read_replace(app, docname, source):
386386
result = result.replace(f"{{{key}}}", app.config.source_read_replace_vals[key])
387387
source[0] = result
388388

389+
def upgrade_util_signature_rewrite(app, domain, objtype, contentnode):
390+
# Same as add_module_names=False but **only** for odoo.upgrade.util functions or classes
391+
signature = contentnode.parent[0]
392+
if objtype == 'function' and signature.astext().startswith('odoo.upgrade.util.'):
393+
# <odoo.upgrade.util.modules>, <modules_installed>, <(cr, *modules)>
394+
signature.pop(0)
395+
if objtype == 'class' and signature.astext().startswith('class odoo.upgrade.util.'):
396+
# <class >, <odoo.upgrade.util.pg.>, <PGRegexp>
397+
signature.pop(1)
398+
389399
def setup(app):
390400
# Generate all alternate URLs for each document
391401
app.add_config_value('project_root', None, 'env')
@@ -395,6 +405,7 @@ def setup(app):
395405
app.add_config_value('is_remote_build', None, 'env') # Whether the build is remotely deployed
396406
app.add_config_value('source_read_replace_vals', {}, 'env')
397407
app.connect('source-read', source_read_replace)
408+
app.connect('object-description-transform', upgrade_util_signature_rewrite)
398409
# TODO uncomment after moving to >= v7.2.5 to also substitute placeholders in included files.
399410
# See https://github.com/sphinx-doc/sphinx/commit/ff1831
400411
# app.connect('include-read', source_read_replace)

0 commit comments

Comments
 (0)