Skip to content

Commit 426564e

Browse files
authored
Merge pull request #645 from effigies/mnt/refurb
STY: Miscellaneous cleanups
2 parents 64bfa89 + 4da0a35 commit 426564e

30 files changed

+191
-204
lines changed

.circleci/config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ docs_deploy: &docs
3232
name: Deploy docs to gh-pages branch
3333
command: gh-pages --no-history --dotfiles --message "doc(update) [skip ci]" --dist docs/_build/html
3434

35-
version: 2
35+
version: 2.1
3636
jobs:
3737

3838
build_docs:
3939
docker:
40-
- image: python:3.7.4
40+
- image: cimg/python:3.11
4141
working_directory: /tmp/gh-pages
4242
environment:
4343
- FSLOUTPUTTYPE: NIFTI

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
napoleon_custom_sections = [("Inputs", "Parameters"), ("Outputs", "Parameters")]
9090

9191
# Intersphinx
92-
intersphinx_mapping = {"https://docs.python.org/3/": None}
92+
intersphinx_mapping = {"python": ("https://docs.python.org/3", None)}
9393

9494
# Linkcode
9595
# The following is used by sphinx.ext.linkcode to provide links to github

pydra/__init__.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,28 @@
1111

1212
import logging
1313

14-
logger = logging.getLogger("pydra")
14+
import __main__
15+
import attr
16+
17+
from . import mark
18+
from .engine import AuditFlag, DockerTask, ShellCommandTask, Submitter, Workflow, specs
19+
20+
__all__ = (
21+
"Submitter",
22+
"Workflow",
23+
"AuditFlag",
24+
"ShellCommandTask",
25+
"DockerTask",
26+
"specs",
27+
"mark",
28+
)
1529

1630
try:
1731
from ._version import __version__
1832
except ImportError:
1933
pass
2034

21-
from .engine import Submitter, Workflow, AuditFlag, ShellCommandTask, DockerTask, specs
22-
from . import mark
35+
logger = logging.getLogger("pydra")
2336

2437

2538
def check_latest_version():
@@ -29,8 +42,6 @@ def check_latest_version():
2942

3043

3144
# Run telemetry on import for interactive sessions, such as IPython, Jupyter notebooks, Python REPL
32-
import __main__
33-
3445
if not hasattr(__main__, "__file__"):
3546
from .engine.core import TaskBase
3647

@@ -39,8 +50,6 @@ def check_latest_version():
3950

4051

4152
# attr run_validators is set to False, but could be changed using use_validator
42-
import attr
43-
4453
attr.set_run_validators(False)
4554

4655

pydra/engine/audit.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
"""Module to keep track of provenance information."""
22
import os
3-
from pathlib import Path
43
import json
54
import attr
65
from ..utils.messenger import send_message, make_message, gen_uuid, now, AuditFlag
76
from .helpers import ensure_list, gather_runtime_info, hash_file
87
from .specs import attr_fields, File, Directory
98

9+
try:
10+
import importlib_resources
11+
except ImportError:
12+
import importlib.resources as importlib_resources # type: ignore
13+
1014

