Skip to content

Commit 26fd5f3

Browse files
aj-fuentesFeyensv
andcommitted
[IMP] upgrade-util: link code documentation
Add direct code documentation from upgrade-util repo. Adapt `extensions/github_link`. Original commit: 3352d33 Part-of: #8836 Co-authored-by: Victor Feyens <[email protected]>
1 parent 62f6502 commit 26fd5f3

File tree

3 files changed

+48
-28
lines changed

3 files changed

+48
-28
lines changed

README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- Python dependencies listed in the file `requirements.txt`.
1010
- Make
1111
- A local copy of the [odoo/odoo repository](https://github.com/odoo/odoo) (optional)
12+
- A local copy of the [odoo/upgrade-util repository](https://github.com/odoo/upgrade-util) (optional)
1213

1314
### Instructions
1415

@@ -18,8 +19,9 @@
1819
3. See [this guide](https://www.odoo.com/documentation/latest/contributing/documentation.html)
1920
for more detailed instructions.
2021

21-
Optional: place your local copy of the `odoo/odoo` repository in the parent directory or in the root
22-
directory of the documentation to build the latter with the documented Python docstrings.
22+
Optional: place your local copy of the `odoo/odoo` and `odoo/upgrade-util` repositories in
23+
the parent directory or in the root directory of the documentation to build the latter
24+
with the documented Python docstrings.
2325

2426
## Contribute to the documentation
2527

conf.py

+21
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,24 @@
133133
)
134134
odoo_dir_in_path = True
135135

136+
if odoo_dir_in_path:
137+
upgrade_util_dir = next(filter(Path.exists, [Path('upgrade-util'), Path('../upgrade-util')]), None)
138+
if not upgrade_util_dir:
139+
_logger.warning(
140+
"Could not find Upgrade Utils sources directory in `upgrade_util`.\n"
141+
"The developer documentation will be built but autodoc directives will be skipped.\n"
142+
"In order to fully build the 'Developer' documentation, clone the repository with "
143+
"`git clone https://github.com/odoo/upgrade-util` or create a symbolic link."
144+
)
145+
odoo_dir_in_path = False
146+
else:
147+
_logger.info(
148+
"Found Upgrade Util sources in %(directory)s",
149+
{'directory': upgrade_util_dir.resolve()},
150+
)
151+
from odoo import upgrade
152+
upgrade.__path__.append(str((upgrade_util_dir / 'src').resolve()))
153+
136154
# Mapping between odoo models related to master data and the declaration of the
137155
# data. This is used to point users to available xml_ids when giving values for
138156
# a field with the autodoc_field extension.
@@ -250,6 +268,9 @@
250268
sphinx_tabs_disable_tab_closing = True
251269
sphinx_tabs_disable_css_loading = True
252270

271+
# Autodoc ordering
272+
autodoc_member_order = 'bysource'
273+
253274
#=== Options for HTML output ===#
254275

255276
html_theme = 'odoo_theme'

extensions/github_link/__init__.py

+23-26
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import os.path
2525

2626
import werkzeug
27+
import contextlib
2728

2829

2930
def setup(app):
@@ -36,6 +37,7 @@ def linkcode_resolve(domain, info):
3637
# TODO: js?
3738
if domain != 'py':
3839
return None
40+
3941
if not (app.config.github_user and app.config.github_project):
4042
return None
4143

@@ -53,10 +55,8 @@ def linkcode_resolve(domain, info):
5355
return None
5456

5557
# get original from decorated methods
56-
try:
57-
obj = getattr(obj, '_orig')
58-
except AttributeError:
59-
pass
58+
with contextlib.suppress(AttributeError):
59+
obj = obj._orig
6060

6161
try:
6262
obj_source_path = inspect.getsourcefile(obj)
@@ -65,37 +65,34 @@ def linkcode_resolve(domain, info):
6565
# obj doesn't have a module, or something
6666
return None
6767

68-
import odoo
6968
# FIXME: make finding project root project-independent
70-
project_root = os.path.join(os.path.dirname(odoo.__file__), '..')
69+
if module.startswith('odoo.upgrade.util'):
70+
from odoo.upgrade import util
71+
project = 'upgrade-util'
72+
project_root = os.path.join(os.path.dirname(util.__file__), '../..')
73+
else:
74+
import odoo
75+
project = 'odoo'
76+
project_root = os.path.join(os.path.dirname(odoo.__file__), '..')
7177
return make_github_link(
7278
app,
73-
os.path.relpath(obj_source_path, project_root),
74-
line,
75-
odoo_repository=True)
79+
project=project,
80+
path=os.path.relpath(obj_source_path, project_root),
81+
line=line,
82+
)
7683
app.config.linkcode_resolve = linkcode_resolve
7784

7885
return {
7986
'parallel_read_safe': True,
8087
'parallel_write_safe': True
8188
}
8289

83-
def make_github_link(app, path, line=None, mode="blob", odoo_repository=False):
84-
config = app.config
85-
86-
user = config.github_user
87-
project = config.github_project
88-
if odoo_repository:
89-
user = 'odoo'
90-
project = 'odoo'
91-
92-
urlpath = "/{user}/{project}/{mode}/{branch}/{path}".format(
93-
user=user,
94-
project=project,
95-
branch=config.version or 'master',
96-
path=path,
97-
mode=mode,
98-
)
90+
def make_github_link(app, project, path, line=None, mode="blob"):
91+
branch = app.config.version or 'master'
92+
if project == 'upgrade-util':
93+
branch = 'master'
94+
95+
urlpath = f"/{app.config.github_user}/{project}/{mode}/{branch}/{path}"
9996
return werkzeug.urls.url_unparse((
10097
'https',
10198
'github.com',
@@ -116,4 +113,4 @@ def add_doc_link(app, pagename, templatename, context, doctree):
116113
source_suffix = app.config.source_suffix
117114
source_suffix = next(iter(source_suffix))
118115
context['github_link'] = lambda mode='edit': make_github_link(
119-
app, f'content/{pagename}{source_suffix}', mode=mode)
116+
app, project=app.config.github_project, path=f'content/{pagename}{source_suffix}', mode=mode)

0 commit comments

Comments
 (0)