Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] core, contributing: adapt to PEP420 native namespace #11914

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions content/contributing/development/coding_guidelines.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions content/developer/reference/backend/orm/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
Changelog
=========

Odoo Online version 18.2
========================

- Native namespaces for ``odoo`` module `PEP-420 <https://peps.python.org/pep-0420/>`_.
See `#195664 <https://github.com/odoo/odoo/pull/195664>`_.

Odoo Online version 18.1
========================

Expand Down
14 changes: 8 additions & 6 deletions extensions/autodoc_field/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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()
Expand Down Expand Up @@ -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)
Expand All @@ -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':
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions extensions/github_link/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down