コード例 #1
0
ファイル: activate.py プロジェクト: pbalm/conda
def help(command):
    # sys.argv[1] will be ..checkenv in activate if an environment is already
    # activated
    # get grandparent process name to see which shell we're using
    win_process = find_parent_shell()
    if command in ('..activate', '..checkenv'):
        if win_process in ["cmd.exe", "powershell.exe"]:
            sys.exit("""Usage: activate ENV

Adds the 'Scripts' and 'Library\\bin' directory of the environment ENV to the front of PATH.
ENV may either refer to just the name of the environment, or the full
prefix path.""")

        else:
            sys.exit("""Usage: source activate ENV

Adds the 'bin' directory of the environment ENV to the front of PATH.
ENV may either refer to just the name of the environment, or the full
prefix path.""")
    elif command == '..deactivate':
        if win_process in ["cmd.exe", "powershell.exe"]:
            sys.exit("""Usage: deactivate

Removes the environment prefix, 'Scripts' and 'Library\\bin' directory
of the environment ENV from the front of PATH.""")
        else:
            sys.exit("""Usage: source deactivate

Removes the 'bin' directory of the environment activated with 'source
activate' from PATH. """)
    else:
        sys.exit("No help available for command %s" % sys.argv[1])
コード例 #2
0
ファイル: install.py プロジェクト: megies/conda
def print_activate(arg):
    from conda.utils import find_parent_shell
    print("#")
    print("# To activate this environment, use:")
    if find_parent_shell() in ["powershell.exe", "cmd.exe"]:
        print("# > activate %s" % arg)
        print("#")
        print("# To deactivate this environment, use:")
        print("# > deactivate")
    else:
        print("# $ source activate %s" % arg)
        print("#")
        print("# To deactivate this environment, use:")
        print("# $ source deactivate")
    print("#")
コード例 #3
0
def print_activate(arg):
    from conda.utils import find_parent_shell
    print("#")
    print("# To activate this environment, use:")
    if find_parent_shell() in ["powershell.exe", "cmd.exe"]:
        print("# > activate %s" % arg)
        print("#")
        print("# To deactivate this environment, use:")
        print("# > deactivate")
    else:
        print("# $ source activate %s" % arg)
        print("#")
        print("# To deactivate this environment, use:")
        print("# $ source deactivate")
    print("#")
コード例 #4
0
ファイル: activate.py プロジェクト: vmuriart/conda
def main():
    import conda.config
    import conda.install
    if '-h' in sys.argv or '--help' in sys.argv:
        help()

    path = os.getenv("PATH")
    # This one is because we force Library/bin to be on PATH on windows.  Strip it off here.
    if on_win:
        path = path.replace(
            join(sys.prefix, "Library", "bin") + os.pathsep, "", 1)

    parent_shell = find_parent_shell(path=True)
    if sys.argv[1] == '..activate':
        if len(sys.argv) == 2 or sys.argv[2].lower() == "root":
            binpath = binpath_from_arg("root")
            rootpath = None
        elif len(sys.argv) == 3:
            base_path = sys.argv[2]
            binpath = binpath_from_arg(base_path)
            rootpath = os.pathsep.join(binpath_from_arg("root"))
        else:
            sys.exit("Error: did not expect more than one argument")
        sys.stderr.write("prepending %s to PATH\n" % pathlist_to_str(binpath))
        path = os.pathsep.join([os.pathsep.join(binpath), path])

        if any(
            [shell in parent_shell
             for shell in ["cmd.exe", "powershell.exe"]]):
            path = translate_stream(path, unix_path_to_win)
            # Clear the root path if it is present
            if rootpath:
                path = path.replace(
                    translate_stream(rootpath, unix_path_to_win), "")
        elif 'cygwin' in parent_shell:
            # this should be harmless to unix paths, but converts win paths to
            # unix for bash on win (msys, cygwin)
            path = translate_stream(path, win_path_to_cygwin)
            # Clear the root path if it is present
            if rootpath:
                path = path.replace(
                    translate_stream(rootpath, win_path_to_cygwin), "")
        else:
            if sys.platform == 'win32':
                path = translate_stream(path, win_path_to_unix)
                if rootpath:
                    rootpath = translate_stream(rootpath, win_path_to_unix)
            # Clear the root path if it is present
            if rootpath:
                path = path.replace(rootpath, "")

    elif sys.argv[1] == '..deactivate':
        path = os.getenv("CONDA_PATH_BACKUP", "")
        sys.stderr.write("path:")
        sys.stderr.write(path)
        if path:
            sys.stderr.write("Restoring PATH to deactivated state\n")
        else:
            path = os.getenv(
                "PATH"
            )  # effectively a no-op; just set PATH to what it already is

    elif sys.argv[1] == '..checkenv':
        if len(sys.argv) < 3:
            sys.exit("Error: no environment provided.")
        if len(sys.argv) > 3:
            sys.exit("Error: did not expect more than one argument.")
        if sys.argv[2] == 'root':
            # no need to check root env and try to install a symlink there
            sys.exit(0)

        # this should throw an error and exit if the env or path can't be found.
        binpath = binpath_from_arg(sys.argv[2])

        # Make sure an env always has the conda symlink
        try:
            conda.install.symlink_conda(binpath[0], conda.config.root_dir,
                                        find_parent_shell())
        except (IOError, OSError) as e:
            if e.errno == errno.EPERM or e.errno == errno.EACCES:
                msg = (
                    "Cannot activate environment {0}, not have write access to conda symlink"
                    .format(sys.argv[2]))
                sys.exit(msg)
            raise
        sys.exit(0)

    elif sys.argv[1] == '..setps1':
        # path is a bit of a misnomer here.  It is the prompt setting.  However, it is returned
        #    below by printing.  That is why it is named "path"
        path = sys.argv[3]
        if not path:
            if on_win:
                path = os.getenv("PROMPT", "$P$G")
            else:
                # zsh uses prompt.  If it exists, prefer it.
                path = os.getenv("PROMPT")
                # fall back to bash default
                if not path:
                    path = os.getenv("PS1")
        # strip off previous prefix, if any:
        path = re.sub(".*\(\(.*\)\)\ ", "", path, count=1)
        env_path = sys.argv[2]
        if conda.config.changeps1 and env_path:
            path = "(({})) {}".format(os.path.split(env_path)[-1], path)

    else:
        # This means there is a bug in main.py
        raise ValueError("unexpected command")

    # This print is actually what sets the PATH or PROMPT variable.  The shell
    # script gets this value, and finishes the job.
    print(path)
