Пример #1
0
def _format_vars(shell):
    shelldict = shells[shell]

    # base_path, _ = run_in(shelldict['printpath'], shell)
    # # windows forces Library/bin onto PATH when starting up.  Strip it for the purposes of this test.
    # if on_win:
    #     base_path = strip_leading_library_bin(base_path, shelldict)

    raw_ps, _ = run_in(shelldict["printps1"], shell)

    old_path_parts = os.environ['PATH'].split(os.pathsep)

    if on_win:
        new_path_parts = tuple(
            _get_prefix_paths(
                join(dirname(CONDA_PACKAGE_ROOT), 'conda', 'shell'))) + tuple(
                    _get_prefix_paths(sys.prefix))
    else:
        new_path_parts = (
            join(dirname(CONDA_PACKAGE_ROOT), 'conda', 'shell', 'bin'),
            dirname(sys.executable),
        )

    if shell == 'bash.exe':
        from conda.activate import native_path_to_unix
        base_paths = tuple(p for p in chain.from_iterable((new_path_parts,
                                                           old_path_parts)))
        base_path = ':'.join(native_path_to_unix(base_paths))

    else:
        base_path = shelldict['pathsep'].join(
            shelldict['path_to'](p)
            for p in chain.from_iterable((new_path_parts, old_path_parts)))
    if shell == 'cmd.exe':
        _command_setup = """\
{set} "PYTHONPATH={PYTHONPATH}"
{set} CONDARC=
{set} CONDA_PATH_BACKUP=
{set} "PATH={new_path}"
"""
    else:
        _command_setup = """\
{set} PYTHONPATH="{PYTHONPATH}"
{set} CONDARC=
{set} CONDA_PATH_BACKUP=
{set} PATH="{new_path}"
"""
        if 'bash' in shell:
            _command_setup += "set -u\n"

    command_setup = _command_setup.format(
        here=dirname(__file__),
        PYTHONPATH=shelldict['path_to'](PYTHONPATH),
        set=shelldict["set_var"],
        new_path=base_path)
    if shelldict["shell_suffix"] == '.bat':
        command_setup = "@echo off\n" + command_setup

    return {
        'echo': shelldict['echo'],
        'nul': shelldict['nul'],
        'printpath': shelldict['printpath'],
        'printdefaultenv': shelldict['printdefaultenv'],
        'printps1': shelldict['printps1'],
        'raw_ps': raw_ps,
        'set_var': shelldict['set_var'],
        'source': shelldict['source_setup'],
        'binpath': shelldict['binpath'],
        'shell_suffix': shelldict['shell_suffix'],
        'syspath': join(dirname(CONDA_PACKAGE_ROOT), 'conda', 'shell'),
        'command_setup': command_setup,
        'base_path': base_path,
    }
Пример #2
0
def _format_vars(shell):
    shelldict = shells[shell]

    # base_path, _ = run_in(shelldict['printpath'], shell)
    # # windows forces Library/bin onto PATH when starting up.  Strip it for the purposes of this test.
    # if on_win:
    #     base_path = strip_leading_library_bin(base_path, shelldict)

    raw_ps, _ = run_in(shelldict["printps1"], shell)

    old_path_parts = os.environ['PATH'].split(os.pathsep)

    if on_win:
        new_path_parts = tuple(
            _get_prefix_paths(join(dirname(CONDA_PACKAGE_ROOT), 'conda', 'shell'))
        ) + tuple(
            _get_prefix_paths(sys.prefix)
        )
    else:
        new_path_parts = (
            join(dirname(CONDA_PACKAGE_ROOT), 'conda', 'shell', 'bin'),
            dirname(sys.executable),
        )

    if shell == 'bash.exe':
        from conda.activate import native_path_to_unix
        base_paths = tuple(p for p in chain.from_iterable((new_path_parts, old_path_parts)))
        base_path = ':'.join(native_path_to_unix(base_paths))

    else:
        base_path = shelldict['pathsep'].join(shelldict['path_to'](p)
                                              for p in chain.from_iterable((new_path_parts,
                                                                            old_path_parts)))
    if shell == 'cmd.exe':
        _command_setup = """\
{set} "PYTHONPATH={PYTHONPATH}"
{set} CONDARC=
{set} CONDA_PATH_BACKUP=
{set} "PATH={new_path}"
"""
    else:
        _command_setup = """\
{set} PYTHONPATH="{PYTHONPATH}"
{set} CONDARC=
{set} CONDA_PATH_BACKUP=
{set} PATH="{new_path}"
{set} _CONDA_ROOT="{shellpath}"
"""
        if 'bash' in shell:
            _command_setup += "set -u\n"

    command_setup = _command_setup.format(
        here=dirname(__file__),
        PYTHONPATH=shelldict['path_to'](PYTHONPATH),
        set=shelldict["set_var"],
        new_path=base_path,
        shellpath=join(dirname(CONDA_PACKAGE_ROOT), 'conda', 'shell')
    )
    if shelldict["shell_suffix"] == '.bat':
        command_setup = "@echo off\n" + command_setup

    return {
        'echo': shelldict['echo'],
        'nul': shelldict['nul'],
        'printpath': shelldict['printpath'],
        'printdefaultenv': shelldict['printdefaultenv'],
        'printps1': shelldict['printps1'],
        'raw_ps': raw_ps,
        'set_var': shelldict['set_var'],
        'source': shelldict['source_setup'],
        'binpath': shelldict['binpath'],
        'shell_suffix': shelldict['shell_suffix'],
        'syspath': join(dirname(CONDA_PACKAGE_ROOT), 'conda', 'shell'),
        'command_setup': command_setup,
        'base_path': base_path,
}