Commit 379733a7 authored by Samuel GAIST's avatar Samuel GAIST Committed by Samuel GAIST

[widgets][experimenteditor] Implement support for new environment file format

Now the user has the choice to configure a remote
or docker environment. This allows for local testing
and then select a suitable environment for the platform.
parent 885baf8a
......@@ -94,8 +94,17 @@ def test_prefix():
env_file.write(
json.dumps(
{
"Test Env": {"name": "Python 2.7", "version": "1.3.0"},
"Another test Env": {"name": "another test", "version": "1.1.1"},
"remote": [
{"name": "Python 2.7", "version": "1.3.0"},
{"name": "Python", "version": "2.0.0"},
],
"docker": {
"Docker test env": {"name": "Pytorch", "version": "1.1.1"},
"Second Docker test env": {
"name": "Pytorch 1.0",
"version": "2.1.1",
},
},
}
)
)
......
......@@ -116,6 +116,13 @@ def parameter_choice_map(prefix_path, algorithm_name):
}
def change_index(index):
if index > 0:
return index - 1
else:
return index + 1
# ------------------------------------------------------------------------------
# Fixtures
......@@ -506,7 +513,7 @@ class TestEnvironmentModel:
model = EnvironmentModel()
model.setContext(beat_context)
assert model.rowCount() == 2
assert model.rowCount() == 4
def test_visual_name(self, beat_context):
model = EnvironmentModel()
......@@ -1066,7 +1073,8 @@ class TestGlobalParametersEditor:
def test_change_environment(self, qtbot, gpe_editor, exp_globals):
gpe_editor.load(exp_globals)
with qtbot.waitSignal(gpe_editor.dataChanged):
gpe_editor.environment_combobox.setCurrentIndex(1)
index = gpe_editor.environment_combobox.currentIndex()
gpe_editor.environment_combobox.setCurrentIndex(change_index(index))
assert gpe_editor.dump() != exp_globals
def test_change_queue(self, qtbot, gpe_editor, exp_globals):
......@@ -1190,8 +1198,10 @@ class TestExperimentEditor:
block_editor = list_widget.widget_list[0]
properties_editor = block_editor.properties_editor
combobox = properties_editor.environment_combobox
with qtbot.waitSignal(experiment_editor.dataChanged):
combobox.setCurrentIndex(1)
index = combobox.currentIndex()
combobox.setCurrentIndex(change_index(index))
dump = experiment_editor.dump_json()
assert dump != experiment_declaration
......
......@@ -125,18 +125,28 @@ class EnvironmentModel(QStandardItemModel):
def refreshContent(self):
self.clear()
if self.context is not None:
def add_row(type_, data):
visual_name = "{name} ({version})".format(**data)
icon = QIcon(f":/resources/{type_}")
self.appendRow(
[
QStandardItem(icon, visual_name),
QStandardItem(data["name"]),
QStandardItem(data["version"]),
]
)
with open(self.context.meta["environments"], "rt") as file_:
json_data = json.load(file_)
for docker_name, data in json_data.items():
remote_data = json_data.get("remote", {})
for data in remote_data:
add_row("remote", data)
docker_data = json_data.get("docker", {})
for _, data in docker_data.items():
if "databases" not in data:
visual_name = "{name} ({version})".format(**data)
self.appendRow(
[
QStandardItem(visual_name),
QStandardItem(data["name"]),
QStandardItem(data["version"]),
]
)
add_row("docker", data)
def setContext(self, context):
self.context = context
......@@ -1144,9 +1154,10 @@ class GlobalParametersEditor(AbstractBaseEditor):
def load(self, json_object):
self.json_object = copy.deepcopy(json_object)
environment = self.json_object["environment"]
env_text = "{} ({})".format(environment["name"], environment["version"])
self.environment_combobox.setCurrentText(env_text)
environment = self.json_object.get("environment")
if environment:
env_text = "{} ({})".format(environment["name"], environment["version"])
self.environment_combobox.setCurrentText(env_text)
parameters = [
item
......@@ -1172,11 +1183,11 @@ class GlobalParametersEditor(AbstractBaseEditor):
def dump(self):
data = copy.deepcopy(self.json_object)
if self.environment_changed:
if self.environment_changed or "environment" not in data:
model = self.environment_combobox.model()
index = model.index(self.environment_combobox.currentIndex(), 0)
data["environment"] = model.environment(index)
if self.queue_changed:
if self.queue_changed or "queue" not in data:
data["queue"] = self.queue_combobox.currentText()
for widget in self.parameters_editor_listwidget.widget_list:
......@@ -1430,9 +1441,9 @@ class ExperimentEditor(AbstractAssetEditor):
self.tabwidget.tabBar().setTabEnabled(
self.loops_widget_index, "loops" in json_object
)
globals_ = json_object.get("globals")
if globals_:
self.globalparameters_widget.load(globals_)
globals_ = json_object.get("globals", {})
self.globalparameters_widget.load(globals_)
def _dump_json(self):
"""Returns the json representation of the asset"""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment