Skip to content

Commit 9ce1e47

Browse files
authored
use importlib instead of the deprecated pkg_resources (#1844)
1 parent f6acdbb commit 9ce1e47

30 files changed

+273
-92
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ list-author-emails:
177177
@git log --format='%aN,%aE' | sort -u | grep -v 'root'
178178

179179
mypy3: mypy
180-
mypy: $(filter-out setup.py gittagger.py,$(PYSOURCES))
180+
mypy: $(PYSOURCES)
181181
if ! test -f $(shell python -c 'import ruamel.yaml; import os.path; print(os.path.dirname(ruamel.yaml.__file__))')/py.typed ; \
182182
then \
183183
rm -Rf mypy-stubs/ruamel/yaml ; \

cwltool/builder.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,15 @@
2222
from cwl_utils.file_formats import check_format
2323
from mypy_extensions import mypyc_attr
2424
from rdflib import Graph
25+
from ruamel.yaml.comments import CommentedMap
26+
from ruamel.yaml.representer import RoundTripRepresenter
27+
from ruamel.yaml.scalarfloat import ScalarFloat
2528
from schema_salad.avro.schema import Names, Schema, make_avsc_object
2629
from schema_salad.exceptions import ValidationException
2730
from schema_salad.sourceline import SourceLine
2831
from schema_salad.utils import convert_to_dict, json_dumps
2932
from schema_salad.validate import validate
3033

31-
from ruamel.yaml.comments import CommentedMap
32-
from ruamel.yaml.representer import RoundTripRepresenter
33-
from ruamel.yaml.scalarfloat import ScalarFloat
34-
3534
from .errors import WorkflowException
3635
from .loghandler import _logger
3736
from .mutation import MutationManager

cwltool/command_line_tool.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,14 @@
3333

3434
import shellescape
3535
from mypy_extensions import mypyc_attr
36+
from ruamel.yaml.comments import CommentedMap, CommentedSeq
3637
from schema_salad.avro.schema import Schema
3738
from schema_salad.exceptions import ValidationException
3839
from schema_salad.ref_resolver import file_uri, uri_file_path
3940
from schema_salad.sourceline import SourceLine
4041
from schema_salad.utils import json_dumps
4142
from schema_salad.validate import validate_ex
4243

43-
from ruamel.yaml.comments import CommentedMap, CommentedSeq
44-
4544
from .builder import (
4645
INPUT_OBJ_VOCAB,
4746
Builder,

cwltool/context.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@
1818
Union,
1919
)
2020

21+
from ruamel.yaml.comments import CommentedMap
2122
from schema_salad.avro.schema import Names
2223
from schema_salad.ref_resolver import Loader
2324
from schema_salad.utils import FetcherCallableType
2425
from typing_extensions import Literal
2526

26-
from ruamel.yaml.comments import CommentedMap
27-
2827
from .mpi import MpiConfig
2928
from .pathmapper import PathMapper
3029
from .stdfsaccess import StdFsAccess

cwltool/cwlrdf.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44

55
from rdflib import Graph
66
from rdflib.query import ResultRow
7+
from ruamel.yaml.comments import CommentedMap
78
from schema_salad.jsonld_context import makerdf
89
from schema_salad.utils import ContextType
910

10-
from ruamel.yaml.comments import CommentedMap
11-
1211
from .cwlviewer import CWLViewer
1312
from .process import Process
1413

cwltool/load_tool.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
)
2222

2323
from cwl_utils.parser import cwl_v1_2, cwl_v1_2_utils
24+
from ruamel.yaml.comments import CommentedMap, CommentedSeq
2425
from schema_salad.exceptions import ValidationException
2526
from schema_salad.fetcher import Fetcher
2627
from schema_salad.ref_resolver import Loader, file_uri
@@ -34,8 +35,6 @@
3435
json_dumps,
3536
)
3637

37-
from ruamel.yaml.comments import CommentedMap, CommentedSeq
38-
3938
from . import CWL_CONTENT_TYPES, process, update
4039
from .context import LoadingContext
4140
from .errors import GraphTargetMissingException

cwltool/main.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@
3333

3434
import argcomplete
3535
import coloredlogs
36-
import pkg_resources # part of setuptools
36+
import ruamel.yaml
37+
from importlib_resources import files
38+
from ruamel.yaml.comments import CommentedMap, CommentedSeq
39+
from ruamel.yaml.main import YAML
3740
from schema_salad.exceptions import ValidationException
3841
from schema_salad.ref_resolver import Loader, file_uri, uri_file_path
3942
from schema_salad.sourceline import cmap, strip_dup_lineno
@@ -45,10 +48,6 @@
4548
yaml_no_ts,
4649
)
4750

