Skip to content

Commit 0405041

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 X-original-commit: 541c9d4
1 parent 2f89941 commit 0405041

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

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

0 commit comments

Comments
 (0)