From 04dc9675f36180f6d11454cb87c6aa73e461591b Mon Sep 17 00:00:00 2001 From: Cindy Liu Date: Thu, 14 Dec 2023 16:47:56 -0800 Subject: [PATCH] Replace deprecated pkg_resources usage Use importlib.metadata to check the jinja2 version Signed-off-by: Cindy Liu --- tools/invocation_header_gen.py | 18 ++++++++++-------- tools/syscall_header_gen.py | 11 ++++++++++- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/tools/invocation_header_gen.py b/tools/invocation_header_gen.py index 6590ab44e..e36d667d7 100755 --- a/tools/invocation_header_gen.py +++ b/tools/invocation_header_gen.py @@ -9,20 +9,13 @@ # ============================ from __future__ import print_function +from importlib.metadata import version from jinja2 import Environment, BaseLoader import argparse import sys import xml.dom.minidom -import pkg_resources from condition import condition_to_cpp -# We require jinja2 to be at least version 2.10, -# In the past we used the 'namespace' feature from that version. -# other versions of jinja, particularly `minijinja`, don't support namespaces. -# However in case `namespace` is needed in the future require a -# version which supports it. -pkg_resources.require("jinja2>=2.10") - COMMON_HEADER = """ /* @@ -184,6 +177,15 @@ def generate(args, invocations): if __name__ == "__main__": + # We require jinja2 to be at least version 2.10, + # In the past we used the 'namespace' feature from that version. + # other versions of jinja, particularly `minijinja`, don't support + # namespaces. However in case `namespace` is needed in the future require a + # version which supports it. + jinja2_version = version("jinja2") + if jinja2_version < "2.10": + sys.exit("Jinja2 should be >= 2.10") + args = parse_args() invocations = parse_xml(args.xml) diff --git a/tools/syscall_header_gen.py b/tools/syscall_header_gen.py index e6123f8ed..1b5626720 100755 --- a/tools/syscall_header_gen.py +++ b/tools/syscall_header_gen.py @@ -9,13 +9,13 @@ # ============================== from __future__ import print_function +from importlib.metadata import version from jinja2 import Environment, BaseLoader import argparse import itertools import re import sys import xml.dom.minidom -import pkg_resources from condition import condition_to_cpp # We require jinja2 to be at least version 2.10, @@ -227,6 +227,15 @@ def generate_libsel4_file(libsel4_header, syscalls): if __name__ == "__main__": + # We require jinja2 to be at least version 2.10, + # In the past we used the 'namespace' feature from that version. + # other versions of jinja, particularly `minijinja`, don't support + # namespaces. However in case `namespace` is needed in the future require a + # version which supports it. + jinja2_version = version("jinja2") + if jinja2_version < "2.10": + sys.exit("Jinja2 should be >= 2.10") + args = parse_args() (api, debug) = parse_xml(args.xml, args.mcs)