示例#1
0
def _backup_init_script(init_script):
    if os.path.exists(init_script):
        backup = _init_script_backup(init_script)
        cli.out(
            "Backing up %s to %s" %
            (util.format_dir(init_script), util.format_dir(backup)),
            err=True,
        )
        shutil.copy(init_script, backup)
示例#2
0
 def _init_prompt_params(self):
     params = []
     params.append(("Location", util.format_dir(self.env_dir)))
     params.append(("Name", self.env_name))
     if self.venv_python:
         params.append(("Python interpreter", self.venv_python))
     else:
         params.append(("Python interpreter", "default"))
     params.append(("Use system site packages",
                    "yes" if self.system_site_packages else "no"))
     if self.guild:
         params.append(("Guild", self.guild))
     else:
         params.append(("Guild", _implicit_guild_version()))
     if self.guild_home:
         params.append(("Guild home", self.guild_home))
     if self.guild_pkg_reqs:
         params.append(("Guild package requirements", self.guild_pkg_reqs))
     if self.user_reqs:
         params.append(("Python requirements", self.user_reqs))
     if self.pre_release:
         params.append(("Use pre-release", "yes"))
     if self.paths:
         params.append(("Additional paths", self.paths))
     if self.isolate_resources:
         params.append(("Resource cache", "local"))
     else:
         params.append(("Resource cache", "shared"))
     return params
示例#3
0
def format_run(run, index=None):
    status = run.status
    operation = format_op_desc(run)
    marked = bool(run.get("marked"))
    started = run.get("started")
    stopped = run.get("stopped")
    return {
        "_run": run,
        "id": run.id,
        "short_id": run.short_id,
        "index": _format_run_index(run, index),
        "short_index": _format_run_index(run),
        "model": run.opref.model_name,
        "op_name": run.opref.op_name,
        "operation": operation,
        "operation_with_marked": _op_with_marked(operation, marked),
        "pkg": run.opref.pkg_name,
        "status": status,
        "status_with_remote": _status_with_remote(status, run.remote),
        "marked": _format_val(marked),
        "label": _format_label(run.get("label") or ""),
        "pid": run.pid or "",
        "started": util.format_timestamp(started),
        "stopped": util.format_timestamp(stopped),
        "duration": util.format_duration(started, stopped),
        "run_dir": util.format_dir(run.path),
        "command": _format_command(run.get("cmd", "")),
        "exit_status": _format_exit_status(run)
    }
示例#4
0
文件: ls_impl.py 项目: yuanbw/guildai
def _run_dir_header(run_dir, args):
    if os.getenv("NO_PATH_HEADER") == "1":
        return os.path.basename(run_dir)
    elif not args.full_path:
        return util.format_dir(run_dir)
    else:
        return run_dir
示例#5
0
 def config(self):
     cwd = util.format_dir(config.cwd())
     return {
         "cwd": cwd,
         "titleLabel": self._title_label(cwd),
         "version": guild.version(),
     }
示例#6
0
def _format_op_dir(op_dir, cwd):
    if op_dir.startswith(cwd):
        return _op_dir_relpath(op_dir, cwd)
    cwd_parent = os.path.dirname(cwd)
    if op_dir.startswith(cwd_parent):
        return _op_dir_peer_path(op_dir, cwd_parent)
    return util.format_dir(op_dir)
示例#7
0
def _header(dir, args):
    if os.getenv("NO_HEADER_PATH") == "1":
        dir = os.path.basename(dir)
    if args.full_path:
        return dir
    else:
        return util.format_dir(dir)
示例#8
0
def format_run(run, index=None):
    status = run.status
    started = run.get("started")
    stopped = run.get("stopped")
    return {
        "_run": run,
        "command": _format_command(run.get("cmd", "")),
        "duration": util.format_duration(started, stopped),
        "exit_status": _format_exit_status(run),
        "from": format_pkg_name(run),
        "id": run.id,
        "index": _format_run_index(run, index),
        "label": run.get("label") or "",
        "marked": format_attr(bool(run.get("marked"))),
        "model": run.opref.model_name,
        "op_name": run.opref.op_name,
        "operation": format_operation(run),
        "pid": run.pid or "",
        "pkg_name": run.opref.pkg_name,
        "run_dir": util.format_dir(run.path),
        "short_id": run.short_id,
        "short_index": _format_run_index(run),
        "sourcecode_digest": run.get("sourcecode_digest", ""),
        "vcs_commit": run.get("vcs_commit", ""),
        "started": util.format_timestamp(started),
        "status": status,
        "status_with_remote": _status_with_remote(status, run.remote),
        "stopped": util.format_timestamp(stopped),
    }
