Skip to content

Commit c425558

Browse files
committed
Added a way to exclude some modules from the result of dependencies
1 parent 7ac51c6 commit c425558

File tree

2 files changed

+62
-2
lines changed

2 files changed

+62
-2
lines changed

odoo_tools/cli/click/module.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def show_module(ctx, module):
197197
)
198198
@click.option(
199199
'--include-modules',
200-
help="Remove logs and warnings.",
200+
help="Include dependencies that aren't in the addons_paths.",
201201
is_flag=True,
202202
default=False
203203
)
@@ -207,6 +207,12 @@ def show_module(ctx, module):
207207
is_flag=True,
208208
default=False
209209
)
210+
@click.option(
211+
'--exclude-modules',
212+
help="Exclude queried modules from the found dependencies.",
213+
is_flag=True,
214+
default=False
215+
)
210216
@click.pass_context
211217
def show_dependencies(
212218
ctx,
@@ -220,7 +226,8 @@ def show_dependencies(
220226
path,
221227
auto,
222228
quiet,
223-
include_modules
229+
include_modules,
230+
exclude_modules,
224231
):
225232
env = ctx.obj['env']
226233

@@ -278,6 +285,9 @@ def check_module(mod):
278285
mods = [
279286
mod.path.name if only_name else str(mod)
280287
for mod in sorted_dependencies
288+
if (
289+
exclude_modules and mod.path.name not in check_modules
290+
) or not exclude_modules
281291
]
282292

283293
if csv:

tests/cli/test_modules.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from mock import patch, MagicMock
2+
from odoo_tools.cli.odot import command
3+
from odoo_tools.api.environment import Environment
4+
5+
from odoo_tools.api.modules import ModuleApi
6+
from odoo_tools.api.objects import Manifest
7+
8+
9+
def test_module_deps(runner, tmp_path):
10+
11+
with patch.object(ModuleApi, 'list') as list_modules:
12+
13+
list_modules.return_value = [
14+
Manifest(tmp_path / 'a', attrs={'version': 1, 'depends': {}}),
15+
Manifest(tmp_path / 'b', attrs={'version': 1, 'depends': {'a'}}),
16+
Manifest(tmp_path / 'c', attrs={'version': 1, 'depends': {'b'}}),
17+
Manifest(
18+
tmp_path / 'd',
19+
attrs={
20+
'version': 1,
21+
'depends': {'a', 'c'}
22+
}
23+
)
24+
]
25+
26+
result = runner.invoke(
27+
command,
28+
[
29+
'module',
30+
'deps',
31+
'--only-name',
32+
'--exclude-modules',
33+
'--csv-modules', 'c,d',
34+
]
35+
)
36+
37+
modules = set(result.stdout.strip().split('\n'))
38+
assert modules == {'a', 'b'}
39+
40+
result = runner.invoke(
41+
command,
42+
[
43+
'module',
44+
'deps',
45+
'--only-name',
46+
'--csv-modules', 'c,d',
47+
]
48+
)
49+
modules = set(result.stdout.strip().split('\n'))
50+
assert modules == {'a', 'b', 'c', 'd'}

0 commit comments

Comments
 (0)