コード例 #5
0
ファイル: activate.py プロジェクト: pbalm/conda
def main():
    from conda.config import root_env_name, root_dir, changeps1
    import conda.install
    if '-h' in sys.argv or '--help' in sys.argv:
        help(sys.argv[1])

    path = None
    shell = find_parent_shell(path=False)
    shelldict = shells[shell]
    if sys.argv[1] == '..activate':
        path = get_path(shelldict)
        if len(sys.argv) == 2 or sys.argv[2].lower() == root_env_name.lower():
            binpath = binpath_from_arg(root_env_name, shelldict=shelldict)
            rootpath = None
        elif len(sys.argv) == 3:
            binpath = binpath_from_arg(sys.argv[2], shelldict=shelldict)
            rootpath = binpath_from_arg(root_env_name, shelldict=shelldict)
        else:
            sys.exit("Error: did not expect more than one argument")
        pathlist_str = pathlist_to_str(binpath)
        sys.stderr.write("prepending %s to PATH\n" % shelldict['path_to'](pathlist_str))

        # Clear the root path if it is present
        if rootpath:
            path = path.replace(shelldict['pathsep'].join(rootpath), "")

        # prepend our new entries onto the existing path and make sure that the separator is native
        path = shelldict['pathsep'].join(binpath + [path, ])

    # deactivation is handled completely in shell scripts - it restores backups of env variables.
    #    It is done in shell scripts because they handle state much better than we can here.

    elif sys.argv[1] == '..checkenv':
        if len(sys.argv) < 3:
            sys.argv.append(root_env_name)
        if len(sys.argv) > 3:
            sys.exit("Error: did not expect more than one argument.")
        if sys.argv[2].lower() == root_env_name.lower():
            # no need to check root env and try to install a symlink there
            sys.exit(0)

        # this should throw an error and exit if the env or path can't be found.
        try:
            prefix = prefix_from_arg(sys.argv[2], shelldict=shelldict)
        except ValueError as e:
            sys.exit(getattr(e, 'message', e))

        # Make sure an env always has the conda symlink
        try:
            conda.install.symlink_conda(prefix, root_dir, shell)
        except (IOError, OSError) as e:
            if e.errno == errno.EPERM or e.errno == errno.EACCES:
                msg = ("Cannot activate environment {0}, not have write access to conda symlink"
                       .format(sys.argv[2]))
                sys.exit(msg)
            raise
        sys.exit(0)

    elif sys.argv[1] == '..setps1':
        # path is a bit of a misnomer here.  It is the prompt setting.  However, it is returned
        #    below by printing.  That is why it is named "path"
        # DO NOT use os.getenv for this.  One Windows especially, it shows cmd.exe settings
        #    for bash shells.  This method uses the shell directly.
        path = os.getenv(shelldict['promptvar'], '')
        # failsafes
        if not path:
            if shelldict['exe'] == 'cmd.exe':
                path = '$P$G'
        # strip off previous prefix, if any:
        path = re.sub(".*\(\(.*\)\)\ ", "", path, count=1)
        env_path = sys.argv[2]
        if changeps1 and env_path:
            path = "(({0})) {1}".format(os.path.split(env_path)[-1], path)

    else:
        # This means there is a bug in main.py
        raise ValueError("unexpected command")

    # This print is actually what sets the PATH or PROMPT variable.  The shell
    # script gets this value, and finishes the job.
    print(path)
