Skip to content

Commit

Permalink
Merge pull request #15 from maxfordham:🐛-fix-clear-console-button
Browse files Browse the repository at this point in the history
🐛-fix-clear-console-button
  • Loading branch information
jgunstone authored Jul 7, 2022
2 parents 0fe76f0 + ec9ae7e commit 59fa383
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 159 deletions.
8 changes: 1 addition & 7 deletions docs/examples/linegraph/linegraph_app.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "2e82c6e5e6f04ad2a34b15a8f9e12da3",
"model_id": "5248ebdc233747b5aef56c5738cb130c",
"version_major": 2,
"version_minor": 0
},
Expand Down Expand Up @@ -115,12 +115,6 @@
"\n",
"\n",
"class LineGraphBatchActions(BatchShellActions):\n",
" @validator(\"config\", always=True)\n",
" def _config(cls, v, values):\n",
" \"\"\"bundles RunApp up as a single argument callable\"\"\"\n",
" if type(v) == dict:\n",
" v = LineGraphConfigBatch(**v)\n",
" return v\n",
"\n",
" @validator(\"runlog_show\", always=True)\n",
" def _runlog_show(cls, v, values):\n",
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -91,50 +91,6 @@
"params": {},
"shell_template": "{{ call }} {{ run }}{% for f in fpths_inputs %} {{f}}{% endfor %}{% for f in fpths_outputs %} {{f}}{% endfor %}{% for k,v in params.items()%} --{{k}} {{v}}{% endfor %}\n",
"shell": "python -O -m linegraph_core 01-linegraph_core/in-01-linegraph_core.lg.json 01-linegraph_core/out-01-linegraph_core.csv 01-linegraph_core/out-01-linegraph_core.plotly.json"
},
{
"index": 2,
"path_run": "/mnt/c/engDev/git_mf/ipyrun/docs/examples/linegraph/linegraph_core",
"pythonpath": "/mnt/c/engDev/git_mf/ipyrun/docs/examples/linegraph",
"run": "linegraph_core",
"name": "linegraph_core",
"long_name": "02 - Linegraph Core",
"key": "02-linegraph_core",
"fdir_root": "/mnt/c/engDev/git_mf/ipyrun/docs/examples/linegraph/linegraph_appdata",
"fdir_appdata": "02-linegraph_core",
"in_batch": false,
"status": "no_outputs",
"update_config_at_runtime": false,
"autodisplay_definitions": [
{
"path": "/mnt/c/engDev/git_mf/ipyrun/docs/examples/linegraph/linegraph_core/input_schema_linegraph.py",
"obj_name": "LineGraph",
"module_name": "input_schema_linegraph",
"ftype": "in",
"ext": ".lg.json"
}
],
"autodisplay_inputs_kwargs": {
"patterns": "*"
},
"autodisplay_outputs_kwargs": {
"patterns": "*.plotly.json"
},
"fpths_inputs": [
"02-linegraph_core/in-02-linegraph_core.lg.json"
],
"fpths_outputs": [
"02-linegraph_core/out-02-linegraph_core.csv",
"02-linegraph_core/out-02-linegraph_core.plotly.json"
],
"fpth_params": null,
"fpth_config": "02-linegraph_core/config-shell_handler.json",
"fpth_runhistory": "02-linegraph_core/runhistory.csv",
"fpth_log": "02-linegraph_core/log.csv",
"call": "python -O -m",
"params": {},
"shell_template": "{{ call }} {{ run }}{% for f in fpths_inputs %} {{f}}{% endfor %}{% for f in fpths_outputs %} {{f}}{% endfor %}{% for k,v in params.items()%} --{{k}} {{v}}{% endfor %}\n",
"shell": "python -O -m linegraph_core 02-linegraph_core/in-02-linegraph_core.lg.json 02-linegraph_core/out-02-linegraph_core.csv 02-linegraph_core/out-02-linegraph_core.plotly.json"
}
]
}
39 changes: 19 additions & 20 deletions src/ipyrun/runshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# #%load_ext lab_black

# +
# TODO: make the config shell commands relative rather than absolute (improves readability)


# +
# core libs
Expand Down Expand Up @@ -61,6 +61,7 @@
display_pydantic_json,
check_installed,
)
from ipyrun.constants import BUTTON_WIDTH_MIN


# from this repo
Expand All @@ -86,8 +87,6 @@
else:
get_fpth_win = lambda v: v

# display_template_ui_model() # TODO: add this to docs


def get_mfuser_initials():
user = getpass.getuser()
Expand Down Expand Up @@ -393,23 +392,25 @@ def get_env(append_to_pythonpath: str):
return env


from ipyrun.constants import BUTTON_WIDTH_MIN
def make_run_hide(fn_on_click):
run_hide = widgets.Button(
layout={"width": BUTTON_WIDTH_MIN}, icon="fa-times", button_style="danger",
)
run_hide.on_click(fn_on_click)
return run_hide


def run_shell(app=None):
def run_shell(app=None, display_hide_btn=True):
"""
app=None
"""
if app.config.update_config_at_runtime:
app.config = app.config
# ^ this updates config and remakes run actions using the setter.
# useful if, for example, output fpths dependent on contents of input files

