diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a4f54de66dc..af1ac87bcec 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -43,7 +43,6 @@ repos: rev: 20.8b1 hooks: - id: black - exclude: ^upgrade_analysis/odoo_patch/ - repo: https://github.com/pre-commit/mirrors-prettier rev: v2.1.2 hooks: @@ -54,7 +53,6 @@ repos: - "@prettier/plugin-xml@0.12.0" args: - --plugin=@prettier/plugin-xml - exclude: ^upgrade_analysis/odoo_patch/ - repo: https://github.com/pre-commit/mirrors-eslint rev: v7.8.1 hooks: @@ -89,7 +87,6 @@ repos: rev: v2.7.2 hooks: - id: pyupgrade - exclude: ^upgrade_analysis/odoo_patch/ - repo: https://github.com/PyCQA/isort rev: 5.5.1 hooks: @@ -97,7 +94,7 @@ repos: name: isort except __init__.py args: - --settings=. - exclude: /__init__\.py$|^upgrade_analysis/odoo_patch/ + exclude: /__init__\.py$ - repo: https://github.com/acsone/setuptools-odoo rev: 2.6.0 hooks: @@ -113,14 +110,13 @@ repos: hooks: - id: flake8 name: flake8 except __init__.py - exclude: /__init__\.py$|^upgrade_analysis/odoo_patch/ + exclude: /__init__\.py$ additional_dependencies: ["flake8-bugbear==20.1.4"] - id: flake8 name: flake8 only __init__.py args: ["--extend-ignore=F401"] # ignore unused imports in __init__.py files: /__init__\.py$ additional_dependencies: ["flake8-bugbear==20.1.4"] - exclude: ^upgrade_analysis/odoo_patch/ - repo: https://github.com/PyCQA/pylint rev: pylint-2.5.3 hooks: diff --git a/upgrade_analysis/odoo_patch/addons/mrp/__init__.py b/upgrade_analysis/odoo_patch/addons/mrp/__init__.py index 94f30010f58..09caee64cb1 100644 --- a/upgrade_analysis/odoo_patch/addons/mrp/__init__.py +++ b/upgrade_analysis/odoo_patch/addons/mrp/__init__.py @@ -1,10 +1,11 @@ +# flake8: noqa: B902 from odoo.addons import mrp from ...odoo_patch import OdooPatch class PreInitHookPatch(OdooPatch): target = mrp - method_names = ['_pre_init_mrp'] + method_names = ["_pre_init_mrp"] def _pre_init_mrp(cr): """ Don't try to create an existing column on reinstall """ diff --git a/upgrade_analysis/odoo_patch/addons/point_of_sale/__init__.py b/upgrade_analysis/odoo_patch/addons/point_of_sale/__init__.py index a67563f42d4..66f003c1787 100644 --- a/upgrade_analysis/odoo_patch/addons/point_of_sale/__init__.py +++ b/upgrade_analysis/odoo_patch/addons/point_of_sale/__init__.py @@ -1,3 +1,4 @@ +# flake8: noqa: B902 from odoo import api from odoo.addons.point_of_sale.models import pos_config from ...odoo_patch import OdooPatch @@ -5,7 +6,7 @@ class PreInitHookPatch(OdooPatch): target = pos_config.PosConfig - method_names = ['post_install_pos_localisation'] + method_names = ["post_install_pos_localisation"] @api.model def post_install_pos_localisation(cr): diff --git a/upgrade_analysis/odoo_patch/addons/stock/__init__.py b/upgrade_analysis/odoo_patch/addons/stock/__init__.py index a28a083cea8..206795b42db 100644 --- a/upgrade_analysis/odoo_patch/addons/stock/__init__.py +++ b/upgrade_analysis/odoo_patch/addons/stock/__init__.py @@ -1,10 +1,11 @@ +# flake8: noqa: B902 from odoo.addons import stock from ...odoo_patch import OdooPatch class PreInitHookPatch(OdooPatch): target = stock - method_names = ['pre_init_hook'] + method_names = ["pre_init_hook"] def pre_init_hook(cr): """ Don't unlink stock data on reinstall """ diff --git a/upgrade_analysis/odoo_patch/odoo/models.py b/upgrade_analysis/odoo_patch/odoo/models.py index 09c10c41836..431fc9635c8 100644 --- a/upgrade_analysis/odoo_patch/odoo/models.py +++ b/upgrade_analysis/odoo_patch/odoo/models.py @@ -1,21 +1,23 @@ from odoo import api, models -from ..odoo_patch import OdooPatch + from ... import upgrade_log +from ..odoo_patch import OdooPatch class BaseModelPatch(OdooPatch): target = models.BaseModel - method_names = ['_convert_records'] + method_names = ["_convert_records"] @api.model def _convert_records(self, records, log=lambda a: None): """ Log data ids that are imported with `load` """ - current_module = self.env.context['module'] + current_module = self.env.context["module"] for res in BaseModelPatch._convert_records._original_method( - self, records, log=log): + self, records, log=log + ): _id, xid, _record, _info = res if xid: - xid = xid if '.' in xid else "%s.%s" % (current_module, xid) + xid = xid if "." in xid else "{}.{}".format(current_module, xid) upgrade_log.log_xml_id(self.env.cr, current_module, xid) yield res diff --git a/upgrade_analysis/odoo_patch/odoo/modules/registry.py b/upgrade_analysis/odoo_patch/odoo/modules/registry.py index 3d0981a001e..017da063fd2 100644 --- a/upgrade_analysis/odoo_patch/odoo/modules/registry.py +++ b/upgrade_analysis/odoo_patch/odoo/modules/registry.py @@ -1,20 +1,22 @@ import logging from threading import current_thread -from odoo import api, SUPERUSER_ID -from ...odoo_patch import OdooPatch -from .... import upgrade_log + +from odoo import SUPERUSER_ID, api from odoo.modules.registry import Registry +from .... import upgrade_log +from ...odoo_patch import OdooPatch + _logger = logging.getLogger(__name__) class RegistryPatch(OdooPatch): target = Registry - method_names = ['init_models'] + method_names = ["init_models"] def init_models(self, cr, model_names, context, install=True): - module_name = context['module'] - _logger.debug('Logging models of module %s', module_name) + module_name = context["module"] + _logger.debug("Logging models of module %s", module_name) upg_registry = current_thread()._upgrade_registry local_registry = {} env = api.Environment(cr, SUPERUSER_ID, {}) @@ -23,7 +25,9 @@ def init_models(self, cr, model_names, context, install=True): continue upgrade_log.log_model(model, local_registry) upgrade_log.compare_registries( - cr, context['module'], upg_registry, local_registry) + cr, context["module"], upg_registry, local_registry + ) return RegistryPatch.init_models._original_method( - self, cr, model_names, context, install=install) + self, cr, model_names, context, install=install + ) diff --git a/upgrade_analysis/odoo_patch/odoo/tools/convert.py b/upgrade_analysis/odoo_patch/odoo/tools/convert.py index 7130859d628..0912c6d2674 100644 --- a/upgrade_analysis/odoo_patch/odoo/tools/convert.py +++ b/upgrade_analysis/odoo_patch/odoo/tools/convert.py @@ -1,11 +1,12 @@ -from ...odoo_patch import OdooPatch -from .... import upgrade_log from odoo.tools.convert import xml_import +from .... import upgrade_log +from ...odoo_patch import OdooPatch + class XMLImportPatch(OdooPatch): target = xml_import - method_names = ['_test_xml_id'] + method_names = ["_test_xml_id"] def _test_xml_id(self, xml_id): res = XMLImportPatch._test_xml_id._original_method(self, xml_id) diff --git a/upgrade_analysis/odoo_patch/odoo_patch.py b/upgrade_analysis/odoo_patch/odoo_patch.py index ac9f02fee2e..c1956f51f46 100644 --- a/upgrade_analysis/odoo_patch/odoo_patch.py +++ b/upgrade_analysis/odoo_patch/odoo_patch.py @@ -4,7 +4,7 @@ class OdooPatch(object): - """ Simple mechanism to apply a collection of monkeypatches using a + """Simple mechanism to apply a collection of monkeypatches using a context manager. Classes can register their monkeypatches by inheriting from this class. @@ -39,21 +39,23 @@ def do_something(self): do_something() ``` """ + def __enter__(self): for cls in OdooPatch.__subclasses__(): for method_name in cls.method_names: method = getattr(cls, method_name) - setattr(method, '_original_method', - getattr(cls.target, method_name)) + method._original_method = getattr(cls.target, method_name) setattr(cls.target, method_name, method) def __exit__(self, exc_type, exc_value, tb): for cls in OdooPatch.__subclasses__(): for method_name in cls.method_names: method = getattr(cls.target, method_name) - if hasattr(method, '_original_method'): + if hasattr(method, "_original_method"): setattr(cls.target, method_name, method._original_method) else: _logger.warn( - '_original_method not found on method %s of class %s', - method_name, cls.target) + "_original_method not found on method %s of class %s", + method_name, + cls.target, + )