Skip to content

Commit dc9fe56

Browse files
authored
Merge pull request #20 from nipype/enable-complete-tests
enabled test_package unittests
2 parents f9351a4 + b156c76 commit dc9fe56

File tree

7 files changed

+94
-27
lines changed

7 files changed

+94
-27
lines changed

.github/workflows/ci-cd.yml

+1
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ jobs:
158158
- freesurfer
159159
- mriqc
160160
- niworkflows
161+
- nireports
161162
steps:
162163

163164
- name: Trigger post-release on downstream repos

nipype2pydra/cli/convert.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,16 @@ def convert(
6565

6666
# Clean previous version of output dir
6767
package_dir = converter.package_dir(package_root)
68-
output_dir = package_dir / "auto" if converter.interface_only else package_dir
69-
if output_dir.exists():
70-
shutil.rmtree(output_dir)
68+
if converter.interface_only:
69+
shutil.rmtree(package_dir / "auto")
70+
else:
71+
for fspath in package_dir.iterdir():
72+
if fspath == package_dir / "__init__.py":
73+
continue
74+
if fspath.is_dir():
75+
shutil.rmtree(fspath)
76+
else:
77+
fspath.unlink()
7178

7279
# Load interface specs
7380
for fspath in interface_yamls:

nipype2pydra/helpers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ def _converted_code(self) -> ty.Tuple[str, ty.List[str]]:
391391

392392
used_configs = set()
393393
parts = re.split(
394-
r"\n (?=[^\s])", replace_undefined(self.src), flags=re.MULTILINE
394+
r"\n (?!\s|\))", replace_undefined(self.src), flags=re.MULTILINE
395395
)
396396
converted_parts = []
397397
for part in parts:

nipype2pydra/package.py

+41-5
Original file line numberDiff line numberDiff line change
@@ -1023,13 +1023,9 @@ def write_pkg_inits(
10231023
names : List[str]
10241024
The names to import in the __init__.py files
10251025
"""
1026-
parts = module_name.split(".")
10271026
# Write base init path that imports __version__ from the auto-generated _version
10281027
# file
1029-
base_init_fspath = package_root.joinpath(*parts, "__init__.py")
1030-
if not base_init_fspath.exists():
1031-
with open(base_init_fspath, "w") as f:
1032-
f.write("from ._version import __version__")
1028+
parts = module_name.split(".")
10331029
for i, part in enumerate(reversed(parts[depth:]), start=1):
10341030
mod_parts = parts[:-i]
10351031
parent_mod = ".".join(mod_parts)
@@ -1104,3 +1100,43 @@ def write_pkg_inits(
11041100

11051101
with open(init_fspath, "w") as f:
11061102
f.write(code_str)
1103+
1104+
BASE_INIT_TEMPLATE = """\"\"\"
1105+
This is a basic doctest demonstrating that the package and pydra can both be successfully
1106+
imported.
1107+
1108+
>>> import pydra.engine
1109+
>>> import pydra.tasks.{pkg}
1110+
\"\"\"
1111+
1112+
from warnings import warn
1113+
from pathlib import Path
1114+
1115+
pkg_path = Path(__file__).parent.parent
1116+
1117+
try:
1118+
from ._version import __version__
1119+
except ImportError:
1120+
raise RuntimeError(
1121+
"pydra-{pkg} has not been properly installed, please run "
1122+
f"`pip install -e {str(pkg_path)}` to install a development version"
1123+
)
1124+
if "nipype" not in __version__:
1125+
try:
1126+
from ._post_release import src_pkg_version, nipype2pydra_version
1127+
except ImportError:
1128+
warn(
1129+
"Nipype interfaces haven't been automatically converted from their specs in "
1130+
f"`nipype-auto-conv`. Please run `{str(pkg_path / 'nipype-auto-conv' / 'generate')}` "
1131+
"to generated the converted Nipype interfaces in pydra.tasks.{pkg}.auto"
1132+
)
1133+
else:
1134+
n_ver = src_pkg_version.replace(".", "_")
1135+
n2p_ver = nipype2pydra_version.replace(".", "_")
1136+
__version__ += (
1137+
"_" if "+" in __version__ else "+"
1138+
) + f"nipype{n_ver}_nipype2pydra{n2p_ver}"
1139+
1140+
1141+
__all__ = ["__version__"]
1142+
"""

nipype2pydra/tests/test_package.py

+33-17
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,33 @@
1616
"pydra-afni",
1717
],
1818
"mriqc": [
19+
"nipype2pydra",
1920
"pydra-ants",
2021
"pydra-afni",
2122
"pydra-fsl",
2223
"pydra-mrtrix3 >=3.0.3a0",
2324
"fileformats-medimage-afni-extras",
2425
"fileformats-medimage-mrtrix3-extras",
2526
"fileformats-medimage-fsl-extras",
27+
"statsmodels",
28+
"dipy",
29+
"bids",
30+
"pydra-niworkflows",
31+
"pydra-nireports",
32+
"matplotlib",
33+
"seaborn",
34+
"templateflow",
35+
"nilearn",
36+
# "nibael",
37+
# "nilearn",
38+
# "migas >= 0.4.0",
39+
# "pandas ~=1.0",
40+
# "pydra >=0.22",
41+
# "PyYAML",
42+
# "scikit-learn",
43+
# "scipy",
44+
# "statsmodel",
45+
# "torch",
2646
],
2747
}
2848

@@ -32,7 +52,7 @@ def package_spec(request):
3252
return EXAMPLE_PKG_GEN_DIR / f"{request.param}.yaml"
3353

3454

35-
@pytest.mark.xfail(reason="Fails due to missing dependencies on PyPI")
55+
@pytest.mark.xfail(reason="Don't have time to debug at the moment")
3656
def test_package_complete(package_spec, cli_runner, tmp_path, tasks_template_args):
3757
pkg_name = package_spec.stem
3858
repo_output = tmp_path / "repo"
@@ -79,19 +99,15 @@ def test_package_complete(package_spec, cli_runner, tmp_path, tasks_template_arg
7999

80100
sp.check_call([sys.executable, "-m", "venv", str(venv_path)])
81101
pip_cmd = [venv_python, "-m", "pip", "install", "-e", str(pkg_root) + "[test]"]
82-
try:
83-
sp.check_call(pip_cmd)
84-
except sp.CalledProcessError:
85-
raise RuntimeError(
86-
f"Failed to install package {pkg_name} with command:\n{' '.join(pip_cmd)}"
87-
)
88-
pytest_cmd = [venv_pytest, str(pkg_root)]
89-
try:
90-
pytest_output = sp.check_output(pytest_cmd)
91-
except sp.CalledProcessError:
92-
raise RuntimeError(
93-
f"Tests of generated package '{pkg_name}' failed when running:\n{' '.join(pytest_cmd)}"
94-
)
95-
96-
assert "fail" not in pytest_output
97-
assert "error" not in pytest_output
102+
p = sp.Popen(pip_cmd, stdout=sp.PIPE, stderr=sp.STDOUT)
103+
pip_output, _ = p.communicate()
104+
pip_output = pip_output.decode("utf-8")
105+
assert (
106+
not p.returncode
107+
), f"Failed to install package pydra-{pkg_name} with command:\n{' '.join(pip_cmd)}:\n\n{pip_output}"
108+
p = sp.Popen([venv_pytest, str(pkg_root)], stderr=sp.PIPE, stdout=sp.STDOUT)
109+
pytest_output, _ = p.communicate()
110+
pytest_output = pytest_output.decode("utf-8")
111+
assert (
112+
p.returncode
113+
), f"Tests for pydra-{pkg_name} package (\n{' '.join(pip_cmd)}) failed:\n\n{pytest_output}"

nipype2pydra/workflow.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,11 @@ def type_repr_(t):
122122
+ "]"
123123
)
124124
if t in (ty.Any, ty.Union, ty.List, ty.Tuple):
125-
return f"ty.{t.__name__}"
125+
try:
126+
t_name = t.__name__
127+
except AttributeError:
128+
t_name = t._name
129+
return f"ty.{t_name}"
126130
elif issubclass(t, Field):
127131
return t.primitive.__name__
128132
elif issubclass(t, FileSet):

pyproject.toml

+3
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,11 @@ test = [
5555
"fileformats-medimage-fsl",
5656
"niworkflows",
5757
"mriqc",
58+
"nipy",
5859
"nireports",
5960
"nitime",
61+
"datalad",
62+
"nirodents",
6063
]
6164
docs = [
6265
"packaging",

0 commit comments

Comments
 (0)