Skip to content

Commit

Permalink
Added a way to exclude some modules from the result of dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
llacroix committed Jul 6, 2023
1 parent 7ac51c6 commit 32f3f83
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
14 changes: 12 additions & 2 deletions odoo_tools/cli/click/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -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,
Expand All @@ -220,7 +226,8 @@ def show_dependencies(
path,
auto,
quiet,
include_modules
include_modules,
exclude_modules,
):
env = ctx.obj['env']

Expand Down Expand Up @@ -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:
Expand Down
50 changes: 50 additions & 0 deletions tests/cli/test_modules.py
Original file line number Diff line number Diff line change
@@ -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'}

0 comments on commit 32f3f83

Please sign in to comment.