Skip to content

Commit 31c7fba

Browse files
committed
cleanups
1 parent 1870e9d commit 31c7fba

File tree

2 files changed

+11
-22
lines changed

2 files changed

+11
-22
lines changed

cwltool/provenance.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import copy
55
import datetime
66
import hashlib
7-
import io
87
import logging
98
import os
109
import os.path
@@ -15,10 +14,10 @@
1514
import uuid
1615
from collections import OrderedDict
1716
from getpass import getuser
18-
from io import open
17+
from io import BytesIO, FileIO, TextIOWrapper, open
1918
from socket import getfqdn
20-
from typing import (IO, Any, Callable, Dict, List, MutableMapping, Optional,
21-
Set, Tuple, Union, cast)
19+
from typing import (IO, Any, Callable, Dict, List, Generator, MutableMapping,
20+
Optional, Set, Tuple, Union, cast)
2221

2322
import prov.model as provM
2423
import six
@@ -149,7 +148,7 @@ def _whoami():
149148
return (username, fullname)
150149

151150

152-
class WritableBagFile(io.FileIO):
151+
class WritableBagFile(FileIO):
153152
"""Writes files in research object."""
154153

155154
def __init__(self, research_object, rel_path):
@@ -209,7 +208,7 @@ def readable(self):
209208

210209
def truncate(self, size=None):
211210
# type: (Optional[int]) -> int
212-
# FIXME: This breaks contract io.IOBase,
211+
# FIXME: This breaks contract IOBase,
213212
# as it means we would have to recalculate the hash
214213
if size is not None:
215214
raise IOError("WritableBagFile can't truncate")
@@ -680,7 +679,7 @@ def declare_directory(self, value): # type: (MutableMapping) -> ProvEntity
680679
def declare_string(self, value):
681680
# type: (Union[Text, str]) -> Tuple[ProvEntity,Text]
682681
"""Save as string in UTF-8."""
683-
byte_s = io.BytesIO(str(value).encode(ENCODING))
682+
byte_s = BytesIO(str(value).encode(ENCODING))
684683
data_file = self.research_object.add_data_file(byte_s, content_type=TEXT_PLAIN)
685684
checksum = posixpath.basename(data_file)
686685
# FIXME: Don't naively assume add_data_file uses hash in filename!
@@ -716,7 +715,7 @@ def declare_artefact(self, value):
716715

717716
if isinstance(value, bytes):
718717
# If we got here then we must be in Python 3
719-
byte_s = io.BytesIO(value)
718+
byte_s = BytesIO(value)
720719
data_file = self.research_object.add_data_file(byte_s)
721720
# FIXME: Don't naively assume add_data_file uses hash in filename!
722721
data_id = "data:%s" % posixpath.split(data_file)[1]
@@ -1051,13 +1050,13 @@ def write_bag_file(self, path, encoding=ENCODING):
10511050
# type: (Text, Optional[str]) -> IO
10521051
"""Write the bag file into our research object."""
10531052
# For some reason below throws BlockingIOError
1054-
#fp = io.BufferedWriter(WritableBagFile(self, path))
1053+
#fp = BufferedWriter(WritableBagFile(self, path))
10551054
bag_file = cast(IO, WritableBagFile(self, path))
10561055
if encoding:
10571056
# encoding: match Tag-File-Character-Encoding: UTF-8
10581057
# newline: ensure LF also on Windows
10591058
return cast(IO,
1060-
io.TextIOWrapper(bag_file, encoding=encoding, newline="\n"))
1059+
TextIOWrapper(bag_file, encoding=encoding, newline="\n"))
10611060
return bag_file
10621061

10631062
def add_tagfile(self, path, when=None):
@@ -1505,7 +1504,7 @@ def jdefault(o):
15051504
rel_path = posixpath.join(_posix_path(WORKFLOW), "primary-output.json")
15061505
else:
15071506
rel_path = posixpath.join(_posix_path(WORKFLOW), "primary-job.json")
1508-
j = json.dumps(copied, indent=4, ensure_ascii=False, default=jdefault)
1507+
j = json_dumps(copied, indent=4, ensure_ascii=False, default=jdefault)
15091508
with self.write_bag_file(rel_path) as file_path:
15101509
file_path.write(j + u"\n")
15111510
_logger.debug(u"[provenance] Generated customised job file: %s",

tests/test_provenance.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
import arcp
1414
import pytest
1515
from rdflib import Graph, Literal, Namespace, URIRef
16-
from rdflib.namespace import DC, DCTERMS, FOAF, RDF, RDFS, SKOS, XSD
17-
from six import StringIO
16+
from rdflib.namespace import DC, DCTERMS, RDF
1817
from six.moves import urllib
1918

2019
import bagit
@@ -25,15 +24,6 @@
2524
from cwltool.utils import onWindows
2625

2726
from .util import get_data
28-
import bagit
29-
import posixpath
30-
import ntpath
31-
from six.moves import urllib
32-
from rdflib import Namespace, URIRef, Graph, Literal
33-
from rdflib.namespace import RDF,RDFS,SKOS,DCTERMS,FOAF,XSD,DC
34-
import arcp
35-
import json
36-
from hashlib import sha1
3727

3828
# RDF namespaces we'll query for later
3929
ORE = Namespace("http://www.openarchives.org/ore/terms/")

0 commit comments

Comments
 (0)