Skip to content

Commit 6fe9a99

Browse files
committed
for non-interface-only packages don't delete everything, leave the __init__.py
1 parent 44a2d31 commit 6fe9a99

File tree

2 files changed

+50
-7
lines changed

2 files changed

+50
-7
lines changed

nipype2pydra/cli/convert.py

Lines changed: 10 additions & 3 deletions
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/package.py

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,10 +1025,6 @@ def write_pkg_inits(
10251025
"""
10261026
# Write base init path that imports __version__ from the auto-generated _version
10271027
# file
1028-
base_init_fspath = package_root.joinpath(*self.name, "__init__.py")
1029-
if not base_init_fspath.exists():
1030-
with open(base_init_fspath, "w") as f:
1031-
f.write("from ._version import __version__")
10321028
parts = module_name.split(".")
10331029
for i, part in enumerate(reversed(parts[depth:]), start=1):
10341030
mod_parts = parts[:-i]
@@ -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+
"""

0 commit comments

Comments
 (0)