yaml-reference 2.6.1__tar.gz → 2.6.2__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.
Files changed (24) hide show
  1. yaml_reference-2.6.2/.github/copilot-instructions.md +141 -0
  2. {yaml_reference-2.6.1 → yaml_reference-2.6.2}/PKG-INFO +1 -1
  3. {yaml_reference-2.6.1 → yaml_reference-2.6.2}/.github/workflows/pytests-pr.yml +0 -0
  4. {yaml_reference-2.6.1 → yaml_reference-2.6.2}/.github/workflows/release.yml +0 -0
  5. {yaml_reference-2.6.1 → yaml_reference-2.6.2}/.github/workflows/spectests-pr.yml +0 -0
  6. {yaml_reference-2.6.1 → yaml_reference-2.6.2}/.gitignore +0 -0
  7. {yaml_reference-2.6.1 → yaml_reference-2.6.2}/.pre-commit-config.yaml +0 -0
  8. {yaml_reference-2.6.1 → yaml_reference-2.6.2}/.python-version +0 -0
  9. {yaml_reference-2.6.1 → yaml_reference-2.6.2}/.vscode/settings.json +0 -0
  10. {yaml_reference-2.6.1 → yaml_reference-2.6.2}/.zed/settings.json +0 -0
  11. {yaml_reference-2.6.1 → yaml_reference-2.6.2}/GitVersion.yml +0 -0
  12. {yaml_reference-2.6.1 → yaml_reference-2.6.2}/LICENSE +0 -0
  13. {yaml_reference-2.6.1 → yaml_reference-2.6.2}/Makefile +0 -0
  14. {yaml_reference-2.6.1 → yaml_reference-2.6.2}/README.md +0 -0
  15. {yaml_reference-2.6.1 → yaml_reference-2.6.2}/pyproject.toml +0 -0
  16. {yaml_reference-2.6.1 → yaml_reference-2.6.2}/scripts/spec-test.sh +0 -0
  17. {yaml_reference-2.6.1 → yaml_reference-2.6.2}/scripts/update-readme-badge.sh +0 -0
  18. {yaml_reference-2.6.1 → yaml_reference-2.6.2}/tests/unit/conftest.py +0 -0
  19. {yaml_reference-2.6.1 → yaml_reference-2.6.2}/tests/unit/test_flatten.py +0 -0
  20. {yaml_reference-2.6.1 → yaml_reference-2.6.2}/tests/unit/test_merge.py +0 -0
  21. {yaml_reference-2.6.1 → yaml_reference-2.6.2}/tests/unit/test_reference.py +0 -0
  22. {yaml_reference-2.6.1 → yaml_reference-2.6.2}/uv.lock +0 -0
  23. {yaml_reference-2.6.1 → yaml_reference-2.6.2}/yaml_reference/__init__.py +0 -0
  24. {yaml_reference-2.6.1 → yaml_reference-2.6.2}/yaml_reference/cli.py +0 -0
