rules: don't eagerly import ruamel until needed

This commit is contained in:
Willi Ballenthin
2024-02-14 14:12:34 +00:00
committed by Willi Ballenthin
parent fdd097a141
commit 4e2f175b9f

View File

@@ -31,7 +31,6 @@ from dataclasses import asdict, dataclass
import yaml
import pydantic
import ruamel.yaml
import yaml.parser
import capa.perf
@@ -1053,6 +1052,11 @@ class Rule:
@staticmethod
def _get_ruamel_yaml_parser():
# we use lazy importing here to avoid eagerly loading dependencies
# that some specialized environments may not have,
# e.g., those that run capa without ruamel.
import ruamel.yaml
# use ruamel to enable nice formatting
# we use the ruamel.yaml parser because it supports roundtripping of documents with comments.