From 623d39ba7641326b681c437c4ba78f5be40f3b1b Mon Sep 17 00:00:00 2001 From: fkantelberg Date: Mon, 18 Nov 2024 09:17:25 +0100 Subject: [PATCH 1/5] Reformat according to black --- src/doblib/ci.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/doblib/ci.py b/src/doblib/ci.py index 6ac11f6..d0b7b8b 100644 --- a/src/doblib/ci.py +++ b/src/doblib/ci.py @@ -168,9 +168,8 @@ def _ci_pylint(self, options, args, paths, ignores): return utils.call(*cmd, *args, *files, pipe=False) def _ci_paths(self): - return ( - self.get("odoo", "addons_path", default=[]) - + self.get("bootstrap", "ci_path", default=[]) + return self.get("odoo", "addons_path", default=[]) + self.get( + "bootstrap", "ci_path", default=[] ) def ci(self, ci, args=None): From b567782758b22e1d51861dd823374992f81e49e6 Mon Sep 17 00:00:00 2001 From: fkantelberg Date: Mon, 18 Nov 2024 09:24:48 +0100 Subject: [PATCH 2/5] Fix unittests --- tests/test_action.py | 2 ++ tests/test_ci.py | 2 ++ tests/test_environment.py | 8 +++++--- tests/test_migrate.py | 2 ++ tests/test_module.py | 8 ++++++++ 5 files changed, 19 insertions(+), 3 deletions(-) diff --git a/tests/test_action.py b/tests/test_action.py index 5b3450c..e1d9f08 100644 --- a/tests/test_action.py +++ b/tests/test_action.py @@ -426,6 +426,8 @@ def test_apply_action(env): odoo = sys.modules["odoo"] = mock.MagicMock() sys.modules["odoo.tools"] = mock.MagicMock() + sys.modules["odoo.modules"] = mock.MagicMock() + sys.modules["odoo.modules.registry"] = mock.MagicMock() sys.modules["odoo.release"] = odoo.release odoo.release.version_info = (14, 0) env._init_odoo.return_value = True diff --git a/tests/test_ci.py b/tests/test_ci.py index a64c51d..b201049 100644 --- a/tests/test_ci.py +++ b/tests/test_ci.py @@ -26,6 +26,8 @@ def env(): def test_test(pytest_mock, env): odoo = sys.modules["odoo"] = mock.MagicMock() tools = sys.modules["odoo.tools"] = mock.MagicMock() + sys.modules["odoo.modules"] = mock.MagicMock() + sys.modules["odoo.modules.registry"] = mock.MagicMock() sys.modules["odoo.release"] = odoo.release odoo.release.version_info = (14, 0) diff --git a/tests/test_environment.py b/tests/test_environment.py index 2391d9e..92e7144 100644 --- a/tests/test_environment.py +++ b/tests/test_environment.py @@ -110,13 +110,15 @@ def test_env(env): with env.env("odoo"): pass - odoo = sys.modules["odoo"] = mock.MagicMock() - reg = odoo.registry.return_value = mock.MagicMock() + sys.modules["odoo"] = mock.MagicMock() + sys.modules["odoo.modules"] = mock.MagicMock() + registry = sys.modules["odoo.modules.registry"] = mock.MagicMock() + reg = registry.Registry.return_value = mock.MagicMock() cr = reg.cursor.return_value = mock.MagicMock() # Test the normal commit with env.env("odoo"): - odoo.registry.assert_called_once_with("odoo") + registry.Registry.assert_called_once_with("odoo") cr.commit.assert_not_called() cr.commit.assert_called_once() diff --git a/tests/test_migrate.py b/tests/test_migrate.py index 129082a..ad4acfe 100644 --- a/tests/test_migrate.py +++ b/tests/test_migrate.py @@ -24,6 +24,8 @@ def env(): def test_migrate(repos, env): odoo = sys.modules["odoo"] = mock.MagicMock() tools = sys.modules["odoo.tools"] = mock.MagicMock() + sys.modules["odoo.modules"] = mock.MagicMock() + sys.modules["odoo.modules.registry"] = mock.MagicMock() tools.config.__getitem__.return_value = "odoo" sys.modules["odoo.release"] = odoo.release odoo.release.version_info = (14, 0) diff --git a/tests/test_module.py b/tests/test_module.py index 369a6f1..3d2c8b9 100644 --- a/tests/test_module.py +++ b/tests/test_module.py @@ -86,6 +86,8 @@ def test_get_installed_modules(env): def test_install_all(env): odoo = sys.modules["odoo"] = mock.MagicMock() sys.modules["odoo.tools"] = mock.MagicMock() + sys.modules["odoo.modules"] = mock.MagicMock() + sys.modules["odoo.modules.registry"] = mock.MagicMock() env.install_all("odoo", ["module"]) odoo.modules.registry.Registry.new.assert_called_once_with( @@ -101,6 +103,8 @@ def test_install_all(env): def test_update_all(env): odoo = sys.modules["odoo"] = mock.MagicMock() sys.modules["odoo.tools"] = mock.MagicMock() + sys.modules["odoo.modules"] = mock.MagicMock() + sys.modules["odoo.modules.registry"] = mock.MagicMock() env.update_specific("odoo", installed=True) odoo.modules.registry.Registry.new.assert_called_once_with( @@ -112,6 +116,8 @@ def test_update_all(env): def test_update_listed(env): odoo = sys.modules["odoo"] = mock.MagicMock() sys.modules["odoo.tools"] = mock.MagicMock() + sys.modules["odoo.modules"] = mock.MagicMock() + sys.modules["odoo.modules.registry"] = mock.MagicMock() env._get_modules = mock.MagicMock() env.update_specific("odoo", listed=True) @@ -143,6 +149,8 @@ def test_update(env): # Quite complex and we have to mock plenty of stuff odoo = sys.modules["odoo"] = mock.MagicMock() tools = sys.modules["odoo.tools"] = mock.MagicMock() + sys.modules["odoo.modules"] = mock.MagicMock() + sys.modules["odoo.modules.registry"] = mock.MagicMock() sys.modules["odoo.release"] = odoo.release tools.config.__getitem__.return_value = "odoo" odoo.release.version_info = (14, 0) From fce2f771c2bb18a7d94dbd335ee930af4f9410b4 Mon Sep 17 00:00:00 2001 From: fkantelberg Date: Fri, 2 May 2025 11:44:23 +0200 Subject: [PATCH 3/5] Add option to set file extensions for pylint and prettier. Add xml check per default. Bump version --- src/doblib/__init__.py | 2 +- src/doblib/ci.py | 32 ++++++++++++++++++++------------ tests/test_ci.py | 10 +++------- 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/doblib/__init__.py b/src/doblib/__init__.py index c130786..1ea9aa5 100644 --- a/src/doblib/__init__.py +++ b/src/doblib/__init__.py @@ -1 +1 @@ -VERSION = "0.19.2" +VERSION = "0.19.3" diff --git a/src/doblib/ci.py b/src/doblib/ci.py index d0b7b8b..bfd9cba 100644 --- a/src/doblib/ci.py +++ b/src/doblib/ci.py @@ -107,17 +107,22 @@ def _ci_isort(self, options, args, paths, ignores): return utils.call(*cmd, *args, *paths, pipe=False) def _ci_prettier(self, options, args, paths, ignores): - """ """ + """Run prettier on supported files""" executable = shutil.which("prettier") if not executable: utils.error("prettier is not installed") return 1 - files = [] + files = set() + + extensions = self.get( + base.SECTION, "prettier", "extension", default=["js", "xml"] + ) for path in paths: - files.extend(glob.glob(f"{path}/**/*.js", recursive=True)) + for ext in extensions: + files.update(glob.glob(f"{path}/**/*.{ext}", recursive=True)) - files = list( + files = sorted( filter( lambda path: not any( fnmatch(path, f"*/{pattern}") @@ -132,7 +137,7 @@ def _ci_prettier(self, options, args, paths, ignores): if not files: return 0 - cmd = ["prettier"] + cmd = ["prettier", "--check"] if options.fix: cmd.append("--write") @@ -140,13 +145,16 @@ def _ci_prettier(self, options, args, paths, ignores): def _ci_pylint(self, options, args, paths, ignores): """Run pylint tests for Odoo""" - files = [] + files = set() + + extensions = self.get( + base.SECTION, "pylint", "extension", default=["csv", "py", "xml"] + ) for path in paths: - files.extend(glob.glob(f"{path}/**/*.csv", recursive=True)) - files.extend(glob.glob(f"{path}/**/*.py", recursive=True)) - files.extend(glob.glob(f"{path}/**/*.xml", recursive=True)) + for ext in extensions: + files.update(glob.glob(f"{path}/**/*.{ext}", recursive=True)) - files = list( + files = sorted( filter( lambda path: not any( fnmatch(path, f"*/{pattern}") @@ -169,7 +177,7 @@ def _ci_pylint(self, options, args, paths, ignores): def _ci_paths(self): return self.get("odoo", "addons_path", default=[]) + self.get( - "bootstrap", "ci_path", default=[] + base.SECTION, "ci_path", default=[] ) def ci(self, ci, args=None): @@ -177,7 +185,7 @@ def ci(self, ci, args=None): args, left = load_ci_arguments(args or []) # Always include this script in the tests - ignores = self.get("bootstrap", "blacklist", default=[]) + ignores = self.get(base.SECTION, "blacklist", default=[]) func = getattr(self, f"_ci_{ci}", None) if ci in CI and callable(func): return func(args, left, self._ci_paths(), ignores) diff --git a/tests/test_ci.py b/tests/test_ci.py index b201049..3eb6310 100644 --- a/tests/test_ci.py +++ b/tests/test_ci.py @@ -6,7 +6,6 @@ from unittest import mock import pytest - from doblib import base from doblib.ci import CIEnvironment @@ -145,15 +144,16 @@ def test_ci_prettier(which, call, env): with mock.patch( "glob.glob", return_value=[ - "test15/path/file.py", - "folder/test123/file.py", "folder/path/test196.py", + "folder/test123/file.py", + "test15/path/file.py", "test2/path/file.py", ], ): assert env.ci("prettier", ["--fix"]) == 42 call.assert_called_once_with( "prettier", + "--check", "--write", "test2/path/file.py", pipe=False, @@ -178,8 +178,6 @@ def test_ci_pylint(call, glob, env): "pylint", "--rcfile=.pylintrc", "test2/path/file.py", - "test2/path/file.py", - "test2/path/file.py", pipe=False, ) @@ -191,8 +189,6 @@ def test_ci_pylint(call, glob, env): "pylint", "--rcfile=.pylintrc", "test2/path/file.py", - "test2/path/file.py", - "test2/path/file.py", pipe=False, ) From 9d6a01b5b2263fb7dce8957a45f60addc4444c25 Mon Sep 17 00:00:00 2001 From: fkantelberg Date: Fri, 2 May 2025 11:58:11 +0200 Subject: [PATCH 4/5] Fix isort CI --- tests/test_ci.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_ci.py b/tests/test_ci.py index 3eb6310..8ab3372 100644 --- a/tests/test_ci.py +++ b/tests/test_ci.py @@ -6,6 +6,7 @@ from unittest import mock import pytest + from doblib import base from doblib.ci import CIEnvironment From 08e26bcd3e717b28081f2ce527bc625bf82b211b Mon Sep 17 00:00:00 2001 From: fkantelberg Date: Fri, 2 May 2025 13:36:31 +0200 Subject: [PATCH 5/5] Load configuration for prettier. Allow to set the config files with options. Bump version --- src/doblib/__init__.py | 2 +- src/doblib/ci.py | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/doblib/__init__.py b/src/doblib/__init__.py index 1ea9aa5..3bc471b 100644 --- a/src/doblib/__init__.py +++ b/src/doblib/__init__.py @@ -1 +1 @@ -VERSION = "0.19.3" +VERSION = "0.19.4" diff --git a/src/doblib/ci.py b/src/doblib/ci.py index bfd9cba..15a095e 100644 --- a/src/doblib/ci.py +++ b/src/doblib/ci.py @@ -141,6 +141,12 @@ def _ci_prettier(self, options, args, paths, ignores): if options.fix: cmd.append("--write") + config_path = self.get( + base.SECTION, "prettier", "config", default=".prettierrc.yml" + ) + if os.path.isfile(config_path): + cmd.append(f"--config {config_path}") + return utils.call(*cmd, *args, *files, pipe=False) def _ci_pylint(self, options, args, paths, ignores): @@ -170,8 +176,9 @@ def _ci_pylint(self, options, args, paths, ignores): return 0 cmd = [sys.executable, "-m", "pylint"] - if os.path.isfile(".pylintrc"): - cmd.append("--rcfile=.pylintrc") + config_path = self.get(base.SECTION, "pylint", "config", default=".pylintrc") + if os.path.isfile(config_path): + cmd.append(f"--rcfile={config_path}") return utils.call(*cmd, *args, *files, pipe=False)