Ejemplo n.º 1
0
def _default_diff_cmd_():
    if util.get_platform() == "Linux":
        return _find_cmd(["meld", "xxdiff -r", "dirdiff", "colordiff"])
    elif util.get_platform() == "Darwin":
        return _find_cmd(["Kaleidoscope", "meld", "DiffMerge", "FileMerge"])
    else:
        return DEFAULT_DIFF_CMD
Ejemplo n.º 2
0
def _pip_bin_args(env_dir):
    if util.get_platform() == "Windows":
        python_bin = os.path.join(env_dir, "Scripts", "python.exe")
    else:
        python_bin = os.path.join(env_dir, "bin", "python")
    assert os.path.exists(python_bin), python_bin
    return [python_bin, "-m", "pip"]
Ejemplo n.º 3
0
def _maybe_gist_access_token_script(local_repo):
    if util.get_platform() == "Windows":
        return None
    script_path = _gist_access_token_script(local_repo)
    if os.path.exists(script_path):
        return script_path
    _write_gist_access_token_script(script_path)
    return script_path
Ejemplo n.º 4
0
def _workaround_multiprocessing_cycle():
    # See https://github.com/dask/distributed/issues/4168#issuecomment-722049470
    try:
        if util.get_platform() == "Windows":
            import multiprocessing.popen_spawn_win32 as _
        else:
            import multiprocessing.popen_spawn_posix as _
    except ImportError:
        pass
Ejemplo n.º 5
0
def _run_tensorboard(args):
    from guild import tensorboard

    tensorboard.setup_logging()
    with util.TempDir("guild-tensorboard-", keep=_keep_logdir(args)) as tmp:
        logdir = tmp.path
        (log.info if args.keep_logdir else log.debug)("Using logdir %s", logdir)
        tensorboard_options = _tensorboard_options(args)
        monitor = tensorboard.RunsMonitor(
            logdir,
            _list_runs_cb(args),
            interval=args.refresh_interval,
            log_images=not args.skip_images,
            log_hparams=not args.skip_hparams,
            run_name_cb=_run_name_cb(args),
        )
        t0 = time.time()
        cli.out("Preparing runs for TensorBoard")
        monitor.run_once(exit_on_error=True)
        if args.test_logdir:
            cli.out("Initialized log dir %s" % logdir)
            return
        _maybe_log_prepare_time(t0)
        monitor.start()
        try:
            tensorboard.serve_forever(
                logdir=logdir,
                host=(args.host or "0.0.0.0"),
                port=(args.port or util.free_port()),
                reload_interval=args.refresh_interval,
                tensorboard_options=tensorboard_options,
                ready_cb=_open_cb(args),
            )
        except tensorboard.TensorboardError as e:
            cli.error(str(e))
        finally:
            log.debug("Stopping")
            monitor.stop()
            if not args.keep_logdir:
                # Removal of temp logdir occurs when context manager
                # exits.
                log.debug("Removing logdir %s", logdir)
            else:
                print("TensorBoard logs saved in %s" % logdir)
    if util.get_platform() != "Windows":
        cli.out()
Ejemplo n.º 6
0
def _shell_f(shell_cmd):
    try:
        import pty
    except ImportError:
        cli.error("shell is not supported on this platform (%s)" % util.get_platform())

    shell_cmd = shell_cmd or os.getenv("SHELL", "bash")

    def f(path):
        if os.path.isfile(path):
            path = os.path.dirname(path)
        cli.note(
            "Running a new shell in %s\n"
            "To exit the shell, type 'exit' and press Enter." % path
        )
        with util.Chdir(path):
            with _fix_shell_columns():
                pty.spawn([shell_cmd])

    return f
Ejemplo n.º 7
0
 def _kill(self):
     if util.get_platform() == "Windows":
         self._kill_win()
     else:
         self._kill_posix()
Ejemplo n.º 8
0
def _popen(cmd, env, cwd):
    if util.get_platform() == "Windows":
        return _popen_win(cmd, env, cwd)
    else:
        return _popen_posix(cmd, env, cwd)
Ejemplo n.º 9
0
def _run_shell_cmd(cmd):
    if util.get_platform() == "Windows":
        return _run_shell_win_cmd(cmd)
    else:
        return _run_shell_posix_cmd(cmd)
Ejemplo n.º 10
0
def _safe_len_path(p):
    if util.get_platform() == "Windows":
        # See http://bit.ly/windows-long-file-names
        return "\\\\?\\" + p
    return p