run_hide = widgets.Button(
layout={"width": BUTTON_WIDTH_MIN}, icon="fa-times", button_style="danger",
)
run_hide.on_click(app._run_hide)
display(run_hide)
if display_hide_btn:
run_hide = make_run_hide(app._run_hide) # button to hide the run console
display(run_hide)
print(f"run { app.config.key}")
if app.status == "up_to_date":
print(f"already up-to-date")
Expand Down Expand Up @@ -709,13 +710,18 @@ def check_batch(app, fn_saveconfig, bool_=True):


def run_batch(app=None):
run_hide = make_run_hide(app._run_hide) # button to hide the run console
display(run_hide)
# TODO: add remove run button
sel = {c.key: c.in_batch for c in app.config.configs}
if True not in sel.values():
print("no runs selected")
else:
print("run the following:")
[print(k) for k, v in sel.items() if v is True]
[v.run() for v in app.run_actions if v.config.in_batch]
[
v.run(display_hide_btn=False) for v in app.run_actions if v.config.in_batch
] # TODO add "hide_button" arg


def batch_get_status(app=None):
Expand Down Expand Up @@ -862,7 +868,7 @@ def _update_status(cls, v, values):

if __name__ == "__main__":
# TODO: update example to this: https://examples.pyviz.org/attractors/attractors.html
# TODO: configure so that the value of the RunApp is the config
# TODO: configure so that the value of the RunApp is the config?

from ipyrun.constants import load_test_constants
from ipyautoui.custom.workingdir import WorkingDirsUi
Expand All @@ -885,13 +891,6 @@ def fn_loaddir_handler(value, app=None):
app.actions.load(fdir_root=fdir_root)

class LineGraphBatchActions(BatchShellActions):
@validator("config", always=True)
def _config(cls, v, values):
"""bundles RunApp up as a single argument callable"""
if type(v) == dict:
v = LineGraphConfigBatch(**v)
return v

@validator("runlog_show", always=True)
def _runlog_show(cls, v, values):
return None
Expand Down
23 changes: 12 additions & 11 deletions src/ipyrun/runui.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def actions(self):
def actions(self, value):
value.app = self
self._actions = value
self._actions.check
self._actions.check_validators()
# ^ REF: https://github.com/samuelcolvin/pydantic/issues/1864#issuecomment-679044432

def _status_indicator(self, onclick):
Expand Down Expand Up @@ -413,7 +413,7 @@ def _init_RunUi(self, name, run_actions):
# self.out_outputs.observe(self._update_out, names='outputs')
# self.out_runlog.observe(self._update_out, names='outputs')

# def _update_out(self, on_change): # TODO: this isnt working properly
# def _update_out(self, on_change):
# out = [self.out_inputs, self.out_outputs, self.out_runlog]
# self.out_box_main.children = [o for o in out if len(o.outputs) > 0]
# TODO: make something like this ^ work.
Expand All @@ -432,7 +432,7 @@ def actions(self, value):
# ^ REF: https://github.com/samuelcolvin/pydantic/issues/1864#issuecomment-679044432
self.update_form()

def update_form(self): # TODO 🐛: form updates if "update_config_at_runtime" == True
def update_form(self):
"""update the form if the actions have changed"""
# self._layout_out()
self.layout_out.children = [
Expand Down Expand Up @@ -600,6 +600,7 @@ def config(self):

@config.setter
def config(self, value):
value.check_validators()
actions = self.cls_actions(config=value, app=self)
self.actions = actions
self.actions.save_config()
Expand Down Expand Up @@ -635,7 +636,7 @@ def _init_BatchActionsUi(self, actions, di_button_styles=DEFAULT_BUTTON_STYLES):
self._init_RunActionsUi(actions, di_button_styles=DEFAULT_BUTTON_STYLES)
self._update_controls()

def _update_objects(self): # TODO: define updated batch objects better...
def _update_objects(self):
self.add = widgets.ToggleButton(**ADD)
self.remove = widgets.ToggleButton(**REMOVE)
self.wizard = widgets.ToggleButton(**WIZARD)
Expand Down Expand Up @@ -781,12 +782,11 @@ def actions(self):

@actions.setter
def actions(self, value):
cl = type(value)
di = value.dict()
di["app"] = self
self._actions = cl(**di)
value.app = self
self._actions = value
self._actions.check_validators()
# ^ REF: https://github.com/samuelcolvin/pydantic/issues/1864#issuecomment-679044432
self.update_form()
# TODO: update this like the other ones are (pydantic update?)

def _init_BatchUi(
self,
Expand Down Expand Up @@ -991,13 +991,14 @@ def config(self):

@config.setter
def config(self, value):
# value.check_validators() # TODO: consider removing the run config data from the batch config
actions = self.cls_actions(config=value, app=self)
self.actions = actions
self.actions.save_config()
try:
self.runs.items = {
c.key: self.make_run(c) for c in self.config.configs
} # TODO: this code isn't generic!
} # TODO: remove config dependent code?
except:
print("error building runs fron config")
print(f"self.config == {str(self.config)}")
Expand Down Expand Up @@ -1040,7 +1041,7 @@ def configs_remove(self, key): # TODO: remove config dependent code?

config_batch = ConfigBatch(
fdir_root=".", path_run="script.py", configs=[config.dict()], title="# title"
) # TODO: sort out "title" (and how its named in the back)
)
batch_app = BatchApp(None)
display(batch_app)

Expand Down

0 comments on commit 59fa383

Please sign in to comment.