Skip to content

Commit 59a92df

Browse files
committed
Autogenerate setup.py for slicer
1 parent b09499d commit 59a92df

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

nipype/interfaces/slicer/generate_classes.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def add_class_to_package(class_codes, class_names, module_name, package_dir):
2626

2727

2828
def crawl_code_struct(code_struct, package_dir):
29+
subpackages = []
2930
for k, v in code_struct.iteritems():
3031
if isinstance(v, str) or isinstance(v, unicode):
3132
module_name = k.lower()
@@ -36,6 +37,7 @@ def crawl_code_struct(code_struct, package_dir):
3637
module_name = k.lower()
3738
add_class_to_package(v.values(), v.keys(), module_name, package_dir)
3839
else:
40+
subpackages.append(k.lower())
3941
f_i = open(os.path.join(package_dir, "__init__.py"), 'a+')
4042
f_i.write("from %s import *\n" % k.lower())
4143
f_i.close()
@@ -44,6 +46,24 @@ def crawl_code_struct(code_struct, package_dir):
4446
rmtree(new_pkg_dir)
4547
os.mkdir(new_pkg_dir)
4648
crawl_code_struct(v, new_pkg_dir)
49+
if subpackages:
50+
f = open(os.path.join(package_dir, "setup.py"), 'w')
51+
f.write("""# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
52+
# vi: set ft=python sts=4 ts=4 sw=4 et:
53+
def configuration(parent_package='',top_path=None):
54+
from numpy.distutils.misc_util import Configuration
55+
56+
config = Configuration('{pkg_name}', parent_package, top_path)
57+
58+
{sub_pks}
59+
60+
return config
61+
62+
if __name__ == '__main__':
63+
from numpy.distutils.core import setup
64+
setup(**configuration(top_path='').todict())
65+
""".format(pkg_name=package_dir.split("/")[-1], sub_pks="\n ".join(["config.add_data_dir('%s')"%sub_pkg for sub_pkg in subpackages])))
66+
f.close()
4767

4868

4969
def generate_all_classes(modules_list=[], launcher=[]):

nipype/interfaces/slicer/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ def configuration(parent_package='',top_path=None):
66
config = Configuration('slicer', parent_package, top_path)
77

88
config.add_data_dir('diffusion')
9+
config.add_data_dir('segmentation')
910
config.add_data_dir('filtering')
1011
config.add_data_dir('legacy')
11-
config.add_data_dir('segmentation')
1212

1313
return config
1414

0 commit comments

Comments
 (0)