subtrix 0.0.0__tar.gz → 0.0.1.post4__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.
- subtrix-0.0.1.post4/.gitignore +162 -0
- subtrix-0.0.1.post4/ARCHITECTURE.md +34 -0
- subtrix-0.0.1.post4/CONTRIBUTING.md +43 -0
- subtrix-0.0.1.post4/LICENSE +1 -0
- subtrix-0.0.1.post4/LICENSE.rst +11 -0
- subtrix-0.0.1.post4/PKG-INFO +168 -0
- subtrix-0.0.1.post4/README.md +152 -0
- subtrix-0.0.1.post4/STATE.md +87 -0
- subtrix-0.0.1.post4/__init__.py +25 -0
- subtrix-0.0.1.post4/cmds/runSubtrix.py +61 -0
- subtrix-0.0.1.post4/cmds/runTest.py +71 -0
- subtrix-0.0.1.post4/pyproject.toml +131 -0
- subtrix-0.0.1.post4/subtrix/__init__.py +39 -0
- subtrix-0.0.1.post4/subtrix/_data_/factorial.yaml +83 -0
- subtrix-0.0.1.post4/subtrix/_data_/loop.yaml +78 -0
- subtrix-0.0.1.post4/subtrix/_data_/sub.yaml +113 -0
- subtrix-0.0.1.post4/subtrix/_data_/subtrix.yaml +32 -0
- subtrix-0.0.1.post4/subtrix/_data_/varr.yaml +113 -0
- subtrix-0.0.1.post4/subtrix/cli.py +158 -0
- subtrix-0.0.1.post4/subtrix/errors.py +59 -0
- subtrix-0.0.1.post4/subtrix/subtrix.py +904 -0
- subtrix-0.0.1.post4/subtrix/utilities/__init__.py +194 -0
- subtrix-0.0.1.post4/subtrix.yaml +28 -0
- subtrix-0.0.0/LICENSE +0 -21
- subtrix-0.0.0/PKG-INFO +0 -59
- subtrix-0.0.0/README.md +0 -39
- subtrix-0.0.0/pyproject.toml +0 -25
- subtrix-0.0.0/setup.cfg +0 -4
- subtrix-0.0.0/subtrix/__init__.py +0 -8
- subtrix-0.0.0/subtrix.egg-info/PKG-INFO +0 -59
- subtrix-0.0.0/subtrix.egg-info/SOURCES.txt +0 -8
- subtrix-0.0.0/subtrix.egg-info/dependency_links.txt +0 -1
- subtrix-0.0.0/subtrix.egg-info/top_level.txt +0 -1
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
*.so
|
|
6
|
+
|
|
7
|
+
# Distribution / packaging
|
|
8
|
+
.Python
|
|
9
|
+
build/
|
|
10
|
+
develop-eggs/
|
|
11
|
+
dist/
|
|
12
|
+
downloads/
|
|
13
|
+
eggs/
|
|
14
|
+
.eggs/
|
|
15
|
+
lib/
|
|
16
|
+
lib64/
|
|
17
|
+
parts/
|
|
18
|
+
sdist/
|
|
19
|
+
var/
|
|
20
|
+
wheels/
|
|
21
|
+
pip-wheel-metadata/
|
|
22
|
+
share/python-wheels/
|
|
23
|
+
*.egg-info/
|
|
24
|
+
.installed.cfg
|
|
25
|
+
*.egg
|
|
26
|
+
MANIFEST
|
|
27
|
+
|
|
28
|
+
# PyInstaller
|
|
29
|
+
*.manifest
|
|
30
|
+
*.spec
|
|
31
|
+
|
|
32
|
+
# Installer logs
|
|
33
|
+
pip-log.txt
|
|
34
|
+
pip-delete-this-directory.txt
|
|
35
|
+
|
|
36
|
+
# Unit test / coverage reports
|
|
37
|
+
htmlcov/
|
|
38
|
+
.tox/
|
|
39
|
+
.nox/
|
|
40
|
+
.coverage
|
|
41
|
+
.coverage.*
|
|
42
|
+
.cache
|
|
43
|
+
nosetests.xml
|
|
44
|
+
coverage.xml
|
|
45
|
+
*.cover
|
|
46
|
+
*.py,cover
|
|
47
|
+
.hypothesis/
|
|
48
|
+
.pytest_cache/
|
|
49
|
+
|
|
50
|
+
# Translations
|
|
51
|
+
*.mo
|
|
52
|
+
*.pot
|
|
53
|
+
|
|
54
|
+
# Django stuff:
|
|
55
|
+
*.log
|
|
56
|
+
local_settings.py
|
|
57
|
+
db.sqlite3
|
|
58
|
+
db.sqlite3-journal
|
|
59
|
+
|
|
60
|
+
# Flask stuff:
|
|
61
|
+
instance/
|
|
62
|
+
.webassets-cache
|
|
63
|
+
|
|
64
|
+
# Scrapy stuff:
|
|
65
|
+
.scrapy
|
|
66
|
+
|
|
67
|
+
# Sphinx documentation
|
|
68
|
+
docs/_build/
|
|
69
|
+
|
|
70
|
+
# PyBuilder
|
|
71
|
+
target/
|
|
72
|
+
|
|
73
|
+
# Jupyter Notebook
|
|
74
|
+
.ipynb_checkpoints
|
|
75
|
+
|
|
76
|
+
# IPython
|
|
77
|
+
profile_default/
|
|
78
|
+
ipython_config.py
|
|
79
|
+
|
|
80
|
+
# pyenv
|
|
81
|
+
.python-version
|
|
82
|
+
|
|
83
|
+
# pipenv
|
|
84
|
+
Pipfile.lock
|
|
85
|
+
|
|
86
|
+
# PEP 582
|
|
87
|
+
__pypackages__/
|
|
88
|
+
|
|
89
|
+
# Celery stuff
|
|
90
|
+
celerybeat-schedule
|
|
91
|
+
celerybeat.pid
|
|
92
|
+
|
|
93
|
+
# SageMath parsed files
|
|
94
|
+
*.sage.py
|
|
95
|
+
|
|
96
|
+
# Environments
|
|
97
|
+
.env
|
|
98
|
+
.venv
|
|
99
|
+
env/
|
|
100
|
+
venv/
|
|
101
|
+
ENV/
|
|
102
|
+
env.bak/
|
|
103
|
+
venv.bak/
|
|
104
|
+
venvs/
|
|
105
|
+
|
|
106
|
+
# Spyder project settings
|
|
107
|
+
.spyderproject
|
|
108
|
+
.spyproject
|
|
109
|
+
|
|
110
|
+
# Rope project settings
|
|
111
|
+
.ropeproject
|
|
112
|
+
|
|
113
|
+
# mkdocs documentation
|
|
114
|
+
/site
|
|
115
|
+
|
|
116
|
+
# mypy
|
|
117
|
+
.mypy_cache/
|
|
118
|
+
.dmypy.json
|
|
119
|
+
dmypy.json
|
|
120
|
+
|
|
121
|
+
# Pyre type checker
|
|
122
|
+
.pyre/
|
|
123
|
+
|
|
124
|
+
# IDEs
|
|
125
|
+
.idea/
|
|
126
|
+
.vscode/
|
|
127
|
+
*.swp
|
|
128
|
+
*.swo
|
|
129
|
+
*~
|
|
130
|
+
|
|
131
|
+
# OS
|
|
132
|
+
.DS_Store
|
|
133
|
+
Thumbs.db
|
|
134
|
+
|
|
135
|
+
# Project specific
|
|
136
|
+
*.state
|
|
137
|
+
.assets
|
|
138
|
+
*.pyo
|
|
139
|
+
*.pyd
|
|
140
|
+
*.pyw
|
|
141
|
+
*.pyz
|
|
142
|
+
*.pywz
|
|
143
|
+
*.pyzz
|
|
144
|
+
poetry.lock
|
|
145
|
+
botpy.log
|
|
146
|
+
|
|
147
|
+
# Syncthing conflict and temporary files
|
|
148
|
+
*.sync-conflict-*
|
|
149
|
+
*.tmp
|
|
150
|
+
.syncthing.*
|
|
151
|
+
|
|
152
|
+
# Falcon test orchestrator side effects (regenerated on every audit)
|
|
153
|
+
FALCON_TEST.yaml
|
|
154
|
+
test_reports/
|
|
155
|
+
|
|
156
|
+
# Specific project directories
|
|
157
|
+
/cmds/
|
|
158
|
+
/dev/
|
|
159
|
+
/zz-*/
|
|
160
|
+
|
|
161
|
+
# Catch-all for hidden files/folders in root (optional, if intended)
|
|
162
|
+
/.*
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Subtrix Architecture
|
|
2
|
+
|
|
3
|
+
## Purpose
|
|
4
|
+
Subtrix is a lightweight templating engine. It parses and evaluates substitution patterns, variables, functions, loops, and nested data, while exposing deterministic utility generators for template authors.
|
|
5
|
+
|
|
6
|
+
## Layers/Modules
|
|
7
|
+
- `subtrix/subtrix.py`: `Mechanism`, parsing, evaluation, and rendering.
|
|
8
|
+
- `subtrix/errors.py`: typed processing/configuration errors.
|
|
9
|
+
- `subtrix/utilities/`: date/time, UUID, and documentation helpers.
|
|
10
|
+
- `subtrix/cli.py`, `cmds/`: command-line runners.
|
|
11
|
+
|
|
12
|
+
## Public API
|
|
13
|
+
`Mechanism`, `SubtrixError`, `PatternNotFoundError`, `InvalidDataTypeError`, `ConfigurationError`, `TemplateProcessingError`, `DependencyError`, `now`, `today`, `uuid_generator`, and `get_doc` are exported from `subtrix`.
|
|
14
|
+
|
|
15
|
+
## Entry points
|
|
16
|
+
```bash
|
|
17
|
+
python -m subtrix.cli --help
|
|
18
|
+
python cmds/runSubtrix.py --help
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Dependencies
|
|
22
|
+
Primarily standalone; Kahndor-style YAML/config loading may be used by integrations. GoaLT and other sibling systems can use it for rendering reports or prompts.
|
|
23
|
+
|
|
24
|
+
## Config
|
|
25
|
+
`subtrix/_data_/*.yaml` contains examples and defaults for substitution, loops, variables, and factorial/function behavior. `subtrix.yaml` is the top-level configuration.
|
|
26
|
+
|
|
27
|
+
## Tests
|
|
28
|
+
```bash
|
|
29
|
+
pytest
|
|
30
|
+
pytest tests/tests/unit/test_subtrix -q
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Cross-repo interactions
|
|
34
|
+
Consumers pass templates and data into `Mechanism`; GoaLT reports and other ecosystem-generated documents are natural integration points. Keep pattern syntax backward compatible.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Contributing to Subtrix
|
|
2
|
+
|
|
3
|
+
Thanks for your interest in contributing. Subtrix is a lightweight templating
|
|
4
|
+
engine that is intentionally small — most contributions fall into one of
|
|
5
|
+
three buckets:
|
|
6
|
+
|
|
7
|
+
## 1. Bug reports
|
|
8
|
+
|
|
9
|
+
Open a GitHub issue with:
|
|
10
|
+
|
|
11
|
+
- A minimal reproduction (template + data + observed vs. expected output).
|
|
12
|
+
- Python version, Subtrix version, and any configuration in use.
|
|
13
|
+
- Stack trace, if applicable.
|
|
14
|
+
|
|
15
|
+
## 2. New patterns
|
|
16
|
+
|
|
17
|
+
Before proposing a new pattern syntax:
|
|
18
|
+
|
|
19
|
+
- Check `ARCHITECTURE.md` for the current pattern grammar.
|
|
20
|
+
- Open an issue first to discuss the syntax — pattern compatibility is a
|
|
21
|
+
hard constraint for downstream consumers (GoaLT, Condor).
|
|
22
|
+
- Add a test in `tests/unit/` covering the new pattern.
|
|
23
|
+
|
|
24
|
+
## 3. Internal refactors
|
|
25
|
+
|
|
26
|
+
- Keep the public API surface in `subtrix/__init__.py` stable.
|
|
27
|
+
- Add type annotations on any new functions (`mypy --strict-subtrix` is a
|
|
28
|
+
release gate).
|
|
29
|
+
- Run `pytest tests/ -v` and `ruff check subtrix/` locally before pushing.
|
|
30
|
+
|
|
31
|
+
## Workflow
|
|
32
|
+
|
|
33
|
+
1. Fork and create a feature branch: `git checkout -b feature/<name>`.
|
|
34
|
+
2. Commit with a descriptive message.
|
|
35
|
+
3. Push and open a pull request against `gamma`.
|
|
36
|
+
4. Wait for CI to pass and a reviewer to approve.
|
|
37
|
+
|
|
38
|
+
## Code style
|
|
39
|
+
|
|
40
|
+
- Python 3.7+ compatibility (the project floor).
|
|
41
|
+
- Type annotations on every public function.
|
|
42
|
+
- Google-style docstrings.
|
|
43
|
+
- Logging via `kahndor.logma`, never `print()`.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
LICENSE.rst
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Copyright 2025 SolutionsBrewer
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
|
4
|
+
documentation files (the “Software”), to deal in the Software without restriction, including without limitation the
|
|
5
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
6
|
+
persons to whom the Software is furnished to do so.
|
|
7
|
+
|
|
8
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
|
9
|
+
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
10
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
11
|
+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: subtrix
|
|
3
|
+
Version: 0.0.1.post4
|
|
4
|
+
Summary: Template Substitution Processor
|
|
5
|
+
Author: Maintainers
|
|
6
|
+
Author-email: solubrew@solutionsbrewer.com
|
|
7
|
+
License: MIT
|
|
8
|
+
Requires-Python: >=3.7
|
|
9
|
+
Requires-Dist: backoff==2.2.1
|
|
10
|
+
Requires-Dist: click==8.3.3
|
|
11
|
+
Requires-Dist: defusedxml; platform_system == "Windows"
|
|
12
|
+
Requires-Dist: futures; python_version < "3"
|
|
13
|
+
Requires-Dist: six; platform_system == "Linux" and python_version > "3.3"
|
|
14
|
+
Requires-Dist: pypiwin32; platform_system == "Windows"
|
|
15
|
+
Requires-Dist: uuid_extensions==0.1.0
|
|
16
|
+
Description: # Subtrix
|
|
17
|
+
|
|
18
|
+
## Project overview
|
|
19
|
+
|
|
20
|
+
Subtrix is a substitution module for Python, providing powerful tools for text
|
|
21
|
+
manipulation through substitutions. The main interface is the `Mechanism` class,
|
|
22
|
+
which allows for standard substitution, term expansion, and variable
|
|
23
|
+
substitution.
|
|
24
|
+
|
|
25
|
+
Subtrix is part of the Solutions Brewer (SB) stack and is consumed by sibling
|
|
26
|
+
projects such as **GoaLT** (report rendering) and **Condor** (prompt
|
|
27
|
+
templating). It is designed to be:
|
|
28
|
+
|
|
29
|
+
- **Deterministic** — given the same template and data, output is byte-stable.
|
|
30
|
+
- **Composable** — the public API is a single class with a small surface.
|
|
31
|
+
- **Safe** — built-in security validation (max size, max recursion, dangerous
|
|
32
|
+
pattern deny-list).
|
|
33
|
+
- **Lightweight** — minimal dependencies, no template precompilation step.
|
|
34
|
+
|
|
35
|
+
See [ARCHITECTURE.md](ARCHITECTURE.md) for the full design and
|
|
36
|
+
[CLI.md](CLI.md) for the command-line interface.
|
|
37
|
+
|
|
38
|
+
## Features
|
|
39
|
+
|
|
40
|
+
- Provides a basic substitution mechanism
|
|
41
|
+
- Supports variable substitution
|
|
42
|
+
- Supports lists of variables to generate multiple documents from a single template
|
|
43
|
+
- Supports term expansion by using term looping substitution all combinations of a list of terms can be generated
|
|
44
|
+
- Provides Prefix and Suffix Support with controls for trailing suffix
|
|
45
|
+
|
|
46
|
+
## Installation
|
|
47
|
+
|
|
48
|
+
You can install Subtrix via pip:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
pip install subtrix
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Alternatively, clone the repository and install from source:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
git clone https://github.com/solubrew/subtrix.git
|
|
58
|
+
cd subtrix
|
|
59
|
+
pip install -e .
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Requirements
|
|
63
|
+
|
|
64
|
+
- Python 3.<MIN_VERSION> or higher
|
|
65
|
+
- Dependencies: re, <EVAL_LIB> (automatically installed via pip where applicable)
|
|
66
|
+
|
|
67
|
+
## Quick Start
|
|
68
|
+
|
|
69
|
+
Import the module and use the Mechanism class for substitutions:
|
|
70
|
+
|
|
71
|
+
## Standard Patterns
|
|
72
|
+
|
|
73
|
+
### Substitution:
|
|
74
|
+
|
|
75
|
+
<[token]>: basic substitution
|
|
76
|
+
<~[token]~>: optional token substituion (is removed if unused in template render)
|
|
77
|
+
<[prefix.:token]>: token substitution with prefix
|
|
78
|
+
<[token:.suffix]>: token substitution with suffix
|
|
79
|
+
|
|
80
|
+
### Variable Substitution:
|
|
81
|
+
|
|
82
|
+
<(token)>: registerd variable lookup for things like TODAY, USER, etc.
|
|
83
|
+
<(prefix.:token)>: optional variable token substituion
|
|
84
|
+
<(token:.suffix)>: optional variable token substituion
|
|
85
|
+
|
|
86
|
+
### Looped Variable Substitution:
|
|
87
|
+
|
|
88
|
+
token: ['point0', 'point1']
|
|
89
|
+
<@[token]@>: [['point0'], ['point1'], ['point0', 'point1']
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
from subtrix import Mechanism
|
|
93
|
+
|
|
94
|
+
# Initialize Mechanism
|
|
95
|
+
template = 'Hello, <[name]>!'
|
|
96
|
+
data = {'name': 'World'}
|
|
97
|
+
mech = Mechanism(template, data)
|
|
98
|
+
|
|
99
|
+
# Perform standard substitution
|
|
100
|
+
result = mech.run()
|
|
101
|
+
print(result) # Output: Hello, World!
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Usage
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
### Variable Substitution
|
|
108
|
+
|
|
109
|
+
Inject variables from various sources:
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
## Development
|
|
113
|
+
|
|
114
|
+
To set up a development environment and run the test suite locally:
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
# Clone and install in editable mode with dev extras
|
|
118
|
+
git clone https://github.com/solubrew/subtrix.git
|
|
119
|
+
cd subtrix
|
|
120
|
+
python -m pip install --upgrade pip
|
|
121
|
+
pip install -e ".[dev]"
|
|
122
|
+
pip install pytest pytest-asyncio
|
|
123
|
+
|
|
124
|
+
# Run the test suite
|
|
125
|
+
pytest tests/ -v
|
|
126
|
+
|
|
127
|
+
# Lint (matches CI)
|
|
128
|
+
ruff check subtrix/
|
|
129
|
+
|
|
130
|
+
# Confirm the package imports cleanly
|
|
131
|
+
python -c "import subtrix; print('Import OK:', subtrix.__name__)"
|
|
132
|
+
|
|
133
|
+
# Render a template from the CLI
|
|
134
|
+
python -m subtrix.cli subtrix "Hello <[name]>!" '{"name": "World"}'
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Before opening a pull request, also run the compliance auditor to verify the
|
|
138
|
+
project is in a releasable state:
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
PYTHONPATH=...:$TASKAXN_PYTHONPATH python -m sasquatch.cli analyze \
|
|
142
|
+
-p . --agent m3rl1n --skip-pii-secrets
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
A score of **>= 90 %** is required to tag a release. See
|
|
146
|
+
[CI_CD.md](CI_CD.md) for the full pipeline description.
|
|
147
|
+
|
|
148
|
+
## Contributing
|
|
149
|
+
|
|
150
|
+
Contributions are welcome! Please follow these steps:
|
|
151
|
+
|
|
152
|
+
1. Fork the repository.
|
|
153
|
+
2. Create a feature branch (`git checkout -b feature/<FEATURE_NAME>`).
|
|
154
|
+
3. Commit your changes (`git commit -am 'Add some feature'`).
|
|
155
|
+
4. Push to the branch (`git push origin feature/<FEATURE_NAME>`).
|
|
156
|
+
5. Open a Pull Request.
|
|
157
|
+
|
|
158
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for more details.
|
|
159
|
+
|
|
160
|
+
## License
|
|
161
|
+
|
|
162
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE.rst) file for details.
|
|
163
|
+
|
|
164
|
+
## Acknowledgments
|
|
165
|
+
|
|
166
|
+
- Built with inspiration from open-source templating and substitution libraries.
|
|
167
|
+
- Thanks to contributors of underlying libraries like re, and Python's built-in eval.
|
|
168
|
+
Description-Content-Type: text/markdown
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# Subtrix
|
|
2
|
+
|
|
3
|
+
## Project overview
|
|
4
|
+
|
|
5
|
+
Subtrix is a substitution module for Python, providing powerful tools for text
|
|
6
|
+
manipulation through substitutions. The main interface is the `Mechanism` class,
|
|
7
|
+
which allows for standard substitution, term expansion, and variable
|
|
8
|
+
substitution.
|
|
9
|
+
|
|
10
|
+
Subtrix is part of the Solutions Brewer (SB) stack and is consumed by sibling
|
|
11
|
+
projects such as **GoaLT** (report rendering) and **Condor** (prompt
|
|
12
|
+
templating). It is designed to be:
|
|
13
|
+
|
|
14
|
+
- **Deterministic** — given the same template and data, output is byte-stable.
|
|
15
|
+
- **Composable** — the public API is a single class with a small surface.
|
|
16
|
+
- **Safe** — built-in security validation (max size, max recursion, dangerous
|
|
17
|
+
pattern deny-list).
|
|
18
|
+
- **Lightweight** — minimal dependencies, no template precompilation step.
|
|
19
|
+
|
|
20
|
+
See [ARCHITECTURE.md](ARCHITECTURE.md) for the full design and
|
|
21
|
+
[CLI.md](CLI.md) for the command-line interface.
|
|
22
|
+
|
|
23
|
+
## Features
|
|
24
|
+
|
|
25
|
+
- Provides a basic substitution mechanism
|
|
26
|
+
- Supports variable substitution
|
|
27
|
+
- Supports lists of variables to generate multiple documents from a single template
|
|
28
|
+
- Supports term expansion by using term looping substitution all combinations of a list of terms can be generated
|
|
29
|
+
- Provides Prefix and Suffix Support with controls for trailing suffix
|
|
30
|
+
|
|
31
|
+
## Installation
|
|
32
|
+
|
|
33
|
+
You can install Subtrix via pip:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
pip install subtrix
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Alternatively, clone the repository and install from source:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
git clone https://github.com/solubrew/subtrix.git
|
|
43
|
+
cd subtrix
|
|
44
|
+
pip install -e .
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Requirements
|
|
48
|
+
|
|
49
|
+
- Python 3.<MIN_VERSION> or higher
|
|
50
|
+
- Dependencies: re, <EVAL_LIB> (automatically installed via pip where applicable)
|
|
51
|
+
|
|
52
|
+
## Quick Start
|
|
53
|
+
|
|
54
|
+
Import the module and use the Mechanism class for substitutions:
|
|
55
|
+
|
|
56
|
+
## Standard Patterns
|
|
57
|
+
|
|
58
|
+
### Substitution:
|
|
59
|
+
|
|
60
|
+
<[token]>: basic substitution
|
|
61
|
+
<~[token]~>: optional token substituion (is removed if unused in template render)
|
|
62
|
+
<[prefix.:token]>: token substitution with prefix
|
|
63
|
+
<[token:.suffix]>: token substitution with suffix
|
|
64
|
+
|
|
65
|
+
### Variable Substitution:
|
|
66
|
+
|
|
67
|
+
<(token)>: registerd variable lookup for things like TODAY, USER, etc.
|
|
68
|
+
<(prefix.:token)>: optional variable token substituion
|
|
69
|
+
<(token:.suffix)>: optional variable token substituion
|
|
70
|
+
|
|
71
|
+
### Looped Variable Substitution:
|
|
72
|
+
|
|
73
|
+
token: ['point0', 'point1']
|
|
74
|
+
<@[token]@>: [['point0'], ['point1'], ['point0', 'point1']
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
from subtrix import Mechanism
|
|
78
|
+
|
|
79
|
+
# Initialize Mechanism
|
|
80
|
+
template = 'Hello, <[name]>!'
|
|
81
|
+
data = {'name': 'World'}
|
|
82
|
+
mech = Mechanism(template, data)
|
|
83
|
+
|
|
84
|
+
# Perform standard substitution
|
|
85
|
+
result = mech.run()
|
|
86
|
+
print(result) # Output: Hello, World!
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Usage
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
### Variable Substitution
|
|
93
|
+
|
|
94
|
+
Inject variables from various sources:
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
## Development
|
|
98
|
+
|
|
99
|
+
To set up a development environment and run the test suite locally:
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
# Clone and install in editable mode with dev extras
|
|
103
|
+
git clone https://github.com/solubrew/subtrix.git
|
|
104
|
+
cd subtrix
|
|
105
|
+
python -m pip install --upgrade pip
|
|
106
|
+
pip install -e ".[dev]"
|
|
107
|
+
pip install pytest pytest-asyncio
|
|
108
|
+
|
|
109
|
+
# Run the test suite
|
|
110
|
+
pytest tests/ -v
|
|
111
|
+
|
|
112
|
+
# Lint (matches CI)
|
|
113
|
+
ruff check subtrix/
|
|
114
|
+
|
|
115
|
+
# Confirm the package imports cleanly
|
|
116
|
+
python -c "import subtrix; print('Import OK:', subtrix.__name__)"
|
|
117
|
+
|
|
118
|
+
# Render a template from the CLI
|
|
119
|
+
python -m subtrix.cli subtrix "Hello <[name]>!" '{"name": "World"}'
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Before opening a pull request, also run the compliance auditor to verify the
|
|
123
|
+
project is in a releasable state:
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
PYTHONPATH=...:$TASKAXN_PYTHONPATH python -m sasquatch.cli analyze \
|
|
127
|
+
-p . --agent m3rl1n --skip-pii-secrets
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
A score of **>= 90 %** is required to tag a release. See
|
|
131
|
+
[CI_CD.md](CI_CD.md) for the full pipeline description.
|
|
132
|
+
|
|
133
|
+
## Contributing
|
|
134
|
+
|
|
135
|
+
Contributions are welcome! Please follow these steps:
|
|
136
|
+
|
|
137
|
+
1. Fork the repository.
|
|
138
|
+
2. Create a feature branch (`git checkout -b feature/<FEATURE_NAME>`).
|
|
139
|
+
3. Commit your changes (`git commit -am 'Add some feature'`).
|
|
140
|
+
4. Push to the branch (`git push origin feature/<FEATURE_NAME>`).
|
|
141
|
+
5. Open a Pull Request.
|
|
142
|
+
|
|
143
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for more details.
|
|
144
|
+
|
|
145
|
+
## License
|
|
146
|
+
|
|
147
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE.rst) file for details.
|
|
148
|
+
|
|
149
|
+
## Acknowledgments
|
|
150
|
+
|
|
151
|
+
- Built with inspiration from open-source templating and substitution libraries.
|
|
152
|
+
- Thanks to contributors of underlying libraries like re, and Python's built-in eval.
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# SubTrix - State
|
|
2
|
+
|
|
3
|
+
## Current Status
|
|
4
|
+
- **State**: Active Development
|
|
5
|
+
- **Last Updated**: 2026-03-02
|
|
6
|
+
- **Version**: 0.0.1.0.1.2
|
|
7
|
+
|
|
8
|
+
## Code Review Summary
|
|
9
|
+
|
|
10
|
+
### Architecture
|
|
11
|
+
- **Main Class**: Mechanism - Core templating engine
|
|
12
|
+
- **Supporting Classes**:
|
|
13
|
+
- DataProcessor - Data validation/normalization
|
|
14
|
+
- DocumentGenerator - Final document formatting
|
|
15
|
+
- PerformanceOptimizer - Caching utilities
|
|
16
|
+
- SecurityValidator - Input validation
|
|
17
|
+
|
|
18
|
+
### Dependencies
|
|
19
|
+
- kahndor - Configuration management
|
|
20
|
+
- kahndor.logma - Logging
|
|
21
|
+
- itertools - Combinations for loops
|
|
22
|
+
- functools - lru_cache
|
|
23
|
+
|
|
24
|
+
### Performance Features (Existing)
|
|
25
|
+
- @lru_cache on pattern search methods
|
|
26
|
+
- Efficient string building with join()
|
|
27
|
+
- Security validation (max size, max recursion)
|
|
28
|
+
|
|
29
|
+
### Test Status
|
|
30
|
+
- Test suite exists but requires `crow` module (not available)
|
|
31
|
+
- Core Mechanism tested manually - WORKS
|
|
32
|
+
|
|
33
|
+
## Gaps Identified
|
|
34
|
+
|
|
35
|
+
## Gaps Identified
|
|
36
|
+
|
|
37
|
+
### High Priority
|
|
38
|
+
| Gap | Status | Notes |
|
|
39
|
+
|-----|--------|-------|
|
|
40
|
+
| Test Suite Blocked | 🔴 NEEDS FIX | conftest.py imports crow module |
|
|
41
|
+
| No Memorization Layer | ✅ N/A | **INTENTIONALLY REMOVED** - Condor handles memorization |
|
|
42
|
+
|
|
43
|
+
### Medium Priority
|
|
44
|
+
| Gap | Status | Notes |
|
|
45
|
+
|-----|--------|-------|
|
|
46
|
+
| Limited Cache Coverage | ✅ N/A | Using @lru_cache only (sufficient for SubTrix) |
|
|
47
|
+
| No Disk Cache | ✅ N/A | Condor provides persistent caching |
|
|
48
|
+
|
|
49
|
+
### Note on Memorization Layer
|
|
50
|
+
**SubTrix does NOT have a memorization layer.** This is by design:
|
|
51
|
+
- SubTrix is lightweight and fast - memorization is NOT needed
|
|
52
|
+
- **Condor** is responsible for the memorization layer
|
|
53
|
+
- SubTrix uses @lru_cache on pattern search methods only (sufficient)
|
|
54
|
+
- [x] LRU cache with namespace support
|
|
55
|
+
- [x] Memory-based caching with LRU eviction
|
|
56
|
+
|
|
57
|
+
### Phase 2: Extend Caching
|
|
58
|
+
- [ ] Cache template parsing results
|
|
59
|
+
- [ ] Cache config loading
|
|
60
|
+
- [ ] Add cache invalidation
|
|
61
|
+
|
|
62
|
+
### Phase 3: Test & Verify
|
|
63
|
+
- [ ] Run performance benchmarks
|
|
64
|
+
- [ ] Verify no regression
|
|
65
|
+
|
|
66
|
+
## Use Cases
|
|
67
|
+
1. Document Generation - ✅ Supported
|
|
68
|
+
2. Template Processing - ✅ Supported
|
|
69
|
+
3. Loop Expansion - ✅ Supported
|
|
70
|
+
|
|
71
|
+
## Development State
|
|
72
|
+
- **Stage**: Development
|
|
73
|
+
- **Stability**: Beta
|
|
74
|
+
|
|
75
|
+
## Key Components
|
|
76
|
+
- `subtrix` - Main module
|
|
77
|
+
|
|
78
|
+
## Dependencies
|
|
79
|
+
- backoff
|
|
80
|
+
- click
|
|
81
|
+
- kahndor
|
|
82
|
+
- kahndor.logma
|
|
83
|
+
- itertools
|
|
84
|
+
- functools
|
|
85
|
+
|
|
86
|
+
## Last Updated
|
|
87
|
+
2026-03-02 (Orin Agent Review)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"""Subtrix - templating engine primitives.
|
|
2
|
+
|
|
3
|
+
This ``__init__.py`` exists so the source-tree layout (where the
|
|
4
|
+
actual package code lives under ``subtrix/subtrix/``) can be used
|
|
5
|
+
directly via ``sys.path`` insertion. In an installed build, the
|
|
6
|
+
build backend flattens the layout so that the canonical
|
|
7
|
+
``subtrix.utilities`` module lives at the top level.
|
|
8
|
+
|
|
9
|
+
Both layouts expose the same module objects:
|
|
10
|
+
|
|
11
|
+
- ``subtrix.utilities`` → inner utilities module (uuid, diff_dicts, …)
|
|
12
|
+
- ``subtrix.subtrix`` → main engine (full source)
|
|
13
|
+
- ``subtrix.subtrix.utilities`` → same utilities module, alternate path
|
|
14
|
+
|
|
15
|
+
The trick used here is ``pkgutil.extend_path(__path__, __name__)``
|
|
16
|
+
which tells Python to also scan any other directories on ``sys.path``
|
|
17
|
+
named ``subtrix`` for additional submodules. This lets the source
|
|
18
|
+
layout's ``subtrix/utilities/`` directory be discovered even though
|
|
19
|
+
the package's primary submodule lives one level deeper.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
import pkgutil
|
|
23
|
+
|
|
24
|
+
__path__ = pkgutil.extend_path(__path__, __name__)
|
|
25
|
+
from .subtrix import utilities # noqa: F401 (expose utilities submodule)
|