コード例 #6
0
def main():
    from conda.config import root_env_name, root_dir, changeps1
    import conda.install
    if '-h' in sys.argv or '--help' in sys.argv:
        help(sys.argv[1])

    path = None
    shell = find_parent_shell(path=False)
    shelldict = shells[shell]
    if sys.argv[1] == '..activate':
        path = get_path(shelldict)
        if len(sys.argv) == 2 or sys.argv[2].lower() == root_env_name.lower():
            binpath = binpath_from_arg(root_env_name, shelldict=shelldict)
            rootpath = None
        elif len(sys.argv) == 3:
            binpath = binpath_from_arg(sys.argv[2], shelldict=shelldict)
            rootpath = binpath_from_arg(root_env_name, shelldict=shelldict)
        else:
            sys.exit("Error: did not expect more than one argument")
        pathlist_str = pathlist_to_str(binpath)
        sys.stderr.write("prepending %s to PATH\n" %
                         shelldict['path_to'](pathlist_str))

        # Clear the root path if it is present
        if rootpath:
            path = path.replace(shelldict['pathsep'].join(rootpath), "")

        # prepend our new entries onto the existing path and make sure that the separator is native
        path = shelldict['pathsep'].join(binpath + [
            path,
        ])

    # deactivation is handled completely in shell scripts - it restores backups of env variables.
    #    It is done in shell scripts because they handle state much better than we can here.

    elif sys.argv[1] == '..checkenv':
        if len(sys.argv) < 3:
            sys.argv.append(root_env_name)
        if len(sys.argv) > 3:
            sys.exit("Error: did not expect more than one argument.")
        if sys.argv[2].lower() == root_env_name.lower():
            # no need to check root env and try to install a symlink there
            sys.exit(0)

        # this should throw an error and exit if the env or path can't be found.
        try:
            binpath = binpath_from_arg(sys.argv[2], shelldict=shelldict)
        except ValueError as e:
            sys.exit(getattr(e, 'message', e))

        # Make sure an env always has the conda symlink
        try:
            conda.install.symlink_conda(shelldict['path_from'](binpath[0]),
                                        root_dir, shell)
        except (IOError, OSError) as e:
            if e.errno == errno.EPERM or e.errno == errno.EACCES:
                msg = (
                    "Cannot activate environment {0}, not have write access to conda symlink"
                    .format(sys.argv[2]))
                sys.exit(msg)
            raise
        sys.exit(0)

    elif sys.argv[1] == '..setps1':
        # path is a bit of a misnomer here.  It is the prompt setting.  However, it is returned
        #    below by printing.  That is why it is named "path"
        # DO NOT use os.getenv for this.  One Windows especially, it shows cmd.exe settings
        #    for bash shells.  This method uses the shell directly.
        path, _ = run_in(shelldict['printps1'],
                         shelldict,
                         env=os.environ.copy())
        # failsafes
        if not path:
            if shelldict['exe'] == 'cmd.exe':
                path = '$P$G'
        # strip off previous prefix, if any:
        path = re.sub(".*\(\(.*\)\)\ ", "", path, count=1)
        env_path = sys.argv[2]
        if changeps1 and env_path:
            path = "(({})) {}".format(os.path.split(env_path)[-1], path)

    else:
        # This means there is a bug in main.py
        raise ValueError("unexpected command")

    # This print is actually what sets the PATH or PROMPT variable.  The shell
    # script gets this value, and finishes the job.
    print(path)
