Beispiel #1
0
    def set_variables(self, project, vars_and_values, env_spec_name=None):
        """Set variables' values in anaconda-project-local.yml.

        Returns a ``Status`` instance which evaluates to True on
        success and has an ``errors`` property (with a list of error
        strings) on failure.

        Args:
            project (Project): the project
            vars_and_values (list of tuple): key-value pairs
            env_spec_name (str): name of env spec to use

        Returns:
            ``Status`` instance
        """
        return project_ops.set_variables(project=project, vars_and_values=vars_and_values, env_spec_name=env_spec_name)
Beispiel #2
0
def _interactively_fix_missing_variables(project, result):
    """Return True if we need to re-prepare."""
    if project.problems:
        return False

    if not console_utils.stdin_is_interactive():
        return False

    # We don't ask the user to manually enter CONDA_PREFIX
    # (CondaEnvRequirement) because it's a bizarre/confusing
    # thing to ask.
    can_ask_about = [
        status for status in result.statuses
        if (not status and isinstance(status.requirement, EnvVarRequirement)
            and not isinstance(status.requirement, CondaEnvRequirement))
    ]

    if can_ask_about:
        print("(Use Ctrl+C to quit.)")

    start_over = False
    values = dict()
    for status in can_ask_about:
        reply = console_utils.console_input(
            "Value for " + status.requirement.env_var + ": ",
            encrypted=status.requirement.encrypted)
        if reply is None:
            return False  # EOF
        reply = reply.strip()
        if reply == '':
            start_over = True
            break
        values[status.requirement.env_var] = reply

    if len(values) > 0:
        status = project_ops.set_variables(project, result.env_spec_name,
                                           values.items(), result)
        if status:
            return True
        else:
            console_utils.print_status_errors(status)
            return False
    else:
        return start_over
Beispiel #3
0
    def set_variables(self, project, env_spec_name, vars_and_values, prepare_result=None):
        """Set variables' values in anaconda-project-local.yml.

        Returns a ``Status`` instance which evaluates to True on
        success and has an ``errors`` property (with a list of error
        strings) on failure.

        Args:
            project (Project): the project
            env_spec_name (str): environment spec name or None for all environment specs
            vars_and_values (list of tuple): key-value pairs
            prepare_result (PrepareResult): result of a previous prepare or None

        Returns:
            ``Status`` instance
        """
        return project_ops.set_variables(project=project,
                                         env_spec_name=env_spec_name,
                                         vars_and_values=vars_and_values,
                                         prepare_result=prepare_result)
Beispiel #4
0
def set_variables(project_dir, vars_and_values):
    """Set the given variables to the given values.

    Returns:
        Returns exit code
    """
    fixed_vars = []
    for var in vars_and_values:
        if '=' not in var:
            print("Error: argument '{}' should be in NAME=value format".format(var))
            return 1
        # maxsplit=1 -- no maxsplit keywork in py27
        fixed_vars.append(tuple(var.split('=', 1)))
    project = load_project(project_dir)
    status = project_ops.set_variables(project, fixed_vars)
    if status:
        print(status.status_description)
        return 0
    else:
        console_utils.print_status_errors(status)
        return 1