From c42555887dc1d532b73698edc20699909dd4f517 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Faure-Lacroix?= Date: Thu, 6 Jul 2023 11:05:12 -0400 Subject: [PATCH] Added a way to exclude some modules from the result of dependencies --- odoo_tools/cli/click/module.py | 14 ++++++++-- tests/cli/test_modules.py | 50 ++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 tests/cli/test_modules.py diff --git a/odoo_tools/cli/click/module.py b/odoo_tools/cli/click/module.py index 2758216..1f72c85 100644 --- a/odoo_tools/cli/click/module.py +++ b/odoo_tools/cli/click/module.py @@ -197,7 +197,7 @@ def show_module(ctx, module): ) @click.option( '--include-modules', - help="Remove logs and warnings.", + help="Include dependencies that aren't in the addons_paths.", is_flag=True, default=False ) @@ -207,6 +207,12 @@ def show_module(ctx, module): is_flag=True, default=False ) +@click.option( + '--exclude-modules', + help="Exclude queried modules from the found dependencies.", + is_flag=True, + default=False +) @click.pass_context def show_dependencies( ctx, @@ -220,7 +226,8 @@ def show_dependencies( path, auto, quiet, - include_modules + include_modules, + exclude_modules, ): env = ctx.obj['env'] @@ -278,6 +285,9 @@ def check_module(mod): mods = [ mod.path.name if only_name else str(mod) for mod in sorted_dependencies + if ( + exclude_modules and mod.path.name not in check_modules + ) or not exclude_modules ] if csv: diff --git a/tests/cli/test_modules.py b/tests/cli/test_modules.py new file mode 100644 index 0000000..29e4fea --- /dev/null +++ b/tests/cli/test_modules.py @@ -0,0 +1,50 @@ +from mock import patch, MagicMock +from odoo_tools.cli.odot import command +from odoo_tools.api.environment import Environment + +from odoo_tools.api.modules import ModuleApi +from odoo_tools.api.objects import Manifest + + +def test_module_deps(runner, tmp_path): + + with patch.object(ModuleApi, 'list') as list_modules: + + list_modules.return_value = [ + Manifest(tmp_path / 'a', attrs={'version': 1, 'depends': {}}), + Manifest(tmp_path / 'b', attrs={'version': 1, 'depends': {'a'}}), + Manifest(tmp_path / 'c', attrs={'version': 1, 'depends': {'b'}}), + Manifest( + tmp_path / 'd', + attrs={ + 'version': 1, + 'depends': {'a', 'c'} + } + ) + ] + + result = runner.invoke( + command, + [ + 'module', + 'deps', + '--only-name', + '--exclude-modules', + '--csv-modules', 'c,d', + ] + ) + + modules = set(result.stdout.strip().split('\n')) + assert modules == {'a', 'b'} + + result = runner.invoke( + command, + [ + 'module', + 'deps', + '--only-name', + '--csv-modules', 'c,d', + ] + ) + modules = set(result.stdout.strip().split('\n')) + assert modules == {'a', 'b', 'c', 'd'}