MCPcopy Create free account
hub / github.com/TactilityProject/Tactility / parse_config

Function parse_config

Buildscripts/DevicetreeCompiler/source/config.py:11–50  ·  view source on GitHub ↗

Parses devicetree.yaml and recursively finds dependencies. Returns a list of DeviceTreeConfig objects in post-order (dependencies first).

(file_path: str, project_root: str)

Source from the content-addressed store, hash-verified

9 dts: str = ""
10
11def parse_config(file_path: str, project_root: str) -> DeviceTreeConfig:
12 """
13 Parses devicetree.yaml and recursively finds dependencies.
14 Returns a list of DeviceTreeConfig objects in post-order (dependencies first).
15 """
16 config = DeviceTreeConfig([], [], "")
17 visited = set()
18
19 def _parse_recursive(current_path: str, is_root: bool):
20 abs_path = os.path.abspath(current_path)
21 if abs_path in visited:
22 return
23 visited.add(abs_path)
24
25 # Try to see if it's a directory and contains devicetree.yaml
26 if os.path.isdir(abs_path):
27 abs_path = os.path.join(abs_path, "devicetree.yaml")
28
29 with open(abs_path, 'r') as f:
30 data = yaml.safe_load(f) or {}
31
32 # Handle dependencies before adding current config (post-order)
33 deps = data.get("dependencies", [])
34 for dep in deps:
35 # Dependencies are relative to project_root
36 dep_path = os.path.join(project_root, dep)
37 _parse_recursive(dep_path, False)
38
39 if is_root:
40 config.dependencies += deps
41 dts_path = data.get("dts", "")
42 config.dts = os.path.join(current_path, dts_path)
43
44 bindings = data.get("bindings", "")
45 if bindings:
46 bindings_resolved = os.path.join(current_path, bindings)
47 config.bindings.append(bindings_resolved)
48
49 _parse_recursive(file_path, True)
50 return config

Callers 2

dependencies.pyFile · 0.90
mainFunction · 0.85

Calls 2

DeviceTreeConfigClass · 0.85
_parse_recursiveFunction · 0.85

Tested by

no test coverage detected