rbtr-lang-hcl 2026.7.0.dev0__py3-none-any.whl

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.
@@ -0,0 +1 @@
1
+ """HCL language plugin package."""
rbtr_lang_hcl/hcl.scm ADDED
@@ -0,0 +1,6 @@
1
+ ; Comments (HCL: `#`, `//`, `/* */` — all `comment`).
2
+ (comment) @comment
3
+
4
+ (config_file
5
+ (body
6
+ (block) @config_key))
@@ -0,0 +1,60 @@
1
+ """HCL language plugin.
2
+
3
+ Extracts each top-level block as a config-key chunk, via a
4
+ tree-sitter query. The block name combines its type and labels.
5
+
6
+ Extracted chunks::
7
+
8
+ resource "aws_instance" "web" {} → config_key "resource aws_instance web"
9
+ variable "region" {} → config_key "variable region"
10
+ terraform {} → config_key "terraform"
11
+ """
12
+
13
+ from __future__ import annotations
14
+
15
+ from typing import TYPE_CHECKING
16
+
17
+ from rbtr.languages.registration import (
18
+ LanguageRegistration,
19
+ NameResolver,
20
+ QueryExtraction,
21
+ load_query,
22
+ )
23
+
24
+ if TYPE_CHECKING:
25
+ from tree_sitter import Node
26
+
27
+ # Top-level blocks only: a `block` whose body is the file's own body,
28
+ # not one nested inside another block.
29
+
30
+
31
+ hcl = LanguageRegistration(
32
+ id="hcl",
33
+ extensions=frozenset({".hcl", ".tf"}),
34
+ grammar_module="tree_sitter_hcl",
35
+ extraction=QueryExtraction(
36
+ query=load_query(__package__, "hcl"),
37
+ ),
38
+ extraction_serial=4,
39
+ )
40
+
41
+
42
+ @hcl.name_extractor
43
+ def hcl_block_name(
44
+ resolver: NameResolver, capture_name: str, node: Node, captures: dict[str, list[Node]]
45
+ ) -> str:
46
+ """Name a top-level HCL block by its type and labels.
47
+
48
+ `resource "aws_instance" "web"` → `"resource aws_instance web"`;
49
+ a bare `terraform {}` block → `"terraform"`. Non-block captures
50
+ fall back to the default resolver.
51
+ """
52
+ if capture_name != "config_key":
53
+ return resolver(capture_name, node, captures)
54
+ labels: list[str] = []
55
+ for child in node.children:
56
+ if child.type == "identifier" and child.text:
57
+ labels.append(child.text.decode("utf-8", errors="replace"))
58
+ elif child.type == "string_lit" and child.text:
59
+ labels.append(child.text.decode("utf-8", errors="replace").strip('"'))
60
+ return " ".join(labels)
rbtr_lang_hcl/py.typed ADDED
File without changes
File without changes
@@ -0,0 +1,92 @@
1
+ [
2
+ {
3
+ "id": "ee86eb0e9a970b30",
4
+ "blob_sha": "sha1",
5
+ "file_path": "main.tf",
6
+ "kind": "comment",
7
+ "name": "<anonymous>",
8
+ "scope": "",
9
+ "language": "hcl",
10
+ "content": "# Greeter service infrastructure.\n#\n# The HCL plugin extracts each top-level block as a doc section, named by its\n# type and labels: a bare block by its type (terraform), a variable/output by\n# its name, a resource by its type and name.",
11
+ "line_start": 1,
12
+ "line_end": 5,
13
+ "metadata": {
14
+ "module": "",
15
+ "names": "",
16
+ "dots": "",
17
+ "language_hint": ""
18
+ }
19
+ },
20
+ {
21
+ "id": "9a3479950102c0b7",
22
+ "blob_sha": "sha1",
23
+ "file_path": "main.tf",
24
+ "kind": "config_key",
25
+ "name": "terraform",
26
+ "scope": "",
27
+ "language": "hcl",
28
+ "content": "terraform {\n required_version = \">= 1.5\"\n}",
29
+ "line_start": 7,
30
+ "line_end": 9,
31
+ "metadata": {
32
+ "module": "",
33
+ "names": "",
34
+ "dots": "",
35
+ "language_hint": ""
36
+ }
37
+ },
38
+ {
39
+ "id": "6a9efd680841aa5e",
40
+ "blob_sha": "sha1",
41
+ "file_path": "main.tf",
42
+ "kind": "config_key",
43
+ "name": "variable region",
44
+ "scope": "",
45
+ "language": "hcl",
46
+ "content": "variable \"region\" {\n description = \"Deployment region for the greeter service.\"\n type = string\n default = \"us-east-1\"\n}",
47
+ "line_start": 11,
48
+ "line_end": 15,
49
+ "metadata": {
50
+ "module": "",
51
+ "names": "",
52
+ "dots": "",
53
+ "language_hint": ""
54
+ }
55
+ },
56
+ {
57
+ "id": "457a0958f846de57",
58
+ "blob_sha": "sha1",
59
+ "file_path": "main.tf",
60
+ "kind": "config_key",
61
+ "name": "resource aws_instance greeter",
62
+ "scope": "",
63
+ "language": "hcl",
64
+ "content": "resource \"aws_instance\" \"greeter\" {\n ami = \"ami-0abc123\"\n instance_type = \"t3.micro\"\n\n tags = {\n Name = \"greeter\"\n }\n}",
65
+ "line_start": 17,
66
+ "line_end": 24,
67
+ "metadata": {
68
+ "module": "",
69
+ "names": "",
70
+ "dots": "",
71
+ "language_hint": ""
72
+ }
73
+ },
74
+ {
75
+ "id": "633460e780957025",
76
+ "blob_sha": "sha1",
77
+ "file_path": "main.tf",
78
+ "kind": "config_key",
79
+ "name": "output greeter_ip",
80
+ "scope": "",
81
+ "language": "hcl",
82
+ "content": "output \"greeter_ip\" {\n description = \"Public IP of the greeter instance.\"\n value = aws_instance.greeter.public_ip\n}",
83
+ "line_start": 26,
84
+ "line_end": 29,
85
+ "metadata": {
86
+ "module": "",
87
+ "names": "",
88
+ "dots": "",
89
+ "language_hint": ""
90
+ }
91
+ }
92
+ ]
@@ -0,0 +1,29 @@
1
+ """HCL extraction test cases (top-level blocks -> config_key)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from pytest_cases import case
6
+
7
+ type SymbolCase = tuple[str, str, list[tuple[str, str, str]]]
8
+
9
+
10
+ @case(tags=["symbol"])
11
+ def case_hcl_splits_by_blocks() -> SymbolCase:
12
+ """HCL splits by top-level blocks."""
13
+ src = """\
14
+ resource "aws_instance" "web" {
15
+ ami = "ami-12345"
16
+ }
17
+
18
+ variable "region" {
19
+ default = "us-east-1"
20
+ }
21
+ """
22
+ return (
23
+ "hcl",
24
+ src,
25
+ [
26
+ ("config_key", "resource aws_instance web", ""),
27
+ ("config_key", "variable region", ""),
28
+ ],
29
+ )
@@ -0,0 +1,29 @@
1
+ # Greeter service infrastructure.
2
+ #
3
+ # The HCL plugin extracts each top-level block as a doc section, named by its
4
+ # type and labels: a bare block by its type (terraform), a variable/output by
5
+ # its name, a resource by its type and name.
6
+
7
+ terraform {
8
+ required_version = ">= 1.5"
9
+ }
10
+
11
+ variable "region" {
12
+ description = "Deployment region for the greeter service."
13
+ type = string
14
+ default = "us-east-1"
15
+ }
16
+
17
+ resource "aws_instance" "greeter" {
18
+ ami = "ami-0abc123"
19
+ instance_type = "t3.micro"
20
+
21
+ tags = {
22
+ Name = "greeter"
23
+ }
24
+ }
25
+
26
+ output "greeter_ip" {
27
+ description = "Public IP of the greeter instance."
28
+ value = aws_instance.greeter.public_ip
29
+ }
@@ -0,0 +1,17 @@
1
+ """HCL extraction tests (cases in `cases_extraction.py`)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from pytest_cases import parametrize_with_cases
6
+
7
+ from rbtr.git import FileEntry
8
+ from rbtr.languages.extract import extract_file
9
+
10
+
11
+ @parametrize_with_cases("lang, source, expected", cases=".cases_extraction", has_tag="symbol")
12
+ def test_extracts_expected_symbols(lang: str, source: str, expected: list) -> None:
13
+ """Each expected (kind, name, scope) tuple appears in the output."""
14
+ chunks = extract_file(FileEntry("input", "sha1", source.encode()), lang)
15
+ symbols = [(c.kind, c.name, c.scope) for c in chunks]
16
+ for exp in expected:
17
+ assert exp in symbols, f"expected {exp} not found in {symbols}"
@@ -0,0 +1,68 @@
1
+ """HCL sample extraction: the `samples/hcl/` project through the real pipeline."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from pathlib import Path
6
+ from typing import TYPE_CHECKING
7
+
8
+ import pytest
9
+ from tree_sitter import Parser
10
+
11
+ from rbtr.git import FileEntry
12
+ from rbtr.index.models import Chunk, ChunkKind, Edge
13
+ from rbtr.languages.edges import build_resolution_map, infer_import_edges
14
+ from rbtr.languages.extract import extract_file
15
+ from rbtr.languages.manager import get_manager
16
+ from rbtr.testing import render_edges
17
+
18
+ if TYPE_CHECKING:
19
+ from syrupy.assertion import SnapshotAssertion
20
+
21
+
22
+ @pytest.fixture
23
+ def project() -> list[tuple[str, str]]:
24
+ root = Path(__file__).parent / "samples" / "hcl"
25
+ return [
26
+ (str(p.relative_to(root)), p.read_text()) for p in sorted(root.rglob("*")) if p.is_file()
27
+ ]
28
+
29
+
30
+ @pytest.fixture
31
+ def chunks(project: list[tuple[str, str]]) -> list[Chunk]:
32
+ manager = get_manager()
33
+ out: list[Chunk] = []
34
+ for path, text in project:
35
+ lang = manager.detect_language(path) or "hcl"
36
+ out.extend(extract_file(FileEntry(path, "sha1", text.encode()), lang))
37
+ return out
38
+
39
+
40
+ @pytest.fixture
41
+ def edges(project: list[tuple[str, str]], chunks: list[Chunk]) -> list[Edge]:
42
+ manager = get_manager()
43
+ repo_files = {path for path, _ in project}
44
+ return infer_import_edges(chunks, repo_files, build_resolution_map(manager))
45
+
46
+
47
+ def test_emits_expected_kinds(chunks: list[Chunk]) -> None:
48
+ """The sample exercises HCL's config-key chunks."""
49
+ kinds = {c.kind for c in chunks}
50
+ assert {ChunkKind.CONFIG_KEY, ChunkKind.COMMENT} <= kinds
51
+
52
+
53
+ def test_parses_cleanly(project: list[tuple[str, str]]) -> None:
54
+ manager = get_manager()
55
+ for path, text in project:
56
+ grammar = manager.grammar(manager.detect_language(path) or "hcl")
57
+ assert grammar is not None
58
+ assert not Parser(grammar).parse(text.encode()).root_node.has_error, path
59
+
60
+
61
+ def test_extraction_matches_snapshot(chunks: list[Chunk], snapshot_json: SnapshotAssertion) -> None:
62
+ assert chunks == snapshot_json
63
+
64
+
65
+ def test_edges_match_snapshot(
66
+ chunks: list[Chunk], edges: list[Edge], snapshot_json: SnapshotAssertion
67
+ ) -> None:
68
+ assert render_edges(edges, chunks) == snapshot_json
@@ -0,0 +1,8 @@
1
+ Metadata-Version: 2.4
2
+ Name: rbtr-lang-hcl
3
+ Version: 2026.7.0.dev0
4
+ Summary: rbtr — HCL / Terraform language plugin
5
+ License-Expression: MIT
6
+ Requires-Dist: rbtr==2026.7.0.dev0
7
+ Requires-Dist: tree-sitter-hcl
8
+ Requires-Python: >=3.13
@@ -0,0 +1,15 @@
1
+ rbtr_lang_hcl/__init__.py,sha256=Fti9IHmwC5o-nqrNdnsGmMmzKZl2OCNJJ6jFo2XjDKQ,35
2
+ rbtr_lang_hcl/hcl.scm,sha256=CAuqcIBJ66vCfM7ieB7TH_ddkfE_b5XpBu4oVtNveAA,123
3
+ rbtr_lang_hcl/plugin.py,sha256=80fI2ix3ewuQS6C654JlR8i5CQzeubkzPnYwg4zpJYM,1818
4
+ rbtr_lang_hcl/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ rbtr_lang_hcl/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ rbtr_lang_hcl/tests/__snapshots__/test_samples/test_edges_match_snapshot.json,sha256=N1F-Xz3GaBn2H1p7uKzhkhKCQV8QVR0t76XD6wmFtXA,3
7
+ rbtr_lang_hcl/tests/__snapshots__/test_samples/test_extraction_matches_snapshot.json,sha256=CJhfX0RebBLX5UgtHt8cQFU451sEUEPX26wxg_opyPE,2494
8
+ rbtr_lang_hcl/tests/cases_extraction.py,sha256=RWDkex1xlE565Sru2a0fAoMdChZMoe6L4o8wei4t-AM,610
9
+ rbtr_lang_hcl/tests/samples/hcl/main.tf,sha256=KlPG1rYpQ45PVYekieGqzxB99Vmy2mIJ_cdCrvhqSBg,679
10
+ rbtr_lang_hcl/tests/test_extraction.py,sha256=JEh4BrD60DKJ8WcEU-I4pUZOwYAU0Hp2aOQ0Lkwqw4Y,712
11
+ rbtr_lang_hcl/tests/test_samples.py,sha256=7smMQp1Q67M44NRO1j3f_BU5emK6iaY8jTHpVZGkGGs,2225
12
+ rbtr_lang_hcl-2026.7.0.dev0.dist-info/WHEEL,sha256=CoDSoyhtC_eO_tlxRYzsTraPv1fPJRXFx91k6ISeAvA,81
13
+ rbtr_lang_hcl-2026.7.0.dev0.dist-info/entry_points.txt,sha256=I7_liJWjgbs_MJHvnE70kT0Hjh8KTq8T1hlaiHJ5To8,49
14
+ rbtr_lang_hcl-2026.7.0.dev0.dist-info/METADATA,sha256=FJ1vk6qbBUqJlIvHHFqaniRn4JPLE-qMpbnGdDbB9wk,229
15
+ rbtr_lang_hcl-2026.7.0.dev0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: uv 0.11.28
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,3 @@
1
+ [rbtr.languages]
2
+ hcl = rbtr_lang_hcl.plugin:hcl
3
+