示例#9
0
def _initialized_msg(config):
    cli.out(
        "Guild environment initialized in {}."
        "\n".format(util.format_dir(config.env_dir))
    )
    cli.out("To activate it " "run:\n")
    cli.out("  %s" % _source_cmd(config.env_dir))
    cli.out()
示例#10
0
def _write_completion_script_to_user_config(shell, script):
    path = os.path.join(config.user_config_home(), "%s_completion" % shell)
    cli.out("Writing completion script to %s" % util.format_dir(path),
            err=True)
    util.ensure_dir(os.path.dirname(path))
    with open(path, "w") as f:
        f.write(script)
        f.write("\n")
    return path
示例#11
0
def _run_dir_header(run_dir, args):
    if os.getenv("NO_HEADER_PATH") == "1":
        run_dir = os.path.basename(run_dir)
    if args.sourcecode:
        return os.path.join(run_dir, ".guild/sourcecode")
    elif not args.full_path:
        return util.format_dir(run_dir)
    else:
        return run_dir
示例#12
0
def _check_init_script(path, sentinel):
    if not os.path.exists(path):
        return
    lines = open(path).readlines()
    for i, line in enumerate(lines):
        if sentinel in line:
            cli.out(
                "Guild completion is already installed in %s on line %i:\n  %s"
                % (util.format_dir(path), i + 1, line.rstrip()),
                err=True,
            )
            raise SystemExit(0)
示例#13
0
def _append_to_init_script(init_script, lines):
    cli.out(
        "Updating %s to support Guild command completion" %
        util.format_dir(init_script),
        err=True,
    )
    util.ensure_dir(os.path.dirname(init_script))
    exists = os.path.exists(init_script)
    with open(init_script, "a") as f:
        if exists:
            f.write(os.linesep)
        for line in lines:
            f.write(line)
            f.write(os.linesep)
示例#14
0
 def _init_prompt_params(self):
     params = []
     params.append(("Location", util.format_dir(self.env_dir)))
     params.append(("Name", self.env_name))
     if self.venv_python:
         params.append(("Python interpreter", self.venv_python))
     else:
         params.append(("Python interpreter", "default"))
     if self.guild:
         params.append(("Guild", self.guild))
     else:
         params.append(("Guild", _implicit_guild_version()))
     if self.guild_pkg_reqs:
         params.append(("Guild package requirements", self.guild_pkg_reqs))
     if self.user_reqs:
         params.append(("Python requirements", self.user_reqs))
     if self.paths:
         params.append(("Additional paths", self.paths))
     if self.local_resource_cache:
         params.append(("Resource cache", "local"))
     else:
         params.append(("Resource cache", "shared"))
     return params
示例#15
0
文件: main.py 项目: wangsd01/guildai
@click.version_option(
    version=guild_version(), prog_name="guild", message="%(prog)s %(version)s"
)
@click.option(
    "-C",
    "cwd",
    metavar="PATH",
    help=("Use PATH as current directory for referencing guild " "files (guild.yml)."),
    default=".",
)
@click.option(
    "-H",
    "guild_home",
    metavar="PATH",
    help="Use PATH as Guild home (default is {}).".format(
        util.format_dir(DEFAULT_GUILD_HOME)
    ),
    default=DEFAULT_GUILD_HOME,
    envvar="GUILD_HOME",
)
@click.option(
    "--debug",
    "log_level",
    help="Log more information during command.",
    flag_value=logging.DEBUG,
)
@click_util.use_args
def main(args):
    """Guild AI command line interface."""
    from . import main_impl
示例#16
0
def _default_format_dir(dir, _cwd):
    return util.format_dir(dir)
示例#17
0
def _format_script_pkg_name(opref):
    return util.format_dir(opref.pkg_name)
示例#18
0
def _format_guildfile_pkg_name(opref):
    return util.format_dir(opref.pkg_name)
示例#19
0
def _save_trials(S):
    if not S.batch_op:
        _save_trials_for_non_batch_error()
    path = _save_trials_path(S.args.save_trials)
    cli.out("Saving trials to %s" % util.format_dir(path))
    _run_tmp_batch(S, {"SAVE_TRIALS": path})
示例#20
0
def _print_header(run_dir, args):
    if not args.full_path and not args.no_format:
        if not args.full_path:
            run_dir = util.format_dir(run_dir)
        cli.out("%s:" % run_dir)