Skip to content

Commit 541c9d4

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 #13519 Signed-off-by: Victor Feyens (vfe) <[email protected]>
1 parent ad5ab46 commit 541c9d4

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
@@ -380,6 +380,16 @@ def source_read_replace(app, docname, source):
380380
result = result.replace(f"{{{key}}}", app.config.source_read_replace_vals[key])
381381
source[0] = result
382382

383+
def upgrade_util_signature_rewrite(app, domain, objtype, contentnode):
384+
# Same as add_module_names=False but **only** for odoo.upgrade.util functions or classes
385+
signature = contentnode.parent[0]
386+
if objtype == 'function' and signature.astext().startswith('odoo.upgrade.util.'):
387+
# <odoo.upgrade.util.modules>, <modules_installed>, <(cr, *modules)>
388+
signature.pop(0)
389+
if objtype == 'class' and signature.astext().startswith('class odoo.upgrade.util.'):
390+
# <class >, <odoo.upgrade.util.pg.>, <PGRegexp>
391+
signature.pop(1)
392+
383393
def setup(app):
384394
# Generate all alternate URLs for each document
385395
app.add_config_value('project_root', None, 'env')
@@ -389,6 +399,7 @@ def setup(app):
389399
app.add_config_value('is_remote_build', None, 'env') # Whether the build is remotely deployed
390400
app.add_config_value('source_read_replace_vals', {}, 'env')
391401
app.connect('source-read', source_read_replace)
402+
app.connect('object-description-transform', upgrade_util_signature_rewrite)
392403

393404
app.add_lexer('json', JsonLexer)
394405
app.add_lexer('xml', XmlLexer)

0 commit comments

Comments
 (0)