コード例 #7
0
ファイル: activate.py プロジェクト: ZachDZimmerman/conda
def main():
    import conda.config
    import conda.install
    if '-h' in sys.argv or '--help' in sys.argv:
        help()

    path = os.getenv("PATH")
    # This one is because we force Library/bin to be on PATH on windows.  Strip it off here.
    if on_win:
        path = path.replace(join(sys.prefix, "Library", "bin")+os.pathsep, "", 1)

    parent_shell = find_parent_shell(path=True)
    if sys.argv[1] == '..activate':
        if len(sys.argv) == 2 or sys.argv[2].lower() == "root":
            binpath = binpath_from_arg("root")
            rootpath = None
        elif len(sys.argv) == 3:
            base_path = sys.argv[2]
            binpath = binpath_from_arg(base_path)
            rootpath = os.pathsep.join(binpath_from_arg("root"))
        else:
            sys.exit("Error: did not expect more than one argument")
        sys.stderr.write("prepending %s to PATH\n" % pathlist_to_str(binpath))
        path = os.pathsep.join([os.pathsep.join(binpath), path])

        if any([shell in parent_shell for shell in ["cmd.exe", "powershell.exe"]]):
            path = translate_stream(path, unix_path_to_win)
            # Clear the root path if it is present
            if rootpath:
                path = path.replace(translate_stream(rootpath, unix_path_to_win), "")
        elif 'cygwin' in parent_shell:
            # this should be harmless to unix paths, but converts win paths to unix for bash on win (msys, cygwin)
            path = translate_stream(path, win_path_to_cygwin)
            # Clear the root path if it is present
            if rootpath:
                path = path.replace(translate_stream(rootpath, win_path_to_cygwin), "")
        else:
            if sys.platform == 'win32':
                path = translate_stream(path, win_path_to_unix)
                if rootpath:
                    rootpath = translate_stream(rootpath, win_path_to_unix)
            # Clear the root path if it is present
            if rootpath:
                path = path.replace(rootpath, "")


    elif sys.argv[1] == '..deactivate':
        path = os.getenv("CONDA_PATH_BACKUP", "")
        sys.stderr.write("path:")
        sys.stderr.write(path)
        if path:
            sys.stderr.write("Restoring PATH to deactivated state\n")
        else:
            path = os.getenv("PATH")  # effectively a no-op; just set PATH to what it already is

    elif sys.argv[1] == '..checkenv':
        if len(sys.argv) < 3:
            sys.exit("Error: no environment provided.")
        if len(sys.argv) > 3:
            sys.exit("Error: did not expect more than one argument.")
        if sys.argv[2] == 'root':
            # no need to check root env and try to install a symlink there
            sys.exit(0)
        binpath = binpath_from_arg(sys.argv[2])  # this should throw an error and exit if the env or path can't be found.
        # Make sure an env always has the conda symlink
        try:
            conda.install.symlink_conda(binpath[0], conda.config.root_dir, find_parent_shell())
        except (IOError, OSError) as e:
            if e.errno == errno.EPERM or e.errno == errno.EACCES:
                sys.exit("Cannot activate environment {}, do not have write access to write conda symlink".format(sys.argv[2]))
            raise
        sys.exit(0)

    elif sys.argv[1] == '..setps1':
        # path is a bit of a misnomer here.  It is the prompt setting.  However, it is returned
        #    below by printing.  That is why it is named "path"
        path = sys.argv[3]
        if not path:
            if on_win:
                path = os.getenv("PROMPT", "$P$G")
            else:
                # zsh uses prompt.  If it exists, prefer it.
                path = os.getenv("PROMPT")
                # fall back to bash default
                if not path:
                    path = os.getenv("PS1")
        # strip off previous prefix, if any:
        path = re.sub(".*\(\(.*\)\)\ ", "", path, count=1)
        env_path = sys.argv[2]
        if conda.config.changeps1 and env_path:
            path = "(({})) {}".format(os.path.split(env_path)[-1], path)

    else:
        # This means there is a bug in main.py
        raise ValueError("unexpected command")

    # This print is actually what sets the PATH or PROMPT variable.  The shell script gets this value, and finishes the job.
    print(path)
コード例 #8
0
ファイル: instructions.py プロジェクト: wesm/conda
def SYMLINK_CONDA_CMD(state, arg):
    install.symlink_conda(state['prefix'], arg, find_parent_shell())
コード例 #9
0
ファイル: instructions.py プロジェクト: AnddyWang/conda
def SYMLINK_CONDA_CMD(state, arg):
    install.symlink_conda(state['prefix'], arg, find_parent_shell())