Skip to content

Commit bf84609

Browse files
authored
Merge pull request #14 from manala/feat/exclusify-filter
feat: Add an "exclusify" filter
2 parents de3bf6b + 16bb78d commit bf84609

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- Add a "file" parameter to "path" module
1313
- Add a "find" module
14+
- Add an "exclusify" filter
1415

1516
## [1.1.0] - 2024-09-13
1617

plugins/filter/exclusify.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from __future__ import annotations
2+
3+
4+
def exclusify(value, against):
5+
paths = value
6+
value_paths = {path['path'] for path in value}
7+
8+
for path in against:
9+
if path['path'] not in value_paths:
10+
path['state'] = 'absent'
11+
paths.append(path)
12+
13+
return paths
14+
15+
16+
class FilterModule(object):
17+
''' Manala path exclusify jinja2 filters '''
18+
19+
def filters(self):
20+
return {
21+
"exclusify": exclusify,
22+
}

plugins/filter/exclusify.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
3+
DOCUMENTATION:
4+
name: exclusify
5+
author:
6+
- Manala (@manala)
7+
short_description: Ensure exclusivity against a list of path, by marking the extras as absent
8+
description:
9+
- Ensure exclusivity against a list of path, by marking the extras as absent
10+
positional: _input,against
11+
options:
12+
_input:
13+
description: A list of paths.
14+
type: list
15+
elements: object
16+
required: true
17+
against:
18+
description: A list of paths.
19+
type: list
20+
elements: str
21+
required: true
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from __future__ import annotations
2+
3+
import unittest
4+
from plugins.filter.exclusify import exclusify
5+
6+
7+
class TestExclusify(unittest.TestCase):
8+
9+
def test_exclusify(self):
10+
self.assertEqual(
11+
[
12+
{"path": "foo"},
13+
{"path": "bar"},
14+
{'path': 'baz', 'state': 'absent'},
15+
],
16+
exclusify(
17+
[
18+
{"path": "foo"},
19+
{"path": "bar"},
20+
],
21+
[
22+
{"path": "bar"},
23+
{"path": "baz"},
24+
],
25+
)
26+
)

0 commit comments

Comments
 (0)