コード例 #1
0
ファイル: test_activate.py プロジェクト: njalerikson/conda
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,
}
コード例 #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}"
"""
        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,
    }
コード例 #3
0
ファイル: test_activate.py プロジェクト: dkoppstein/conda

def _envpaths(env_root, env_name="", shell=None):
    """Supply the appropriate platform executable folders.  rstrip on root removes
       trailing slash if env_name is empty (the default)

    Assumes that any prefix used here exists.  Will not work on prefixes that don't.
    """
    sep = shells[shell]['sep']
    return binpath_from_arg(sep.join([env_root, env_name]), shell)


PYTHONPATH = os.path.dirname(os.path.dirname(__file__))

# Make sure the subprocess activate calls this python
syspath = os.pathsep.join(_get_prefix_paths(context.root_prefix))


def make_win_ok(path):
    if on_win:
        return unix_path_to_win(path)
    else:
        return path


def print_ps1(env_dirs, raw_ps, number):
    return u"(%s) %s" % (make_win_ok(env_dirs[number]), raw_ps)


CONDA_ENTRY_POINT = """\
#!{syspath}/python