From c11ae3f057030bf247be90a6cdec06847c889f13 Mon Sep 17 00:00:00 2001 From: Brett Smith Date: Thu, 4 Jan 2024 10:42:02 -0500 Subject: [PATCH] 20846: Migrate from pkg_resources to importlib in sdk/cwl Now that we're deprecating Python 3.7, it's easy to rely on importlib from the stdlib. Arvados-DCO-1.1-Signed-off-by: Brett Smith --- sdk/cwl/arvados_cwl/__init__.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/sdk/cwl/arvados_cwl/__init__.py b/sdk/cwl/arvados_cwl/__init__.py index fd3b7a5d16..9fc00c0017 100644 --- a/sdk/cwl/arvados_cwl/__init__.py +++ b/sdk/cwl/arvados_cwl/__init__.py @@ -10,11 +10,12 @@ from future.utils import viewitems from builtins import str import argparse +import importlib.metadata +import importlib.resources import logging import os import sys import re -import pkg_resources # part of setuptools from schema_salad.sourceline import SourceLine import schema_salad.validate as validate @@ -57,15 +58,12 @@ arvados.log_handler.setFormatter(logging.Formatter( def versionstring(): """Print version string of key packages for provenance and debugging.""" - - arvcwlpkg = pkg_resources.require("arvados-cwl-runner") - arvpkg = pkg_resources.require("arvados-python-client") - cwlpkg = pkg_resources.require("cwltool") - - return "%s %s, %s %s, %s %s" % (sys.argv[0], arvcwlpkg[0].version, - "arvados-python-client", arvpkg[0].version, - "cwltool", cwlpkg[0].version) - + return "{} {}, arvados-python-client {}, cwltool {}".format( + sys.argv[0], + importlib.metadata.version('arvados-cwl-runner'), + importlib.metadata.version('arvados-python-client'), + importlib.metadata.version('cwltool'), + ) def arg_parser(): # type: () -> argparse.ArgumentParser parser = argparse.ArgumentParser( @@ -270,10 +268,8 @@ def add_arv_hints(): cwltool.command_line_tool.ACCEPTLIST_RE = cwltool.command_line_tool.ACCEPTLIST_EN_RELAXED_RE supported_versions = ["v1.0", "v1.1", "v1.2"] for s in supported_versions: - res = pkg_resources.resource_stream(__name__, 'arv-cwl-schema-%s.yml' % s) - customschema = res.read().decode('utf-8') + customschema = importlib.resources.read_text(__name__, f'arv-cwl-schema-{s}.yml', 'utf-8') use_custom_schema(s, "http://arvados.org/cwl", customschema) - res.close() cwltool.process.supportedProcessRequirements.extend([ "http://arvados.org/cwl#RunInSingleContainer", "http://arvados.org/cwl#OutputDirType", -- 2.30.2