Skip to content

Commit

Permalink
#280, continuation
Browse files Browse the repository at this point in the history
  • Loading branch information
servoz committed Nov 27, 2023
1 parent 4e0fede commit 30aaa79
Show file tree
Hide file tree
Showing 9 changed files with 170 additions and 59 deletions.
4 changes: 4 additions & 0 deletions #processes/User_processes/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""blabla"""

from .test_pipeline_2 import Test_pipeline_2
from .test_pipeline_3 import Test_pipeline_3
43 changes: 43 additions & 0 deletions #processes/User_processes/test_pipeline_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-
"""blablabla"""

from capsul.api import Pipeline
import traits.api as traits


class Test_pipeline_2(Pipeline):
"""blablabla"""

def pipeline_definition(self):
"""blablabla"""

# nodes
self.add_process("smooth_1", "nipype.interfaces.spm.preprocess.Smooth")
self.add_process("smooth_2", "mia_processes.bricks.preprocess.spm.spatial_preprocessing.Smooth")

# links
self.export_parameter("smooth_1", "in_files", is_optional=False)
self.add_link("smooth_1._smoothed_files->smooth_2.in_files")
self.export_parameter("smooth_2", "smoothed_files", is_optional=False)

# parameters order

self.reorder_traits(("in_files", "smoothed_files"))

# nodes positions
self.node_position = {
"inputs": (-158.72567486702476, 0.0),
"smooth_1": (161.00348869401944, 63.69497664007747),
"smooth_2": (425.16579928888143, 187.1456296015163),
"outputs": (790.8471758506131, 187.1456296015163),
}

# nodes dimensions
self.node_dimension = {
"inputs": (86.19217025915623, 75.0),
"smooth_1": (232.625, 460.0),
"smooth_2": (233.578125, 215.0),
"outputs": (118.36291795522196, 62.0),
}

self.do_autoexport_nodes_parameters = False
26 changes: 26 additions & 0 deletions #processes/User_processes/test_pipeline_3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
"""blablabla"""

from capsul.api import Pipeline
import traits.api as traits


class Test_pipeline_3(Pipeline):
"""blablabla"""

def pipeline_definition(self):
"""blablabla"""

# nodes
self.add_process("smooth_1", "nipype.interfaces.spm.preprocess.Smooth")

# links
self.export_parameter("smooth_1", "in_files", is_optional=False)
self.export_parameter("smooth_1", "_smoothed_files", is_optional=True)
self.export_parameter("smooth_1", "_spm_script_file", is_optional=True)

# parameters order

self.reorder_traits(("in_files", "_smoothed_files", "_spm_script_file"))

self.do_autoexport_nodes_parameters = False
File renamed without changes.
150 changes: 95 additions & 55 deletions populse_mia/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,40 +242,6 @@
del mia_processes_dir
del mia_processes

# Adding personal libraries (User_processes: by default in Mia, but others
# can be added by developers):
# TODO: The same fix type will certainly have to be made in user more
# (for ~/.populse_mia/process' ).
mia_proc = os.path.join(
root_dev_dir, populse_bdir, "populse_mia", "processes"
)

if os.path.isdir(mia_proc):
mia_proc_dir = os.listdir(mia_proc)

if mia_proc_dir:
i += 1
sys.path.insert(i, mia_proc)
pypath.append(mia_proc)

for elt in mia_proc_dir:
print(
" . Using {0} package from {1}...".format(elt, mia_proc)
)

del mia_proc_dir

try:
del elt

except NameError:
# there is nothing in the "processes" directory!
os.mkdir(os.path.join(mia_proc, "User_processes"))
Path(
os.path.join(mia_proc, "User_processes", "__init__.py")
).touch()

del mia_proc
del root_dev_dir

