From d8ee081ea076b97d61a46caab0a7eb2493f2d7c6 Mon Sep 17 00:00:00 2001 From: "Krzysztof Magusiak (krma)" Date: Sat, 25 Jan 2025 09:21:03 +0000 Subject: [PATCH] [IMP] core: PEP420 native namespace task-4035335 --- .../contributing/development/coding_guidelines.rst | 8 ++++---- .../developer/reference/backend/orm/changelog.rst | 6 ++++++ extensions/autodoc_field/__init__.py | 14 ++++++++------ extensions/github_link/__init__.py | 4 ++-- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/content/contributing/development/coding_guidelines.rst b/content/contributing/development/coding_guidelines.rst index 2cdc634081..c8bd0728de 100644 --- a/content/contributing/development/coding_guidelines.rst +++ b/content/contributing/development/coding_guidelines.rst @@ -411,8 +411,8 @@ Imports The imports are ordered as #. External libraries (one per line sorted and split in python stdlib) -#. Imports of ``odoo`` -#. Imports from Odoo modules (rarely, and only if necessary) +#. Imports of ``odoo`` submodules +#. Imports from Odoo addons (rarely, and only if necessary) Inside these 3 groups, the imported lines are alphabetically sorted. @@ -424,8 +424,8 @@ Inside these 3 groups, the imported lines are alphabetically sorted. import time from datetime import datetime # 2 : imports of odoo - import odoo - from odoo import api, fields, models, _ # alphabetically ordered + from odoo import api, fields, models # alphabetically ordered + from odoo.fields import Domain from odoo.tools.safe_eval import safe_eval as eval # 3 : imports from odoo addons from odoo.addons.web.controllers.main import login_redirect diff --git a/content/developer/reference/backend/orm/changelog.rst b/content/developer/reference/backend/orm/changelog.rst index d6deeeed8a..b0cce0ddda 100644 --- a/content/developer/reference/backend/orm/changelog.rst +++ b/content/developer/reference/backend/orm/changelog.rst @@ -4,6 +4,12 @@ Changelog ========= +Odoo Online version 18.2 +======================== + +- Native namespaces for ``odoo`` module `PEP-420 `_. + See `#195664 `_. + Odoo Online version 18.1 ======================== diff --git a/extensions/autodoc_field/__init__.py b/extensions/autodoc_field/__init__.py index 4f14b56c21..1ab3b78084 100644 --- a/extensions/autodoc_field/__init__.py +++ b/extensions/autodoc_field/__init__.py @@ -6,8 +6,6 @@ from sphinx.domains.python import PyAttribute, PyClasslike from sphinx.ext.autodoc import AttributeDocumenter, ClassDocumenter -import odoo - nested_parse = RSTState.nested_parse def patched_nested_parse(self, block, input_offset, node, match_titles=False, state_machine_class=None, state_machine_kwargs=None): @@ -23,7 +21,8 @@ class OdooClassDocumenter(ClassDocumenter): @classmethod def can_document_member(cls, member, membername, isattr, parent): - return isinstance(member, odoo.models.MetaModel) + from odoo.models import MetaModel + return isinstance(member, MetaModel) def add_content(self, more_content): sourcename = self.get_sourcename() @@ -56,7 +55,8 @@ class FieldDocumenter(AttributeDocumenter): @classmethod def can_document_member(cls, member, membername, isattr, parent): - return isinstance(member, odoo.fields.Field) + from odoo.fields import Field + return isinstance(member, Field) def update_annotations(self, parent): super().update_annotations(parent) @@ -67,7 +67,8 @@ def update_annotations(self, parent): if field.type == 'many2one': annotation[attrname] = int elif field.type in ('one2many', 'many2many'): - annotation[attrname] = Sequence[odoo.fields.Command] + from odoo.fields import Command + annotation[attrname] = Sequence[Command] elif field.type in ('selection', 'reference', 'char', 'text', 'html'): annotation[attrname] = str elif field.type == 'boolean': @@ -104,7 +105,8 @@ def add_content(self, more_content): if reference: self.add_line(f":possible_values: `{reference} <{self.config.source_read_replace_vals['GITHUB_PATH']}/{reference}>`__", source_name) if field.default: - self.add_line(f":default: {field.default(odoo.models.Model)}", source_name) + from odoo.models import Model + self.add_line(f":default: {field.default(Model)}", source_name) super().add_content(more_content) if field.help: diff --git a/extensions/github_link/__init__.py b/extensions/github_link/__init__.py index 3993d538b8..baa9c00776 100644 --- a/extensions/github_link/__init__.py +++ b/extensions/github_link/__init__.py @@ -71,9 +71,9 @@ def linkcode_resolve(domain, info): project = 'upgrade-util' project_root = os.path.join(os.path.dirname(util.__file__), '../..') else: - import odoo + from odoo import release project = 'odoo' - project_root = os.path.join(os.path.dirname(odoo.__file__), '..') + project_root = os.path.join(os.path.dirname(release.__file__), '..') return make_github_link( app, project=project,