[tune] add-note command for Tune CLI (#4321)

Co-Authored-By: andrewztan <andrewztan12@gmail.com>
This commit is contained in:
Andrew Tan
2019-03-11 14:16:44 -07:00
committed by Richard Liaw
parent 08a476932c
commit c435013b27
2 changed files with 39 additions and 0 deletions
+26
View File
@@ -48,6 +48,8 @@ try:
except subprocess.CalledProcessError:
TERM_HEIGHT, TERM_WIDTH = 100, 100
EDITOR = os.getenv('EDITOR', 'vim')
def _check_tabulate():
"""Checks whether tabulate is installed."""
@@ -230,3 +232,27 @@ def list_experiments(project_path,
info_df = info_df.sort_values(by=sort)
print_format_output(info_df)
def add_note(path, filename="note.txt"):
"""Opens a txt file at the given path where user can add and save notes.
Args:
path (str): Directory where note will be saved.
filename (str): Name of note. Defaults to "note.txt"
"""
path = os.path.expanduser(path)
assert os.path.isdir(path), "{} is not a valid directory.".format(path)
filepath = os.path.join(path, filename)
exists = os.path.isfile(filepath)
try:
subprocess.call([EDITOR, filepath])
except Exception as exc:
logger.error("Editing note failed!")
raise exc
if exists:
print("Note updated at:", filepath)
else:
print("Note created at:", filepath)
+13
View File
@@ -29,10 +29,23 @@ def list_experiments(project_path, sort):
commands.list_experiments(project_path, sort)
@cli.command()
@click.argument("path", required=True, type=str)
@click.option(
"--filename",
default="note.txt",
type=str,
help='Specify filename for note.')
def add_note(path, filename):
"""Adds user notes as a text file at the given path."""
commands.add_note(path, filename)
cli.add_command(list_trials, name="ls")
cli.add_command(list_trials, name="list-trials")
cli.add_command(list_experiments, name="lsx")
cli.add_command(list_experiments, name="list-experiments")
cli.add_command(add_note, name="add-note")
def main():