elif "CASA_DISTRO" in os.environ:
Expand Down Expand Up @@ -680,7 +646,7 @@ def main():
parameter
- _cancel_clicked: exit form Mia
- _make_default_config: make default configuration
- _save_default_config: save default configuration
- _save_yml_file: save data in a YAML file
- _verify_miaConfig: check the config and try to fix if necessary
"""

Expand Down Expand Up @@ -736,8 +702,13 @@ def _cancel_clicked(dialog):
def _make_default_config(dialog):
"""Make default configuration.
Default directories and configuration files are created only if they
do not exist (they are not overwritten if they already exist).
Default directories (properties_path/properties,
properties_path/processes/User_processes), configuration files
(properties_path/properties/saved_projects.yml,
properties_path/properties/config.yml) and
properties_path/processes/User_processes__init__.py are created
only if they do not exist (they are not overwritten if they already
exist).
:param dialog: QtWidgets.QDialog object ('msg' in the main function)
"""
Expand Down Expand Up @@ -772,7 +743,7 @@ def _make_default_config(dialog):
if not os.path.exists(
os.path.join(properties_dir, "saved_projects.yml")
):
_save_default_config(
_save_yml_file(
{"paths": []},
os.path.join(properties_dir, "saved_projects.yml"),
)
Expand All @@ -783,7 +754,7 @@ def _make_default_config(dialog):
)

if not os.path.exists(os.path.join(properties_dir, "config.yml")):
_save_default_config(
_save_yml_file(
"gAAAAABd79UO5tVZSRNqnM5zzbl0KDd7Y98KCSKCNizp9aDq"
"ADs9dAQHJFbmOEX2QL_jJUHOTBfFFqa3OdfwpNLbvWNU_rR0"
"VuT1ZdlmTYv4wwRjhlyPiir7afubLrLK4Jfk84OoOeVtR0a5"
Expand Down Expand Up @@ -832,7 +803,7 @@ def _make_default_config(dialog):

print("\nDefault configuration checked.\n")

def _save_default_config(a_dic, a_file):
def _save_yml_file(a_dic, a_file):
"""Save data in a YAML file.
:param a_dic: a dictionary
Expand Down Expand Up @@ -870,16 +841,22 @@ def _verify_miaConfig(dialog=None):
:param dialog: QtWidgets.QDialog object ('msg' in the main function)
"""

if dialog is not None and not dialog.file_line_edit.text():
# FIXME: Shouldn't we carry out a more thorough invalidity check
# (we're only checking the empty string here)?
print("Warning: configuration root directory is invalid...")
return

save_flag = False
config = None

if dialog is not None:
if not dialog.file_line_edit.text():
# FIXME: Shouldn't we carry out a more thorough invalidity
# check (we're only checking the empty
# string here)?
print("Warning: configuration root directory is invalid...")
msg = QMessageBox()
msg.setIcon(QMessageBox.Warning)
msg.setWindowTitle("Mia configuration Error")
msg.setText("No configuration path found...")
msg.exec()
return

with open(dot_mia_config, "r") as stream:
try:
if verCmp(yaml.__version__, "5.1", "sup"):
Expand All @@ -906,7 +883,22 @@ def _verify_miaConfig(dialog=None):
mia_home_properties_path = dict()

mia_home_properties_path_new = dict()
_make_default_config(dialog)

try:
_make_default_config(dialog)

except Exception as e:
print(
"\nAutomatic configuration fails: {0} ...".format(
e,
)
)
msg = QMessageBox()
msg.setIcon(QMessageBox.Warning)
msg.setWindowTitle("Mia configuration Error")
msg.setText("Automatic configuration fails...")
msg.exec()
return

if DEV_MODE:
mia_home_properties_path_new[
Expand Down Expand Up @@ -937,17 +929,24 @@ def _verify_miaConfig(dialog=None):
print("- {0}: {1}".format(key, value))

print()
_save_default_config(mia_home_properties_path, dot_mia_config)
_save_yml_file(mia_home_properties_path, dot_mia_config)

try:
config = Config()

# Check properties/config.yml by checking if
# key == 'name' / value == 'MIA':
if config.config["name"] != "MIA":
raise yaml.YAMLError(
"\nThe '{}' file seems to be "
"corrupted...\n".format(dot_mia_config)
)

if not config.get_admin_hash():
config.set_admin_hash(
"60cfd1916033576b0f2368603fe612fb"
"78b8c20e4f5ad9cf39c9cf7e912dd282"
)
dialog.close()

except Exception as e:
print(
Expand All @@ -956,7 +955,15 @@ def _verify_miaConfig(dialog=None):
e,
)
)
raise
msg = QMessageBox()
msg.setIcon(QMessageBox.Warning)
msg.setWindowTitle("Mia configuration Error")
msg.setText("No configuration path found...")
msg.exec()
return

else:
dialog.close()

else:
config = Config()
Expand Down Expand Up @@ -989,6 +996,8 @@ def _verify_miaConfig(dialog=None):
if save_flag is True:
config.saveConfig()

# The directory in which the configuration is located must be
# declared in ~/.populse_mia/configuration_path.yml
dot_mia_config = os.path.join(
os.path.expanduser("~"), ".populse_mia", "configuration_path.yml"
)
Expand Down Expand Up @@ -1019,7 +1028,8 @@ def _verify_miaConfig(dialog=None):
if mia_home_properties_path is None:
raise yaml.YAMLError(
"\nThe '{}' file seems to be "
"corrupted...\n".format(dot_mia_config)
"corrupted or the configuration has never "
"been initialized...\n".format(dot_mia_config)
)

if DEV_MODE and "properties_dev_path" not in mia_home_properties_path:
Expand All @@ -1035,7 +1045,7 @@ def _verify_miaConfig(dialog=None):
"\nNo properties path found in {}...\n".format(dot_mia_config)
)

_save_default_config(mia_home_properties_path, dot_mia_config)
_save_yml_file(mia_home_properties_path, dot_mia_config)
_verify_miaConfig()

except Exception as e:
Expand Down Expand Up @@ -1079,10 +1089,40 @@ def _verify_miaConfig(dialog=None):
msg.setLayout(vbox_layout)
msg.exec()

global pypath
# Adding personal libraries User_processes (and others if any) to sys.path
# and to pypath.
config = Config()
properties_path = config.get_properties_path()
user_proc = os.path.join(properties_path, "processes")

if DEV_MODE and pypath:
config = Config()
if os.path.isdir(user_proc):
user_proc_dir = os.listdir(user_proc)

if user_proc_dir:
sys.path.append(user_proc)
pypath.append(user_proc)

for elt in user_proc_dir:
print(
" . Using {0} package from {1}...".format(elt, user_proc)
)

del user_proc_dir

try:
del elt

except NameError:
# There's nothing in the "processes" directory! Let's try to fix
# it and put at least one valid directory User_processes
os.mkdir(os.path.join(user_proc, "User_processes"))
Path(
os.path.join(user_proc, "User_processes", "__init__.py")
).touch()

# global pypath

if pypath:
config.get_capsul_engine()
c = config.get_capsul_config()
pc = (
Expand Down
4 changes: 2 additions & 2 deletions populse_mia/software_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def __init__(self, config_path=None):

else:
# FIXME: What can we do if "MIA_DEV_MODE" is not in os.environ?
print("\nMIA_DEV_MODE not found ...\n")
print("\nMIA_DEV_MODE not found...\n")

self.properties_path = None
self.config = self.loadConfig()
Expand Down Expand Up @@ -487,7 +487,7 @@ def get_config_path(self):

config_path = getattr(self, "config_path", None)

if config_path:
if config_path is not None:
return config_path

return os.path.join(self.get_properties_path(), "properties")
Expand Down
Empty file.
1 change: 0 additions & 1 deletion properties/config.yml

This file was deleted.

1 change: 0 additions & 1 deletion properties/saved_projects.yml

This file was deleted.

0 comments on commit 30aaa79

Please sign in to comment.