From 4e2f175b9fd648148782c7d576549f57c6df4b93 Mon Sep 17 00:00:00 2001 From: Willi Ballenthin Date: Wed, 14 Feb 2024 14:12:34 +0000 Subject: [PATCH] rules: don't eagerly import ruamel until needed --- capa/rules/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/capa/rules/__init__.py b/capa/rules/__init__.py index d9e43dfc..8ce3433d 100644 --- a/capa/rules/__init__.py +++ b/capa/rules/__init__.py @@ -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.