Skip to content

Commit 309f48d

Browse files
committed
mypyc fixes
1 parent 822a16a commit 309f48d

File tree

7 files changed

+39
-28
lines changed

7 files changed

+39
-28
lines changed

cwl_utils/hello.simg

4.03 KB
Binary file not shown.

cwl_utils/inputs_schema_gen.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import sys
1111
from contextlib import suppress
1212
from copy import deepcopy
13+
from importlib.resources import files
1314
from pathlib import Path
1415
from typing import Any, TypeGuard, Union
1516
from urllib.parse import urlparse
@@ -59,13 +60,6 @@
5960
"null": "null",
6061
}
6162

62-
JSON_TEMPLATE_PATH = (
63-
Path(__file__)
64-
.parent.joinpath("./templates/workflow_input_json_schema_template.json")
65-
.absolute()
66-
.resolve()
67-
)
68-
6963
# Some type hinting
7064
InputType = Union[
7165
InputArraySchema, InputEnumSchema, InputRecordSchema, str, File, Directory
@@ -343,7 +337,12 @@ def cwl_to_jsonschema(cwl_obj: Workflow | CommandLineTool) -> Any:
343337
344338
"""
345339
# Initialise the schema from the workflow input json schema template
346-
with JSON_TEMPLATE_PATH.open() as template_h:
340+
341+
with (
342+
files("cwl-utils")
343+
.joinpath("./templates/workflow_input_json_schema_template.json")
344+
.open() as template_h
345+
):
347346
input_json_schema = json.load(template_h)
348347

349348
# Get the complex schema keys

cwl_utils/sandboxjs.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from cwl_utils.types import CWLOutputType
2626
from cwl_utils.utils import singularity_supports_userns
2727

28-
default_timeout = 20
28+
default_timeout: float = 20
2929
"""Default number of seconds to wait while running a javascript engine."""
3030

3131
seg_symbol = r"""\w+"""
@@ -66,7 +66,15 @@ def stdfmt(data: str) -> str:
6666
class JSEngine(ABC):
6767
@abstractmethod
6868
def eval(
69-
self, scan: str, jslib: str = "", **kwargs: Any
69+
self,
70+
scan: str,
71+
jslib: str = "",
72+
timeout: float = default_timeout,
73+
force_docker_pull: bool = False,
74+
debug: bool = False,
75+
js_console: bool = False,
76+
container_engine: str = "docker",
77+
**kwargs: Any,
7078
) -> CWLOutputType | Awaitable[CWLOutputType]: ...
7179

7280
@abstractmethod

cwl_utils/tests/test_examples.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@
22
"""Tests of example Python scripts."""
33
import os
44
import runpy
5+
from importlib.resources import as_file, files
56
from pathlib import Path
67

78

89
def test_load_example() -> None:
910
"""Test the load_cwl_by_path.py script."""
1011
cwd = Path.cwd()
11-
parent = Path(__file__).resolve().parent
12-
os.chdir(parent.parent)
13-
result_raw = runpy.run_path(str(parent / "load_cwl_by_path.py"))
14-
os.chdir(cwd)
12+
target = files("cwl_utils/tests").joinpath("load_cwl_by_path.py")
13+
with as_file(target) as target_path:
14+
os.chdir(target_path.parent)
15+
result_raw = runpy.run_path(str(target_path))
16+
os.chdir(cwd)
1517
result = result_raw["saved_obj"]
1618
assert result["class"] == "Workflow"

cwl_utils/tests/util.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,10 @@ def get_path(filename: str) -> Path:
1212
"""Get the filepath for a given test file."""
1313
# normalizing path depending on OS or else it will cause problem when joining path
1414
filename = os.path.normpath(filename)
15-
filepath = None
16-
try:
17-
file_manager = ExitStack()
18-
atexit.register(file_manager.close)
19-
traversable = files("cwl-utils") / filename
20-
filepath = file_manager.enter_context(as_file(traversable))
21-
except ModuleNotFoundError:
22-
pass
23-
if not filepath or not filepath.is_file():
24-
filepath = Path(os.path.dirname(__file__), os.pardir, filename)
15+
file_manager = ExitStack()
16+
atexit.register(file_manager.close)
17+
traversable = files("cwl_utils") / filename
18+
filepath = file_manager.enter_context(as_file(traversable))
2519
return filepath.resolve()
2620

2721

cwl_utils/utils.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# SPDX-License-Identifier: Apache-2.0
22
"""Miscellaneous utility functions."""
3-
import os
43
import pathlib
54
import subprocess # nosec
65
import sys
@@ -9,8 +8,8 @@
98
import urllib.request
109
from collections.abc import MutableMapping, MutableSequence
1110
from copy import deepcopy
11+
from importlib.resources import files
1212
from io import StringIO
13-
from pathlib import Path
1413
from typing import Any
1514
from urllib.parse import urlparse
1615

@@ -215,7 +214,7 @@ def singularity_supports_userns() -> bool:
215214
global _USERNS # pylint: disable=global-statement
216215
if _USERNS is None:
217216
try:
218-
hello_image = Path(os.path.dirname(__file__), "hello.simg")
217+
hello_image = files("cwl_utils").joinpath("hello.simg")
219218
result = subprocess.Popen( # nosec
220219
["singularity", "exec", "--userns", str(hello_image), "true"],
221220
stderr=subprocess.PIPE,

pyproject.toml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ include = [
9090
"/*requirements.txt",
9191
"/cwl_utils/**.py",
9292
"/cwl_utils/*.js",
93+
"/cwl_utils/parser/*.py",
9394
"/cwl_utils/tests/**.py",
9495
"/cwl_utils/templates/*",
9596
"/cwl_utils/testdata/*.cwl",
@@ -129,6 +130,7 @@ include = [
129130
"/LICENSE",
130131
"/cwl_utils/**.py",
131132
"/cwl_utils/*.js",
133+
"/cwl_utils/parser/*.py",
132134
"/cwl_utils/tests/**.py",
133135
"/cwl_utils/templates/*",
134136
"/cwl_utils/testdata/*.cwl",
@@ -153,13 +155,20 @@ enable-by-default = false
153155
dependencies = [
154156
"hatch-mypyc>=0.16.0",
155157
"mypy==1.19.0",
158+
"types-requests",
159+
"types-jsonschema",
160+
"types-setuptools>=57.4.0",
156161
]
157162
require-runtime-dependencies = true
158163
exclude = [
159164
"/create_cwl_from_objects.py",
160165
"/load_cwl_by_path.py",
166+
"/cwl_utils/tests",
167+
"/cwl_utils/testdata",
168+
]
169+
include = [
170+
"/cwl_utils/parser",
161171
]
162-
163172

164173
[tool.hatch.envs.test]
165174
features = ["testing"]

0 commit comments

Comments
 (0)