Beispiel #1
0
def _print_staged_dir_instructions(run):
    cmd_args = run.get("cmd") or []
    cmd = " ".join([util.shlex_quote(arg) for arg in cmd_args])
    cli.out("{op} staged in '{dir}'\n"
            "To start the operation, use "
            "\"(cd '{dir}' && source .guild/ENV && {cmd})\"".format(
                op=run_util.format_operation(run), dir=run.dir, cmd=cmd))
Beispiel #2
0
def _quote_arg(arg):
    """Returns arg, quoted as needed.

    Special handling for args starting and ending with double-quotes -
    these are assumed to be quoted and are returned unmodified.
    """
    if isinstance(arg, _noquote):
        return arg.val
    return util.shlex_quote(arg)
Beispiel #3
0
def join_splittable_flag_vals(vals, split_spec=None):
    encoded_vals = [encode_flag_val(val) for val in vals]
    if split_spec in (None, True, "shlex"):
        return " ".join([util.shlex_quote(x) for x in encoded_vals])
    elif isinstance(split_spec, six.string_types):
        return split_spec.join(encoded_vals)
    else:
        raise ValueError("split_spec must be None, True, or a string: %r" %
                         split_spec)
Beispiel #4
0
def _init_flags(run, args):
    arg_flags, other_args = op_util.args_to_flags(args)
    if other_args:
        log.warning(
            "unexpected args: %s",
            " ".join([util.shlex_quote(arg) for arg in other_args]),
        )
    flags = run.get("flags", {})
    flags.update(arg_flags)
    return flags
Beispiel #5
0
def flag_assign(name,
                val,
                quote=False,
                shell_safe=False,
                truncate_floats=False):
    formatted = run_util.format_flag_val(val, truncate_floats)
    if quote or shell_safe:
        formatted = util.shlex_quote(formatted)
        if not shell_safe:
            formatted = _strip_shlex_single_quotes(formatted)
    return "%s=%s" % (name, formatted)
Beispiel #6
0
 def _init_guild_cmd(self, name, args, env):
     cmd_lines = ["set -e"]
     cmd_lines.extend(self._env_activate_cmd_lines())
     cmd_lines.extend(self._set_columns())
     assert self.guild_home is not None
     cmd_lines.append("export GUILD_HOME=%s" % self.guild_home)
     if env:
         cmd_lines.extend(self._cmd_env(env))
     quoted_args = [util.shlex_quote(arg) for arg in args]
     cmd_lines.append("guild %s %s" % (name, " ".join(quoted_args)))
     return "; ".join(cmd_lines)
Beispiel #7
0
def main():
    _init_logging()
    args, rest_args = _parse_args()
    run = _init_run(args)
    _check_env()
    flags, other_args = op_util.args_to_flags(rest_args)
    if other_args:
        log.warning(
            "unexpected args: %s",
            " ".join([util.shlex_quote(arg) for arg in other_args]),
        )
    run_notebook = _init_run_notebook(args.notebook, flags, run)
    if args.no_exec or os.getenv("NB_NO_EXEC") == "1":
        log.info("NB_NO_EXEC specified, skipping execute")
        return
    _nbexec(run_notebook)
    _print_output(run_notebook)
    _save_images(run_notebook)
    _nbconvert_html(run_notebook)
def _encode_base_args(args):
    return " ".join([util.shlex_quote(arg) for arg in args])
Beispiel #9
0
def _preview_cmd(op):
    return [util.shlex_quote(arg) for arg in op.cmd_args]
Beispiel #10
0
def _encode_splittable_list(l):
    return " ".join([util.shlex_quote(yaml_util.encode_yaml(x)) for x in l])
Beispiel #11
0
# Copyright 2017-2020 TensorHub, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""No-op module that can be used for operation main.

This is useful during development or to simply print a message.
"""

from __future__ import print_function

import sys

if __name__ == "__main__":
    to_print = sys.argv[1:]
    if to_print:
        from guild import util

        print(*[util.shlex_quote(x) for x in to_print])
Beispiel #12
0
def _print_op_cmd_args(args):
    cli.out(" ".join([util.shlex_quote(arg) for arg in args]))