1115
class Audit:
1216
"""Handle provenance tracking and resource utilization."""
@@ -133,9 +137,8 @@ def audit_message(self, message, flags=None):
133137
134138
"""
135139
if self.develop:
136-
with open(
137-
Path(os.path.dirname(__file__)) / ".." / "schema/context.jsonld"
138-
) as fp:
140+
context_file = importlib_resources.files("pydra") / "schema/context.jsonld"
141+
with context_file.open() as fp:
139142
context = json.load(fp)
140143
else:
141144
context = {

pydra/engine/core.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ def _run(self, rerun=False, **kwargs):
491491
lockfile = self.cache_dir / (checksum + ".lock")
492492
# Eagerly retrieve cached - see scenarios in __init__()
493493
self.hooks.pre_run(self)
494-
logger.debug(f"'%s' is attempting to acquire lock on %s", self.name, lockfile)
494+
logger.debug("'%s' is attempting to acquire lock on %s", self.name, lockfile)
495495
with SoftFileLock(lockfile):
496496
if not (rerun or self.task_rerun):
497497
result = self.result()
@@ -1105,7 +1105,7 @@ async def _run(self, submitter=None, rerun=False, **kwargs):
11051105
lockfile = self.cache_dir / (checksum + ".lock")
11061106
self.hooks.pre_run(self)
11071107
logger.debug(
1108-
f"'%s' is attempting to acquire lock on %s with Pydra lock",
1108+
"'%s' is attempting to acquire lock on %s with Pydra lock",
11091109
self.name,
11101110
lockfile,
11111111
)
@@ -1231,7 +1231,7 @@ def _collect_outputs(self):
12311231
err_file = getattr(self, val.name).output_dir / "_error.pklz"
12321232
raise ValueError(
12331233
f"Task {val.name} raised an error, full crash report is here: "
1234-
f"{str(err_file)}"
1234+
f"{err_file}"
12351235
)
12361236
return attr.evolve(output, **output_wf)
12371237

pydra/engine/helpers_file.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ def template_update(inputs, output_dir, state_ind=None, map_copyfiles=None):
606606
for fld in fields_templ:
607607
if fld.type not in [str, ty.Union[str, bool]]:
608608
raise Exception(
609-
f"fields with output_file_template"
609+
"fields with output_file_template"
610610
" has to be a string or Union[str, bool]"
611611
)
612612
dict_mod[fld.name] = template_update_single(
@@ -638,7 +638,7 @@ def template_update_single(
638638
if spec_type == "input":
639639
if field.type not in [str, ty.Union[str, bool]]:
640640
raise Exception(
641-
f"fields with output_file_template"
641+
"fields with output_file_template"
642642
"has to be a string or Union[str, bool]"
643643
)
644644
inp_val_set = inputs_dict_st[field.name]

pydra/engine/helpers_state.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ def _add_name(mlist, name):
344344
if "." in elem or elem.startswith("_"):
345345
pass
346346
else:
347-
mlist[i] = "{}.{}".format(name, mlist[i])
347+
mlist[i] = f"{name}.{mlist[i]}"
348348
elif isinstance(elem, list):
349349
mlist[i] = _add_name(elem, name)
350350
elif isinstance(elem, tuple):

pydra/engine/state.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -454,13 +454,11 @@ def _remove_repeated(self, previous_splitters):
454454
f"{self.other_states}"
455455
)
456456

457-
repeated = set(
458-
[
459-
(el, previous_splitters.count(el))
460-
for el in previous_splitters
461-
if previous_splitters.count(el) > 1
462-
]
463-
)
457+
repeated = {
458+
(el, previous_splitters.count(el))
459+
for el in previous_splitters
460+
if previous_splitters.count(el) > 1
461+
}
464462
if repeated:
465463
# assuming that I want to remove from right
466464
previous_splitters.reverse()

pydra/engine/tests/conftest.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import pytest
2+
from pydra import set_input_validator
3+
4+
try:
5+
import importlib_resources
6+
except ImportError:
7+
import importlib.resources as importlib_resources
8+
9+
10+
@pytest.fixture(scope="package")
11+
def data_tests_dir():
12+
test_nii = importlib_resources.files("pydra").joinpath(
13+
"engine", "tests", "data_tests"
14+
)
15+
with importlib_resources.as_file(test_nii) as path:
16+
yield path
17+
18+
19+
@pytest.fixture()
20+
def use_validator():
21+
set_input_validator(flag=True)
22+
yield None
23+
set_input_validator(flag=False)

pydra/engine/tests/data_tests/loading.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import os
2-
3-
41
def loading(filename):
52
with open(filename) as f:
63
txt = f.read()

0 commit comments

Comments
 (0)