Replace deprecated pkg_resources usage

Use importlib.metadata to check the jinja2 version

Signed-off-by: Cindy Liu <hcindyl@google.com>
This commit is contained in:
Cindy Liu
2023-12-14 16:47:56 -08:00
committed by Gerwin Klein
parent 7bad3610f1
commit 04dc9675f3
2 changed files with 20 additions and 9 deletions

View File

@@ -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)

View File

@@ -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)