Exemplo n.º 1
0
def welcome(opts):
    sys.stdout.write(
        apply_styles(
            opts, r'''{success}                   _
{success}                  | |
{success} _ __  _   _   ___| |__
{success}| '_ \| | | | / __| '_ \
{success}| |_) | |_| |_\__ \ | | |
{success}| .__/ \__, (_)___/_| |_|
{success}| |     __/ |
{success}|_|    |___/

{success}py.sh{plain} is now installed!

A standalone Python interpreter has been installed into {code}{{work_dir}}{plain}.
{success}Recommended:{plain} Add {code}{{work_dir}}{plain} to your {code}.gitignore{plain} file.

Use {code}./{{script_name}}{plain} to manage your environment.
{success}Hint:{plain} You can learn a lot from {code}./{{script_name}} --help{plain}
and {code}./{{script_name}} <command name> --help{plain}.

''').format(
                work_dir=os.path.relpath(opts.work_path, opts.root_path),
                script_name=opts.script_name,
            ))
Exemplo n.º 2
0
def capture_errors(opts):
    try:
        yield
    except TaskWarning as ex:
        sys.stdout.write(apply_styles(opts, "{warn}WARNING!{plain}\n"))
        sys.stdout.write("* {}\n".format(ex.args[0]))
    except KeyboardInterrupt:
        sys.stdout.write(apply_styles(opts, "{warn}ABORTED!{plain}\n"))
        sys.exit(1)
    except Exception as ex:
        sys.stdout.write(apply_styles(opts, "{error}ERROR!{plain}\n"))
        sys.stdout.write("{}\n".format(ex.args[0] if isinstance(ex, TaskError) else "Unexpected error."))
        if opts.traceback:
            traceback.print_exc(file=sys.stdout)
        sys.exit(1)
    finally:
        sys.stdout.flush()
Exemplo n.º 3
0
def capture_errors(opts):
    try:
        yield
    except TaskWarning as ex:
        sys.stdout.write(apply_styles(opts, "{warn}WARNING!{plain}\n"))
        sys.stdout.write("* {}\n".format(ex.args[0]))
    except KeyboardInterrupt:
        sys.stdout.write(apply_styles(opts, "{warn}ABORTED!{plain}\n"))
        sys.exit(1)
    except Exception as ex:
        sys.stdout.write(apply_styles(opts, "{error}ERROR!{plain}\n"))
        sys.stdout.write("{}\n".format(
            ex.args[0] if isinstance(ex, TaskError) else "Unexpected error."))
        if opts.traceback:
            traceback.print_exc(file=sys.stdout)
        sys.exit(1)
    finally:
        sys.stdout.flush()
Exemplo n.º 4
0
def activate(opts):
    config = load_config(opts)
    package_name = config.get("name", os.path.basename(opts.root_path))
    with mark_task(opts, "Activating {} environment".format(opts.conda_env)):
        shell_local_exec(
            opts,
            apply_styles(opts, """printf "{success}done!{plain}
Deactivate environment with {code}exit{plain} or {code}[Ctl+D]{plain}.
" && export PS1="(\[{code}\]{{package_name}}\[{plain}\]) \\h:\\W \\u\\$ " && bash"""),
            package_name=package_name,
        )
Exemplo n.º 5
0
def format_shell_local(opts, command, **kwargs):
    return format_shell(
        apply_styles(opts, (
            "if source activate {{conda_env}} &> /dev/null ; then "
            "test -f {{env_file_path}} && source {{env_file_path}} ; "
            "{{{{command}}}} ; "
            "else "
            "printf \"{error}ERROR!{plain}\\nRun ./{{script_name}} install before attempting other commands.\\n\" ; "
            "fi")),
        conda_env=opts.conda_env,
        env_file_path=os.path.join(opts.root_path, opts.env_file),
        script_name=opts.script_name,
    ).format(command=format_shell(command, **kwargs))
Exemplo n.º 6
0
def activate(opts):
    config = load_config(opts)
    package_name = config.get("name", os.path.basename(opts.root_path))
    with mark_task(opts, "Activating {} environment".format(opts.conda_env)):
        shell_local_exec(
            opts,
            apply_styles(
                opts, """printf "{success}done!{plain}
Deactivate environment with {code}exit{plain} or {code}[Ctl+D]{plain}.
" && export PS1="(\[{code}\]{{package_name}}\[{plain}\]) \\h:\\W \\u\\$ " && bash"""
            ),
            package_name=package_name,
        )
Exemplo n.º 7
0
def format_shell_local(opts, command, **kwargs):
    return format_shell(
        apply_styles(opts, (
            "if source activate {{conda_env}} &> /dev/null ; then "
            "test -f {{env_file_path}} && source {{env_file_path}} ; "
            "{{{{command}}}} ; "
            "else "
            "printf \"{error}ERROR!{plain}\\nRun ./{{script_name}} install before attempting other commands.\\n\" ; "
            "fi"
        )),
        conda_env=opts.conda_env,
        env_file_path=os.path.join(opts.root_path, opts.env_file),
        script_name=opts.script_name,
    ).format(command=format_shell(command, **kwargs))
Exemplo n.º 8
0
def welcome(opts):
    sys.stdout.write(apply_styles(opts, r'''{success}                   _
{success}                  | |
{success} _ __  _   _   ___| |__
{success}| '_ \| | | | / __| '_ \
{success}| |_) | |_| |_\__ \ | | |
{success}| .__/ \__, (_)___/_| |_|
{success}| |     __/ |
{success}|_|    |___/

{success}py.sh{plain} is now installed!

A standalone Python interpreter has been installed into {code}{{work_dir}}{plain}.
{success}Recommended:{plain} Add {code}{{work_dir}}{plain} to your {code}.gitignore{plain} file.

Use {code}./{{script_name}}{plain} to manage your environment.
{success}Hint:{plain} You can learn a lot from {code}./{{script_name}} --help{plain}
and {code}./{{script_name}} <command name> --help{plain}.

''').format(
        work_dir=os.path.relpath(opts.work_path, opts.root_path),
        script_name=opts.script_name,
    ))
Exemplo n.º 9
0
def mark_task(opts, description):
    sys.stdout.write("{}... ".format(description))
    sys.stdout.flush()
    with capture_errors(opts):
        yield
        sys.stdout.write(apply_styles(opts, "{success}done!{plain}\n"))
Exemplo n.º 10
0
def mark_task(opts, description):
    sys.stdout.write("{}... ".format(description))
    sys.stdout.flush()
    with capture_errors(opts):
        yield
        sys.stdout.write(apply_styles(opts, "{success}done!{plain}\n"))