Skip to content

Commit 156b08a

Browse files
committed
simplify IO
1 parent cc85467 commit 156b08a

File tree

7 files changed

+16
-19
lines changed

7 files changed

+16
-19
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,11 @@ diff-cover.html: coverage.xml
133133

134134
## test : run the ${MODULE} test suite
135135
test: FORCE
136-
python setup.py test # --addopts "-n auto --dist=loadfile"
136+
python setup.py test --addopts "tests" #-n auto --dist=loadfile"
137137

138138
## testcov : run the ${MODULE} test suite and collect coverage
139139
testcov: $(pysources)
140-
python setup.py test --addopts "--cov ${MODULE}" # -n auto --dist=loadfile"
140+
python setup.py test --addopts "tests --cov ${MODULE}" # -n auto --dist=loadfile"
141141

142142
sloccount.sc: ${PYSOURCES} Makefile
143143
sloccount --duplicates --wide --details $^ > $@

cwl_utils/graph_split.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77

88
import os
99
import sys
10-
from io import StringIO
1110
from pathlib import Path
12-
from typing import Any, Dict, List, MutableMapping, Set, Text, Union, cast
11+
from typing import IO, Any, Dict, List, MutableMapping, Set, Text, Union, cast
1312

1413
from ruamel import yaml
1514
from schema_salad.sourceline import SourceLine, add_lc_filename
@@ -18,16 +17,13 @@
1817
def main(args: List[str]) -> None:
1918
"""Split the packed CWL at the path of the first argument."""
2019
with open(args[0], "r") as source_handle:
21-
sourceStr = str(source_handle.read())
22-
run(sourceStr, (Path.cwd() / args[0]).as_uri())
20+
run(source_handle)
2321

2422

25-
def run(sourceStr: str, source_uri: str) -> None:
23+
def run(sourceIO: IO[str]) -> None:
2624
"""Loop over the provided packed CWL document and split it up."""
27-
sourceIO = StringIO(sourceStr)
28-
sourceIO.name = source_uri
2925
source = yaml.main.round_trip_load(sourceIO, preserve_quotes=True)
30-
add_lc_filename(source, source_uri)
26+
add_lc_filename(source, sourceIO.name)
3127

3228
if "$graph" not in source:
3329
print("No $graph, so not for us.")
@@ -51,8 +47,8 @@ def my_represent_none(
5147
for import_name in imports:
5248
rewrite_types(entry, "#{}".format(import_name), False)
5349
if entry_id == "main":
54-
entry_id = "unpacked_{}".format(os.path.basename(source_uri))
55-
with open(entry_id, "w") as result_handle:
50+
entry_id = "unpacked_{}".format(os.path.basename(sourceIO.name))
51+
with open(entry_id, "w", encoding="utf-8") as result_handle:
5652
yaml.main.round_trip_dump(
5753
entry,
5854
result_handle,
@@ -159,7 +155,7 @@ def rewrite_schemadef(document: MutableMapping[str, Any]) -> Set[str]:
159155
for field in entry["fields"]:
160156
field["name"] = field["name"].split("/")[2]
161157
rewrite_types(field, entry_file, True)
162-
with open(entry_file[1:], "a") as entry_handle:
158+
with open(entry_file[1:], "a", encoding="utf-8") as entry_handle:
163159
yaml.dump([entry], entry_handle, Dumper=yaml.RoundTripDumper)
164160
entry["$import"] = entry_file[1:]
165161
del entry["name"]

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
ruamel.yaml<=0.16.5,>=0.12.4
2-
schema_salad
2+
schema-salad

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/usr/bin/env python3
22
import sys
3-
import os
43

54
from setuptools import find_packages, setup
65

tests/test_etools_to_clt.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
"""Test the CWL Expression refactoring tool."""
2-
from os import environ
32
from pathlib import Path
43

54
from cwltool.errors import WorkflowException

tests/test_graph_split.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Test the CWL $graph document splitter tool."""
22
import os
3+
from io import StringIO
34
from pathlib import Path
45
from unittest import TestCase
56

@@ -13,4 +14,6 @@
1314
def test_graph_split(tmp_path: Path):
1415
"""Confirm that a user provided example produces no exception."""
1516
os.chdir(tmp_path)
16-
run(requests.get(URI).text, URI)
17+
sourceIO = StringIO(requests.get(URI).text)
18+
sourceIO.name = URI
19+
run(sourceIO)

tox.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ setenv =
4646
commands =
4747
py{36,37,38,39}-unit: python -m pip install -U pip setuptools wheel
4848
py{36,37,38,39}-unit: python -m pip install -e .
49-
py{36,37,38,39}-unit: coverage run --parallel-mode -m pytest --strict {posargs}
49+
py{36,37,38,39}-unit: coverage run --parallel-mode -m pytest --strict tests {posargs}
5050
py{36,37,38,39}-unit: coverage combine
5151
py{36,37,38,39}-unit: coverage report
5252
py{36,37,38,39}-unit: coverage xml
@@ -55,7 +55,7 @@ commands =
5555
py{36,37,38,39}-lint: flake8 setup.py cwl_utils
5656
py{36,37,38,39}-lint: black --diff --check --exclude 'parser_v.*' setup.py cwl_utils
5757
py{36,37,38,39}-mypy: make mypy
58-
py{36,37,38,39}-mypy: make mypyc
58+
# py{36,37,38,39}-mypy: make mypyc
5959

6060
whitelist_externals =
6161
py{36,37,38,39}-lint: flake8

0 commit comments

Comments
 (0)