vcti-attribute-enricher 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- vcti_attribute_enricher-1.0.0/LICENSE +8 -0
- vcti_attribute_enricher-1.0.0/PKG-INFO +213 -0
- vcti_attribute_enricher-1.0.0/README.md +171 -0
- vcti_attribute_enricher-1.0.0/pyproject.toml +79 -0
- vcti_attribute_enricher-1.0.0/setup.cfg +4 -0
- vcti_attribute_enricher-1.0.0/src/vcti/attribute_enricher/__init__.py +19 -0
- vcti_attribute_enricher-1.0.0/src/vcti/attribute_enricher/enricher.py +249 -0
- vcti_attribute_enricher-1.0.0/src/vcti/attribute_enricher/py.typed +0 -0
- vcti_attribute_enricher-1.0.0/src/vcti/attribute_enricher/rule.py +52 -0
- vcti_attribute_enricher-1.0.0/src/vcti_attribute_enricher.egg-info/PKG-INFO +213 -0
- vcti_attribute_enricher-1.0.0/src/vcti_attribute_enricher.egg-info/SOURCES.txt +15 -0
- vcti_attribute_enricher-1.0.0/src/vcti_attribute_enricher.egg-info/dependency_links.txt +1 -0
- vcti_attribute_enricher-1.0.0/src/vcti_attribute_enricher.egg-info/requires.txt +12 -0
- vcti_attribute_enricher-1.0.0/src/vcti_attribute_enricher.egg-info/top_level.txt +1 -0
- vcti_attribute_enricher-1.0.0/tests/test_enricher.py +570 -0
- vcti_attribute_enricher-1.0.0/tests/test_rule.py +77 -0
- vcti_attribute_enricher-1.0.0/tests/test_version.py +25 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
Copyright (c) 2018-2026 Visual Collaboration Technologies Inc.
|
|
2
|
+
All Rights Reserved.
|
|
3
|
+
|
|
4
|
+
This software is proprietary and confidential. Unauthorized copying,
|
|
5
|
+
distribution, or use of this software, via any medium, is strictly
|
|
6
|
+
prohibited. Access is granted only to authorized VCollab developers
|
|
7
|
+
and individuals explicitly authorized by Visual Collaboration
|
|
8
|
+
Technologies Inc.
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: vcti-attribute-enricher
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Rule-based attribute enrichment for any sequence of items
|
|
5
|
+
Author-email: "Visual Collaboration Technologies Inc." <info@vcollab.com>
|
|
6
|
+
License: Copyright (c) 2018-2026 Visual Collaboration Technologies Inc.
|
|
7
|
+
All Rights Reserved.
|
|
8
|
+
|
|
9
|
+
This software is proprietary and confidential. Unauthorized copying,
|
|
10
|
+
distribution, or use of this software, via any medium, is strictly
|
|
11
|
+
prohibited. Access is granted only to authorized VCollab developers
|
|
12
|
+
and individuals explicitly authorized by Visual Collaboration
|
|
13
|
+
Technologies Inc.
|
|
14
|
+
|
|
15
|
+
Project-URL: Homepage, https://github.com/vcollab/vcti-python-attribute-enricher
|
|
16
|
+
Project-URL: Repository, https://github.com/vcollab/vcti-python-attribute-enricher
|
|
17
|
+
Project-URL: Changelog, https://github.com/vcollab/vcti-python-attribute-enricher/blob/main/CHANGELOG.md
|
|
18
|
+
Project-URL: Issues, https://github.com/vcollab/vcti-python-attribute-enricher/issues
|
|
19
|
+
Keywords: attributes,enrichment,rules,vcti,metadata
|
|
20
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
21
|
+
Classifier: Intended Audience :: Developers
|
|
22
|
+
Classifier: Operating System :: OS Independent
|
|
23
|
+
Classifier: Programming Language :: Python :: 3
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
26
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
27
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
28
|
+
Classifier: Typing :: Typed
|
|
29
|
+
Requires-Python: <3.15,>=3.12
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
License-File: LICENSE
|
|
32
|
+
Requires-Dist: vcti-lookup>=1.0.0
|
|
33
|
+
Requires-Dist: vcti-predicate>=1.0.0
|
|
34
|
+
Provides-Extra: test
|
|
35
|
+
Requires-Dist: pytest; extra == "test"
|
|
36
|
+
Requires-Dist: pytest-cov; extra == "test"
|
|
37
|
+
Provides-Extra: lint
|
|
38
|
+
Requires-Dist: ruff; extra == "lint"
|
|
39
|
+
Provides-Extra: typecheck
|
|
40
|
+
Requires-Dist: mypy; extra == "typecheck"
|
|
41
|
+
Dynamic: license-file
|
|
42
|
+
|
|
43
|
+
# Attribute Enricher
|
|
44
|
+
|
|
45
|
+
Rule-based attribute enrichment for any sequence of items.
|
|
46
|
+
|
|
47
|
+
## Overview
|
|
48
|
+
|
|
49
|
+
`vcti-attribute-enricher` adds attributes to items in a sequence by
|
|
50
|
+
matching `vcti-lookup` rules. Each `EnrichRule` pairs a condition
|
|
51
|
+
(`when`) with attributes to write (`set`); the enricher walks an
|
|
52
|
+
iterable, evaluates each rule against each item, and stamps matching
|
|
53
|
+
items with the rule's attributes.
|
|
54
|
+
|
|
55
|
+
The package is iterable-generic, not tree-specific: the items can be
|
|
56
|
+
tree-node payloads (e.g., from `vcti-fileloader`), dicts, dataclasses,
|
|
57
|
+
or any object with an attribute-bearing surface. Reading and writing
|
|
58
|
+
are pluggable via `getter` / `setter` callables, with sensible defaults
|
|
59
|
+
for `vcti-fileloader`'s `DataNode`-shaped payloads.
|
|
60
|
+
|
|
61
|
+
The package is the write-side counterpart to `vcti-lookup`: where
|
|
62
|
+
Lookup filters a sequence by rules, the enricher mutates the sequence
|
|
63
|
+
by rules.
|
|
64
|
+
|
|
65
|
+
## Installation
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
pip install vcti-attribute-enricher
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### In `requirements.txt`
|
|
72
|
+
|
|
73
|
+
```
|
|
74
|
+
vcti-attribute-enricher>=1.0.0
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### In `pyproject.toml` dependencies
|
|
78
|
+
|
|
79
|
+
```toml
|
|
80
|
+
dependencies = [
|
|
81
|
+
"vcti-attribute-enricher>=1.0.0",
|
|
82
|
+
]
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## Quick Start
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
from vcti.attribute_enricher import EnrichRule, apply_rules
|
|
91
|
+
from vcti.lookup import MISSING, Rule
|
|
92
|
+
|
|
93
|
+
items = [
|
|
94
|
+
{"name": "stress.h5", "dtype": "float64", "attributes": {}, "enricher_attributes": {}},
|
|
95
|
+
{"name": "ids.h5", "dtype": "int64", "attributes": {}, "enricher_attributes": {}},
|
|
96
|
+
{"name": "config.json", "dtype": "object", "attributes": {}, "enricher_attributes": {}},
|
|
97
|
+
]
|
|
98
|
+
|
|
99
|
+
def getter(item, key):
|
|
100
|
+
# Read from the item's "attributes" dict, then the top-level item.
|
|
101
|
+
# Return MISSING (not None) when absent so the rule cleanly no-matches.
|
|
102
|
+
if key in item["attributes"]:
|
|
103
|
+
return item["attributes"][key]
|
|
104
|
+
return item.get(key, MISSING)
|
|
105
|
+
|
|
106
|
+
apply_rules(
|
|
107
|
+
items,
|
|
108
|
+
rules=[
|
|
109
|
+
EnrichRule(set={"loaded_at": "2026-06-06"}), # every item
|
|
110
|
+
EnrichRule(set={"category": "mechanical"},
|
|
111
|
+
when=(Rule("name", "^=", "stress"),)), # name starts with "stress"
|
|
112
|
+
EnrichRule(set={"is_numeric": True},
|
|
113
|
+
when=(Rule("dtype", "^=", "float"),
|
|
114
|
+
Rule("dtype", "!=", "object"))), # AND across rules
|
|
115
|
+
],
|
|
116
|
+
getter=getter,
|
|
117
|
+
setter=lambda item, key, value: item["enricher_attributes"].__setitem__(key, value),
|
|
118
|
+
)
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
For payloads with a single mutable attribute dict (the common case):
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
items = [{"name": "x", "tags": {}}, {"name": "y", "tags": {}}]
|
|
125
|
+
|
|
126
|
+
apply_rules(
|
|
127
|
+
items,
|
|
128
|
+
rules=[EnrichRule(set={"seen": True})],
|
|
129
|
+
getter=lambda item, key: item.get(key, MISSING),
|
|
130
|
+
setter=lambda item, key, value: item["tags"].__setitem__(key, value),
|
|
131
|
+
)
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
> Getters must return `vcti.lookup.MISSING` for absent attributes, not
|
|
135
|
+
> `None`. `None` is a legal value that gets passed to the operator;
|
|
136
|
+
> `MISSING` short-circuits the rule to "no match".
|
|
137
|
+
|
|
138
|
+
## Enriching tree-node payloads
|
|
139
|
+
|
|
140
|
+
The package's default getter/setter are tuned for `vcti-fileloader`'s
|
|
141
|
+
`DataNode`/`LazyDataNode` payloads, which carry both a read-only
|
|
142
|
+
`file_attributes` mapping (file-native) and a mutable
|
|
143
|
+
`enricher_attributes` dict. The merged read view is exposed via
|
|
144
|
+
`.attributes` (a `ChainMap`).
|
|
145
|
+
|
|
146
|
+
```python
|
|
147
|
+
from vcti.attribute_enricher import EnrichRule, apply_rules
|
|
148
|
+
from vcti.tree import descendants
|
|
149
|
+
from vcti.lookup import Rule
|
|
150
|
+
|
|
151
|
+
apply_rules(
|
|
152
|
+
descendants(tree, subtree_root, include_self=True),
|
|
153
|
+
rules=[
|
|
154
|
+
EnrichRule(set={"file_path": str(path)}),
|
|
155
|
+
EnrichRule(set={"category": "mechanical"},
|
|
156
|
+
when=(Rule("name", "^=", "stress"),)),
|
|
157
|
+
],
|
|
158
|
+
)
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
No `getter` / `setter` arguments needed — the defaults read
|
|
162
|
+
`item.attributes` (ChainMap) and write to `item.enricher_attributes`.
|
|
163
|
+
|
|
164
|
+
---
|
|
165
|
+
|
|
166
|
+
## How it works
|
|
167
|
+
|
|
168
|
+
1. **Iterate** the supplied items.
|
|
169
|
+
2. For each item, evaluate every `EnrichRule`:
|
|
170
|
+
- If `when` is empty, the rule matches.
|
|
171
|
+
- If `when` has one or more `Rule`s, every rule must match (AND).
|
|
172
|
+
- A rule matches by reading the relevant attribute through `getter`
|
|
173
|
+
and evaluating it via `vcti.predicate.evaluate` (forwarded through
|
|
174
|
+
`vcti-lookup`).
|
|
175
|
+
3. On a match, write each key/value in `set` to the item via `setter`.
|
|
176
|
+
|
|
177
|
+
**Layering — last write wins.** Multiple `EnrichRule`s that match the
|
|
178
|
+
same item all apply, in the order given. Later rules overwrite earlier
|
|
179
|
+
ones on collision. This makes it easy to express "set a default for
|
|
180
|
+
everything, then refine for specific subsets."
|
|
181
|
+
|
|
182
|
+
**Return value.** `apply_rules` returns an `EnrichResult` with summary
|
|
183
|
+
counts — handy for logging and for spotting dead rules:
|
|
184
|
+
|
|
185
|
+
```python
|
|
186
|
+
result = apply_rules(items, rules)
|
|
187
|
+
print(result.items_visited, result.items_matched, result.writes_applied)
|
|
188
|
+
print(result.per_rule_matches) # match count per rule, in order; 0 = dead rule
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
The items are mutated in place; the result carries metrics only.
|
|
192
|
+
|
|
193
|
+
---
|
|
194
|
+
|
|
195
|
+
## API
|
|
196
|
+
|
|
197
|
+
| Symbol | Description |
|
|
198
|
+
|---|---|
|
|
199
|
+
| `EnrichRule(set, when=())` | Frozen dataclass. `set` is a dict of attributes to write; `when` is a `tuple[Rule, ...]` combined with AND logic. Empty `when` matches every item. Not hashable (the `set` dict). |
|
|
200
|
+
| `apply_rules(items, rules, *, getter=None, setter=None)` | Walk `items`, evaluate `rules`, stamp matches. Returns an `EnrichResult`. Defaults to `vcti.lookup.attributes_getter` and a setter that writes to `item.enricher_attributes`. Mutates in place (not thread-safe); raises `ValueError` with rule context if evaluation fails (fail-fast, non-transactional). |
|
|
201
|
+
| `EnrichResult(items_visited, items_matched, writes_applied, per_rule_matches)` | Frozen dataclass of summary counts returned by `apply_rules`. `per_rule_matches` is per-rule, in order (a `0` flags a dead rule). |
|
|
202
|
+
| `Getter` / `Setter` | Type aliases for the `(item, key) -> value` and `(item, key, value) -> None` callables. |
|
|
203
|
+
|
|
204
|
+
Values in `set` are written by reference — a mutable value shared across
|
|
205
|
+
matched items is the same object on each. See [docs/patterns.md](docs/patterns.md)
|
|
206
|
+
for pitfalls.
|
|
207
|
+
|
|
208
|
+
---
|
|
209
|
+
|
|
210
|
+
## Dependencies
|
|
211
|
+
|
|
212
|
+
- [vcti-lookup](https://pypi.org/project/vcti-lookup/) (>=1.0.0) — `Rule`, `MISSING`, default `attributes_getter`
|
|
213
|
+
- [vcti-predicate](https://pypi.org/project/vcti-predicate/) (>=1.0.0) — `evaluate()` is called directly for rule matching
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
# Attribute Enricher
|
|
2
|
+
|
|
3
|
+
Rule-based attribute enrichment for any sequence of items.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
`vcti-attribute-enricher` adds attributes to items in a sequence by
|
|
8
|
+
matching `vcti-lookup` rules. Each `EnrichRule` pairs a condition
|
|
9
|
+
(`when`) with attributes to write (`set`); the enricher walks an
|
|
10
|
+
iterable, evaluates each rule against each item, and stamps matching
|
|
11
|
+
items with the rule's attributes.
|
|
12
|
+
|
|
13
|
+
The package is iterable-generic, not tree-specific: the items can be
|
|
14
|
+
tree-node payloads (e.g., from `vcti-fileloader`), dicts, dataclasses,
|
|
15
|
+
or any object with an attribute-bearing surface. Reading and writing
|
|
16
|
+
are pluggable via `getter` / `setter` callables, with sensible defaults
|
|
17
|
+
for `vcti-fileloader`'s `DataNode`-shaped payloads.
|
|
18
|
+
|
|
19
|
+
The package is the write-side counterpart to `vcti-lookup`: where
|
|
20
|
+
Lookup filters a sequence by rules, the enricher mutates the sequence
|
|
21
|
+
by rules.
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install vcti-attribute-enricher
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### In `requirements.txt`
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
vcti-attribute-enricher>=1.0.0
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### In `pyproject.toml` dependencies
|
|
36
|
+
|
|
37
|
+
```toml
|
|
38
|
+
dependencies = [
|
|
39
|
+
"vcti-attribute-enricher>=1.0.0",
|
|
40
|
+
]
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## Quick Start
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
from vcti.attribute_enricher import EnrichRule, apply_rules
|
|
49
|
+
from vcti.lookup import MISSING, Rule
|
|
50
|
+
|
|
51
|
+
items = [
|
|
52
|
+
{"name": "stress.h5", "dtype": "float64", "attributes": {}, "enricher_attributes": {}},
|
|
53
|
+
{"name": "ids.h5", "dtype": "int64", "attributes": {}, "enricher_attributes": {}},
|
|
54
|
+
{"name": "config.json", "dtype": "object", "attributes": {}, "enricher_attributes": {}},
|
|
55
|
+
]
|
|
56
|
+
|
|
57
|
+
def getter(item, key):
|
|
58
|
+
# Read from the item's "attributes" dict, then the top-level item.
|
|
59
|
+
# Return MISSING (not None) when absent so the rule cleanly no-matches.
|
|
60
|
+
if key in item["attributes"]:
|
|
61
|
+
return item["attributes"][key]
|
|
62
|
+
return item.get(key, MISSING)
|
|
63
|
+
|
|
64
|
+
apply_rules(
|
|
65
|
+
items,
|
|
66
|
+
rules=[
|
|
67
|
+
EnrichRule(set={"loaded_at": "2026-06-06"}), # every item
|
|
68
|
+
EnrichRule(set={"category": "mechanical"},
|
|
69
|
+
when=(Rule("name", "^=", "stress"),)), # name starts with "stress"
|
|
70
|
+
EnrichRule(set={"is_numeric": True},
|
|
71
|
+
when=(Rule("dtype", "^=", "float"),
|
|
72
|
+
Rule("dtype", "!=", "object"))), # AND across rules
|
|
73
|
+
],
|
|
74
|
+
getter=getter,
|
|
75
|
+
setter=lambda item, key, value: item["enricher_attributes"].__setitem__(key, value),
|
|
76
|
+
)
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
For payloads with a single mutable attribute dict (the common case):
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
items = [{"name": "x", "tags": {}}, {"name": "y", "tags": {}}]
|
|
83
|
+
|
|
84
|
+
apply_rules(
|
|
85
|
+
items,
|
|
86
|
+
rules=[EnrichRule(set={"seen": True})],
|
|
87
|
+
getter=lambda item, key: item.get(key, MISSING),
|
|
88
|
+
setter=lambda item, key, value: item["tags"].__setitem__(key, value),
|
|
89
|
+
)
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
> Getters must return `vcti.lookup.MISSING` for absent attributes, not
|
|
93
|
+
> `None`. `None` is a legal value that gets passed to the operator;
|
|
94
|
+
> `MISSING` short-circuits the rule to "no match".
|
|
95
|
+
|
|
96
|
+
## Enriching tree-node payloads
|
|
97
|
+
|
|
98
|
+
The package's default getter/setter are tuned for `vcti-fileloader`'s
|
|
99
|
+
`DataNode`/`LazyDataNode` payloads, which carry both a read-only
|
|
100
|
+
`file_attributes` mapping (file-native) and a mutable
|
|
101
|
+
`enricher_attributes` dict. The merged read view is exposed via
|
|
102
|
+
`.attributes` (a `ChainMap`).
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
from vcti.attribute_enricher import EnrichRule, apply_rules
|
|
106
|
+
from vcti.tree import descendants
|
|
107
|
+
from vcti.lookup import Rule
|
|
108
|
+
|
|
109
|
+
apply_rules(
|
|
110
|
+
descendants(tree, subtree_root, include_self=True),
|
|
111
|
+
rules=[
|
|
112
|
+
EnrichRule(set={"file_path": str(path)}),
|
|
113
|
+
EnrichRule(set={"category": "mechanical"},
|
|
114
|
+
when=(Rule("name", "^=", "stress"),)),
|
|
115
|
+
],
|
|
116
|
+
)
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
No `getter` / `setter` arguments needed — the defaults read
|
|
120
|
+
`item.attributes` (ChainMap) and write to `item.enricher_attributes`.
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## How it works
|
|
125
|
+
|
|
126
|
+
1. **Iterate** the supplied items.
|
|
127
|
+
2. For each item, evaluate every `EnrichRule`:
|
|
128
|
+
- If `when` is empty, the rule matches.
|
|
129
|
+
- If `when` has one or more `Rule`s, every rule must match (AND).
|
|
130
|
+
- A rule matches by reading the relevant attribute through `getter`
|
|
131
|
+
and evaluating it via `vcti.predicate.evaluate` (forwarded through
|
|
132
|
+
`vcti-lookup`).
|
|
133
|
+
3. On a match, write each key/value in `set` to the item via `setter`.
|
|
134
|
+
|
|
135
|
+
**Layering — last write wins.** Multiple `EnrichRule`s that match the
|
|
136
|
+
same item all apply, in the order given. Later rules overwrite earlier
|
|
137
|
+
ones on collision. This makes it easy to express "set a default for
|
|
138
|
+
everything, then refine for specific subsets."
|
|
139
|
+
|
|
140
|
+
**Return value.** `apply_rules` returns an `EnrichResult` with summary
|
|
141
|
+
counts — handy for logging and for spotting dead rules:
|
|
142
|
+
|
|
143
|
+
```python
|
|
144
|
+
result = apply_rules(items, rules)
|
|
145
|
+
print(result.items_visited, result.items_matched, result.writes_applied)
|
|
146
|
+
print(result.per_rule_matches) # match count per rule, in order; 0 = dead rule
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
The items are mutated in place; the result carries metrics only.
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## API
|
|
154
|
+
|
|
155
|
+
| Symbol | Description |
|
|
156
|
+
|---|---|
|
|
157
|
+
| `EnrichRule(set, when=())` | Frozen dataclass. `set` is a dict of attributes to write; `when` is a `tuple[Rule, ...]` combined with AND logic. Empty `when` matches every item. Not hashable (the `set` dict). |
|
|
158
|
+
| `apply_rules(items, rules, *, getter=None, setter=None)` | Walk `items`, evaluate `rules`, stamp matches. Returns an `EnrichResult`. Defaults to `vcti.lookup.attributes_getter` and a setter that writes to `item.enricher_attributes`. Mutates in place (not thread-safe); raises `ValueError` with rule context if evaluation fails (fail-fast, non-transactional). |
|
|
159
|
+
| `EnrichResult(items_visited, items_matched, writes_applied, per_rule_matches)` | Frozen dataclass of summary counts returned by `apply_rules`. `per_rule_matches` is per-rule, in order (a `0` flags a dead rule). |
|
|
160
|
+
| `Getter` / `Setter` | Type aliases for the `(item, key) -> value` and `(item, key, value) -> None` callables. |
|
|
161
|
+
|
|
162
|
+
Values in `set` are written by reference — a mutable value shared across
|
|
163
|
+
matched items is the same object on each. See [docs/patterns.md](docs/patterns.md)
|
|
164
|
+
for pitfalls.
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
## Dependencies
|
|
169
|
+
|
|
170
|
+
- [vcti-lookup](https://pypi.org/project/vcti-lookup/) (>=1.0.0) — `Rule`, `MISSING`, default `attributes_getter`
|
|
171
|
+
- [vcti-predicate](https://pypi.org/project/vcti-predicate/) (>=1.0.0) — `evaluate()` is called directly for rule matching
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "vcti-attribute-enricher"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "Rule-based attribute enrichment for any sequence of items"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
authors = [
|
|
11
|
+
{name = "Visual Collaboration Technologies Inc.", email = "info@vcollab.com"}
|
|
12
|
+
]
|
|
13
|
+
requires-python = ">=3.12,<3.15"
|
|
14
|
+
license = {file = "LICENSE"}
|
|
15
|
+
keywords = ["attributes", "enrichment", "rules", "vcti", "metadata"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 5 - Production/Stable",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"Operating System :: OS Independent",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.12",
|
|
22
|
+
"Programming Language :: Python :: 3.13",
|
|
23
|
+
"Programming Language :: Python :: 3.14",
|
|
24
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
25
|
+
"Typing :: Typed",
|
|
26
|
+
]
|
|
27
|
+
dependencies = [
|
|
28
|
+
"vcti-lookup>=1.0.0",
|
|
29
|
+
"vcti-predicate>=1.0.0",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[project.urls]
|
|
33
|
+
Homepage = "https://github.com/vcollab/vcti-python-attribute-enricher"
|
|
34
|
+
Repository = "https://github.com/vcollab/vcti-python-attribute-enricher"
|
|
35
|
+
Changelog = "https://github.com/vcollab/vcti-python-attribute-enricher/blob/main/CHANGELOG.md"
|
|
36
|
+
Issues = "https://github.com/vcollab/vcti-python-attribute-enricher/issues"
|
|
37
|
+
|
|
38
|
+
[tool.setuptools.packages.find]
|
|
39
|
+
where = ["src"]
|
|
40
|
+
include = ["vcti.attribute_enricher", "vcti.attribute_enricher.*"]
|
|
41
|
+
|
|
42
|
+
[tool.setuptools.package-data]
|
|
43
|
+
"vcti.attribute_enricher" = ["py.typed"]
|
|
44
|
+
|
|
45
|
+
[project.optional-dependencies]
|
|
46
|
+
test = ["pytest", "pytest-cov"]
|
|
47
|
+
lint = ["ruff"]
|
|
48
|
+
typecheck = ["mypy"]
|
|
49
|
+
|
|
50
|
+
[tool.pytest.ini_options]
|
|
51
|
+
testpaths = ["src", "tests"]
|
|
52
|
+
addopts = "--cov=src/vcti/attribute_enricher --cov-report=term-missing --cov-fail-under=95 --doctest-modules --import-mode=importlib"
|
|
53
|
+
|
|
54
|
+
[tool.mypy]
|
|
55
|
+
python_version = "3.12"
|
|
56
|
+
strict = true
|
|
57
|
+
files = ["src"]
|
|
58
|
+
namespace_packages = true
|
|
59
|
+
explicit_package_bases = true
|
|
60
|
+
mypy_path = ["src"]
|
|
61
|
+
|
|
62
|
+
[tool.coverage.run]
|
|
63
|
+
branch = true
|
|
64
|
+
|
|
65
|
+
[tool.coverage.report]
|
|
66
|
+
exclude_also = [
|
|
67
|
+
"raise NotImplementedError",
|
|
68
|
+
"if TYPE_CHECKING:",
|
|
69
|
+
"if __name__ == .__main__.:",
|
|
70
|
+
"@(abc\\.)?abstractmethod",
|
|
71
|
+
"\\.\\.\\.",
|
|
72
|
+
]
|
|
73
|
+
|
|
74
|
+
[tool.ruff]
|
|
75
|
+
target-version = "py312"
|
|
76
|
+
line-length = 99
|
|
77
|
+
|
|
78
|
+
[tool.ruff.lint]
|
|
79
|
+
select = ["E", "F", "W", "I", "UP"]
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Copyright Visual Collaboration Technologies Inc. All Rights Reserved.
|
|
2
|
+
# See LICENSE for details.
|
|
3
|
+
"""vcti.attribute_enricher — Rule-based attribute enrichment for any sequence of items."""
|
|
4
|
+
|
|
5
|
+
from importlib.metadata import version
|
|
6
|
+
|
|
7
|
+
from .enricher import EnrichResult, Getter, Setter, apply_rules
|
|
8
|
+
from .rule import EnrichRule
|
|
9
|
+
|
|
10
|
+
__version__ = version("vcti-attribute-enricher")
|
|
11
|
+
|
|
12
|
+
__all__ = [
|
|
13
|
+
"__version__",
|
|
14
|
+
"EnrichResult",
|
|
15
|
+
"EnrichRule",
|
|
16
|
+
"Getter",
|
|
17
|
+
"Setter",
|
|
18
|
+
"apply_rules",
|
|
19
|
+
]
|