@@ -0,0 +1,141 @@
1
+ # Copilot Instructions for yaml-reference
2
+
3
+ ## Project Overview
4
+
5
+ **yaml-reference** is a Python library that extends `ruamel.yaml` with cross-file YAML composition using custom tags (`!reference`, `!reference-all`, `!flatten`, `!merge`). It's built to be a reference implementation of the [yaml-reference-specs](https://github.com/dsillman2000/yaml-reference-specs) specification.
6
+
7
+ ## Build, Test, and Lint
8
+
9
+ **Tool chain:** `uv` (Python package manager) + `pytest` (testing) + `ruff` (linting/formatting)
10
+
11
+ ### Install dependencies
12
+ ```bash
13
+ uv sync
14
+ ```
15
+
16
+ ### Run all tests
17
+ ```bash
18
+ uv run pytest tests/ -v
19
+ ```
20
+
21
+ ### Run a single test file
22
+ ```bash
23
+ uv run pytest tests/unit/test_reference.py -v
24
+ ```
25
+
26
+ ### Run tests matching a pattern
27
+ ```bash
28
+ uv run pytest tests/unit/test_reference.py::test_reference_load -v
29
+ ```
30
+
31
+ ### Run spec compliance tests (tests against yaml-reference-specs)
32
+ ```bash
33
+ make spec-test
34
+ ```
35
+
36
+ ### Code formatting
37
+ ```bash
38
+ uv run ruff format
39
+ # or
40
+ make format
41
+ ```
42
+
43
+ ### Linting and auto-fix
44
+ ```bash
45
+ uv run ruff check --fix
46
+ # or
47
+ make lint
48
+ ```
49
+
50
+ ### Run full quality check (format + lint + test)
51
+ ```bash
52
+ make check
53
+ ```
54
+
55
+ ### Build package
56
+ ```bash
57
+ uv build
58
+ ```
59
+
60
+ ## Architecture
61
+
62
+ The library is structured in two key parts:
63
+
64
+ ### Core Module (`yaml_reference/__init__.py`)
65
+ - **Reference & ReferenceAll classes**: Represent the `!reference` and `!reference-all` YAML tags as Python objects
66
+ - **parse_yaml_with_references()**: Parses YAML, returning Reference/ReferenceAll objects without resolving them (one layer only)
67
+ - **load_yaml_with_references()**: Fully recursively resolves all references, returning a complete Python dict
68
+ - **Flatten & Merge classes**: Represent `!flatten` and `!merge` tag logic
69
+ - **YAML loader setup**: Registers custom constructors with `ruamel.yaml.YAML` for each tag
70
+
71
+ ### CLI Module (`yaml_reference/cli.py`)
72
+ - Simple entry point that calls the core loading functions
73
+ - Outputs JSON to stdout (compatible with spec tests)
74
+ - Takes optional `--allow` flag for path restrictions
75
+
76
+ ### Test Structure (`tests/unit/`)
77
+ - `test_reference.py`: Tests for `!reference` and `!reference-all` tag resolution
78
+ - `test_flatten.py`: Tests for `!flatten` tag behavior
79
+ - `test_merge.py`: Tests for `!merge` tag behavior
80
+ - `conftest.py`: Pytest fixtures and test utilities
81
+
82
+ ## Key Conventions & Design Patterns
83
+
84
+ ### Security-First Path Handling
85
+ 1. **Relative paths only**: All references must use relative paths (e.g., `path: "config/db.yaml"`). Absolute paths raise `ValueError`.
86
+ 2. **Path restriction by default**: References can only access files in the same directory or subdirectories (no `..` to escape). Use `allow_paths` parameter to explicitly allow other directory trees.
87
+ 3. **Security invariant**: Disallowed files are **never opened or read into memory**. Path filtering happens before file I/O.
88
+ 4. **Silent omission (for `!reference-all`)**: When a glob pattern matches files outside allowed paths, those files are silently dropped from results and the function returns `rc=0` (not an error).
89
+
90
+ ### YAML Tag Implementation Pattern
91
+ Each custom tag follows this pattern:
92
+ 1. Define a class with `yaml_tag` attribute
93
+ 2. Implement `@classmethod from_yaml(cls, constructor, node)` to parse from YAML
94
+ 3. Register constructor with the YAML loader in `__init__.py`
95
+ 4. The class instance persists through `parse_yaml_with_references()`, allowing layer-by-layer resolution
96
+
97
+ ### Reference Resolution Order
98
+ 1. **Circular reference detection** occurs during recursive resolution by tracking a "resolution stack"
99
+ 2. **Anchors** (optional parameter): If specified, extract only the anchored section from the referenced file
100
+ 3. **Recursive expansion**: `load_yaml_with_references()` recursively expands all tags, applying `!flatten` and `!merge` logic as it encounters them
101
+
102
+ ### Error Handling
103
+ - **ValueError** for spec violations: absolute paths, circular references, invalid anchors
104
+ - **FileNotFoundError** for missing referenced files
105
+ - **Glob errors**: Return empty list `[]` if glob matches no files (silent omission)
106
+
107
+ ### Spec Compliance Testing
108
+ The project tests against `yaml-reference-specs`, a Go-based reference implementation. The spec tests verify:
109
+ - Correct expansion of all four tags
110
+ - Proper error detection (bad paths, missing files, circular refs)
111
+ - Path restriction enforcement
112
+ - Edge cases like empty globs and nested composition
113
+
114
+ Run with: `make spec-test` or `scripts/spec-test.sh`
115
+
116
+ ## Pre-commit Hooks
117
+
118
+ The repository enforces conventional commits and code quality via pre-commit:
119
+ - **ruff-check** and **ruff-format**: Ensures consistent style
120
+ - **conventional-pre-commit**: Enforces Conventional Commits format (e.g., `feat:`, `fix:`, `docs:`)
121
+ - Standard hooks: trailing whitespace, EOF fixers, YAML validation
122
+
123
+ Install hooks with: `pre-commit install`
124
+
125
+ ## Common Workflows
126
+
127
+ ### Adding a new tag type
128
+ 1. Create a class in `yaml_reference/__init__.py` with `yaml_tag` attribute and `from_yaml()` classmethod
129
+ 2. Register the constructor after the class definition
130
+ 3. Add resolution logic (handle in recursive expansion)
131
+ 4. Write tests in `tests/unit/test_*.py` following existing patterns
132
+ 5. Update README.md with usage example
133
+
134
+ ### Debugging a reference resolution issue
135
+ 1. Use `parse_yaml_with_references()` to see raw Reference objects before resolution
136
+ 2. Add print statements or use a debugger to trace the `_resolve_references()` recursive calls
137
+ 3. Check the resolution stack to verify circular reference detection is working
138
+ 4. Run a specific test with `-v` flag to see detailed assertion output
139
+
140
+ ### Updating error messages
141
+ Ensure error messages follow this pattern: include the problematic value, the path of the file where the error occurred, and the specific constraint violated. This helps spec tests verify proper error handling.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: yaml-reference
3
- Version: 2.6.1
3
+ Version: 2.6.2
4
4
  Summary: Extension package built on top of `ruamel.yaml` to support cross-file references in YAML files using tags `!reference` and `!reference-all`.
5
5
  Project-URL: Repository, https://github.com/dsillman2000/yaml-reference.git
6
6
  Author-email: David Sillman <dsillman2000@gmail.com>
File without changes
File without changes
File without changes
File without changes