def test_install_conda_sh(self):
        with tempdir() as conda_prefix:
            target_path = join(conda_prefix, 'etc', 'profile.d', 'conda.sh')
            context.dev = False
            result = install_conda_sh(target_path, conda_prefix)
            assert result == Result.MODIFIED

            with open(target_path) as fh:
                created_file_contents = fh.read()

            from conda.activate import PosixActivator
            activator = PosixActivator()

            line0, line1, line2, line3, _, remainder = created_file_contents.split('\n', 5)
            assert line0 == "export CONDA_EXE='%s'" % activator.path_conversion(context.conda_exe)
            assert line1 == "export _CE_M=''"
            assert line2 == "export _CE_CONDA=''"
            assert line3.startswith("export CONDA_PYTHON_EXE=")

            with open(join(CONDA_PACKAGE_ROOT, 'shell', 'etc', 'profile.d', 'conda.sh')) as fh:
                original_contents = fh.read()
            assert remainder == original_contents

            result = install_conda_sh(target_path, conda_prefix)
            assert result == Result.NO_CHANGE
Ejemplo n.º 2
0
    def test_install_conda_sh(self):
        with tempdir() as conda_prefix:
            target_path = join(conda_prefix, 'etc', 'profile.d', 'conda.sh')
            context.dev = False
            result = install_conda_sh(target_path, conda_prefix)
            assert result == Result.MODIFIED

            with open(target_path) as fh:
                created_file_contents = fh.read()

            from conda.activate import PosixActivator
            activator = PosixActivator()

            line0, line1, line2, line3, _, remainder = created_file_contents.split('\n', 5)
            assert line0 == "export CONDA_EXE='%s'" % activator.path_conversion(context.conda_exe)
            assert line1 == "export _CE_M=''"
            assert line2 == "export _CE_CONDA=''"
            assert line3.startswith("export CONDA_PYTHON_EXE=")

            with open(join(CONDA_PACKAGE_ROOT, 'shell', 'etc', 'profile.d', 'conda.sh')) as fh:
                original_contents = fh.read()
            assert remainder == original_contents

            result = install_conda_sh(target_path, conda_prefix)
            assert result == Result.NO_CHANGE
Ejemplo n.º 3
0
def get_conda_prefixes_on_PATH():
    '''
    :return: A tuple of:
               A list of conda prefixes found on PATH in the order in which they appear.
               A list of the suffixes that determine a conda prefix on this platform.
    '''

    if on_win:
        condapathlist = list(CmdExeActivator()._get_path_dirs(''))
    else:
        condapathlist = list(PosixActivator()._get_path_dirs(''))
    pathlist = environ.get('PATH', '').split(pathsep)
    pathlist = pathlist + pathlist
    conda_prefixes = []
    for pei, _ in enumerate(pathlist[:-len(condapathlist)]):
        all_good = True
        for cei, ce in enumerate(condapathlist):
            if not pathlist[pei + cei].endswith(ce):
                all_good = False
                break
        if not all_good:
            continue
        conda_prefixes.append(pathlist[pei][-len(condapathlist[0]):])
    return conda_prefixes, condapathlist