48-
import ruamel.yaml
49-
from ruamel.yaml.comments import CommentedMap, CommentedSeq
50-
from ruamel.yaml.main import YAML
51-
5251
from . import CWL_CONTENT_TYPES, workflow
5352
from .argparser import arg_parser, generate_parser, get_default_args
5453
from .context import LoadingContext, RuntimeContext, getdefault
@@ -646,12 +645,12 @@ def setup_schema(
646645
if custom_schema_callback is not None:
647646
custom_schema_callback()
648647
elif args.enable_ext:
649-
with pkg_resources.resource_stream(__name__, "extensions.yml") as res:
650-
ext10 = res.read().decode("utf-8")
651-
with pkg_resources.resource_stream(__name__, "extensions-v1.1.yml") as res:
652-
ext11 = res.read().decode("utf-8")
653-
with pkg_resources.resource_stream(__name__, "extensions-v1.2.yml") as res:
654-
ext12 = res.read().decode("utf-8")
648+
with files("cwltool").joinpath("extensions.yml") as res:
649+
ext10 = res.read_text("utf-8")
650+
with files("cwltool").joinpath("extensions-v1.1.yml") as res:
651+
ext11 = res.read_text("utf-8")
652+
with files("cwltool").joinpath("extensions-v1.2.yml") as res:
653+
ext12 = res.read_text("utf-8")
655654
use_custom_schema("v1.0", "http://commonwl.org/cwltool", ext10)
656655
use_custom_schema("v1.1", "http://commonwl.org/cwltool", ext11)
657656
use_custom_schema("v1.2", "http://commonwl.org/cwltool", ext12)

cwltool/pack.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@
1414
cast,
1515
)
1616

17+
from ruamel.yaml.comments import CommentedMap, CommentedSeq
1718
from schema_salad.ref_resolver import Loader, SubLoader
1819
from schema_salad.utils import ResolveType
1920

20-
from ruamel.yaml.comments import CommentedMap, CommentedSeq
21-
2221
from .context import LoadingContext
2322
from .load_tool import fetch_document, resolve_and_validate_document
2423
from .process import shortname, uniquename

cwltool/process.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@
3333
)
3434

3535
from cwl_utils import expression
36+
from importlib_resources import files
3637
from mypy_extensions import mypyc_attr
37-
from pkg_resources import resource_stream
3838
from rdflib import Graph
39+
from ruamel.yaml.comments import CommentedMap, CommentedSeq
3940
from schema_salad.avro.schema import (
4041
Names,
4142
Schema,
@@ -49,8 +50,6 @@
4950
from schema_salad.utils import convert_to_dict
5051
from schema_salad.validate import avro_type_name, validate_ex
5152

52-
from ruamel.yaml.comments import CommentedMap, CommentedSeq
53-
5453
from .builder import INPUT_OBJ_VOCAB, Builder
5554
from .context import LoadingContext, RuntimeContext, getdefault
5655
from .errors import UnsupportedRequirement, WorkflowException
@@ -195,22 +194,19 @@ def get_schema(
195194
version = ".".join(version.split(".")[:-1])
196195
for f in cwl_files:
197196
try:
198-
res = resource_stream(__name__, f"schemas/{version}/{f}")
199-
cache["https://w3id.org/cwl/" + f] = res.read().decode("UTF-8")
200-
res.close()
197+
with files("cwltool").joinpath(f"schemas/{version}/{f}") as res:
198+
cache["https://w3id.org/cwl/" + f] = res.read_text("UTF-8")
201199
except OSError:
202200
pass
203201

204202
for f in salad_files:
205203
try:
206-
res = resource_stream(
207-
__name__,
204+
with files("cwltool").joinpath(
208205
f"schemas/{version}/salad/schema_salad/metaschema/{f}",
209-
)
210-
cache["https://w3id.org/cwl/salad/schema_salad/metaschema/" + f] = res.read().decode(
211-
"UTF-8"
212-
)
213-
res.close()
206+
) as res:
207+
cache["https://w3id.org/cwl/salad/schema_salad/metaschema/" + f] = res.read_text(
208+
"UTF-8"
209+
)
214210
except OSError:
215211
pass
216212

cwltool/procgenerator.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import copy
22
from typing import Dict, Optional, Tuple, cast
33

4+
from ruamel.yaml.comments import CommentedMap
45
from schema_salad.exceptions import ValidationException
56
from schema_salad.sourceline import indent
67

7-
from ruamel.yaml.comments import CommentedMap
8-
98
from .context import LoadingContext, RuntimeContext
109
from .errors import WorkflowException
1110
from .load_tool import load_tool

0 commit comments

Comments
 (0)