Skip to content

Commit 07aa937

Browse files
pdgendtcarlescufi
authored andcommitted
manifest: Use faster yaml CLoader if available
Speed up the yaml parsing used by west by using LibYAML if available. Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
1 parent c8e0337 commit 07aa937

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

src/west/commands.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222

2323
import colorama
2424
import pykwalify
25+
26+
try:
27+
from yaml import CSafeLoader as SafeLoader
28+
except ImportError:
29+
from yaml import SafeLoader # type: ignore
30+
2531
import yaml
2632

2733
from west.configuration import Configuration
@@ -649,7 +655,7 @@ def _ext_specs(project):
649655
# Load the spec file and check the schema.
650656
with open(spec_file) as f:
651657
try:
652-
commands_spec = yaml.safe_load(f.read())
658+
commands_spec = yaml.load(f.read(), Loader=SafeLoader)
653659
except yaml.YAMLError as e:
654660
raise ExtensionCommandError from e
655661
try:

src/west/manifest.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222

2323
import pykwalify.core
2424
import yaml
25+
26+
try:
27+
from yaml import CSafeLoader as SafeLoader
28+
except ImportError:
29+
from yaml import SafeLoader # type: ignore
30+
2531
from packaging.version import parse as parse_version
2632

2733
from west import util
@@ -204,7 +210,7 @@ def _is_yml(path: PathType) -> bool:
204210

205211
def _load(data: str) -> Any:
206212
try:
207-
return yaml.safe_load(data)
213+
return yaml.load(data, Loader=SafeLoader)
208214
except yaml.scanner.ScannerError as e:
209215
raise MalformedManifest(data) from e
210216

0 commit comments

Comments
 (0)