Example #1
0
    def __init__(self, registry, env_specs=None):
        """Extend superclass to default to CONDA_PREFIX and carry environment information.

        Args:
            registry (PluginRegistry): plugin registry
            env_specs (dict): dict from env name to ``CondaEnvironment``
        """
        super(CondaEnvRequirement, self).__init__(registry=registry, env_var=conda_api.conda_prefix_variable())
        self.env_specs = env_specs
        self._conda = new_conda_manager()
Example #2
0
    def __init__(self, registry, env_specs=None):
        """Extend superclass to default to CONDA_PREFIX and carry environment information.

        Args:
            registry (PluginRegistry): plugin registry
            env_specs (dict): dict from env name to ``CondaEnvironment``
        """
        super(CondaEnvRequirement,
              self).__init__(registry=registry,
                             env_var=conda_api.conda_prefix_variable())
        self.env_specs = env_specs
        self._conda = new_conda_manager()
Example #3
0
    def exec_info_for_environment(self, environ, extra_args=None):
        """Get a ``CommandExecInfo`` ready to be executed.

        Args:
            environ (dict): the environment containing a CONDA_PREFIX, PATH, and PROJECT_DIR
            extra_args (list of str): extra args to append to the command line
        Returns:
            argv as list of strings
        """
        conda_var = conda_api.conda_prefix_variable()
        for name in (conda_var, 'PATH', 'PROJECT_DIR'):
            if name not in environ:
                raise ValueError("To get a runnable command for the app, %s must be set." % (name))

        (args, shell) = self._choose_args_and_shell(environ, extra_args)

        if args is None:
            # command doesn't work on our platform for example
            return None

        # always look in the project directory. This is a little
        # odd because we don't add PROJECT_DIR to PATH for child
        # processes - maybe we should?
        path = os.pathsep.join([environ['PROJECT_DIR'], environ['PATH']])

        # if we're using a shell, then args[0] is a whole command
        # line and not a single program name, and the shell will
        # search the path for us.
        if not shell:
            executable = find_executable(args[0], path)
            # if we didn't find args[0] on the path, we leave it as-is
            # and wait for it to fail when we later try to run it.
            if executable is not None:
                # if the executable is in cwd, for some reason find_executable does not
                # return the full path to it, just a relative path.
                args[0] = os.path.abspath(executable)

        # conda.misc.launch() uses the home directory
        # instead of the project directory as cwd when
        # running an installed package, but for our
        # purposes where we know we have a project dir
        # that's user-interesting, project directory seems
        # more useful. This way apps can for example find
        # sample data files relative to the project
        # directory.
        return CommandExecInfo(cwd=environ['PROJECT_DIR'],
                               args=args,
                               env=environ,
                               shell=shell,
                               notebook=self.notebook,
                               bokeh_app=self.bokeh_app)
Example #4
0
    def check(dirname):
        env_var = conda_api.conda_prefix_variable()

        try:
            _push_fake_env_creator()
            project = Project(dirname)
            environ = minimal_environ()
            # we specify the command name but not the
            # env_spec_name but it should imply the proper env
            # spec name.
            result = prepare_without_interaction(project, environ=environ, command_name='hello')
            expected_path = project.env_specs['foo'].path(project.directory_path)
            assert result.environ[env_var] == expected_path
        finally:
            _pop_fake_env_creator()
Example #5
0
    def check(dirname):
        env_var = conda_api.conda_prefix_variable()

        try:
            _push_fake_env_creator()
            project = Project(dirname)
            environ = minimal_environ()
            # we specify the command name but not the
            # env_spec_name but it should imply the proper env
            # spec name.
            result = prepare_without_interaction(project, environ=environ, command_name='hello')
            expected_path = project.env_specs['foo'].path(project.directory_path)
            assert result.environ[env_var] == expected_path
        finally:
            _pop_fake_env_creator()
Example #6
0
    def exec_info_for_environment(self, environ, extra_args=None):
        """Get a ``CommandExecInfo`` ready to be executed.

        Args:
            environ (dict): the environment containing a CONDA_PREFIX, PATH, and PROJECT_DIR
            extra_args (list of str): extra args to append to the command line
        Returns:
            argv as list of strings
        """
        conda_var = conda_api.conda_prefix_variable()
        for name in (conda_var, 'PATH', 'PROJECT_DIR'):
            if name not in environ:
                raise ValueError("To get a runnable command for the app, %s must be set." % (name))

        (args, shell) = self._choose_args_and_shell(environ, extra_args)

        if args is None:
            # command doesn't work on our platform for example
            return None

        # always look in the project directory. This is a little
        # odd because we don't add PROJECT_DIR to PATH for child
        # processes - maybe we should?
        path = os.pathsep.join([environ['PROJECT_DIR'], environ['PATH']])

        # if we're using a shell, then args[0] is a whole command
        # line and not a single program name, and the shell will
        # search the path for us.
        if not shell:
            executable = find_executable(args[0], path)
            # if we didn't find args[0] on the path, we leave it as-is
            # and wait for it to fail when we later try to run it.
            if executable is not None:
                # if the executable is in cwd, for some reason find_executable does not
                # return the full path to it, just a relative path.
                args[0] = os.path.abspath(executable)

        # conda.misc.launch() uses the home directory
        # instead of the project directory as cwd when
        # running an installed package, but for our
        # purposes where we know we have a project dir
        # that's user-interesting, project directory seems
        # more useful. This way apps can for example find
        # sample data files relative to the project
        # directory.
        return CommandExecInfo(cwd=environ['PROJECT_DIR'], args=args, env=environ, shell=shell)
Example #7
0
    def check(dirname):
        env_var = conda_api.conda_prefix_variable()

        try:
            _push_fake_env_creator()
            project = Project(dirname)
            environ = minimal_environ()
            result = prepare_without_interaction(project, environ=environ, env_spec_name='foo')
            expected_path = project.env_specs['foo'].path(project.directory_path)
            assert result.environ[env_var] == expected_path

            environ = minimal_environ()
            result = prepare_without_interaction(project, environ=environ, env_spec_name='bar')
            assert result
            expected_path = project.env_specs['bar'].path(project.directory_path)
            assert result.environ[env_var] == expected_path
        finally:
            _pop_fake_env_creator()
Example #8
0
    def check(dirname):
        env_var = conda_api.conda_prefix_variable()

        try:
            _push_fake_env_creator()
            project = Project(dirname)
            environ = minimal_environ()
            result = prepare_without_interaction(project, environ=environ, env_spec_name='foo')
            expected_path = project.env_specs['foo'].path(project.directory_path)
            assert result.environ[env_var] == expected_path

            environ = minimal_environ()
            result = prepare_without_interaction(project, environ=environ, env_spec_name='bar')
            assert result
            expected_path = project.env_specs['bar'].path(project.directory_path)
            assert result.environ[env_var] == expected_path
        finally:
            _pop_fake_env_creator()
Example #9
0
 def missing_env_vars_to_configure(self, requirement, environ, local_state_file):
     """Override superclass to require env prefix."""
     if self._get_env_prefix(environ) is not None:
         return ()
     else:
         return (conda_api.conda_prefix_variable(), )
Example #10
0
 def _get_env_prefix(self, environ):
     # on unix, ENV_PATH is the prefix and DEFAULT_ENV can be just a name,
     # on windows DEFAULT_ENV is always the prefix
     return environ.get(conda_api.conda_prefix_variable(), None)
Example #11
0
from conda_kapsel.internal.test.test_conda_api import monkeypatch_conda_not_to_use_links
from conda_kapsel.prepare import (prepare_without_interaction, prepare_with_browser_ui, unprepare)
from conda_kapsel.project_file import DEFAULT_PROJECT_FILENAME
from conda_kapsel.project import Project
from conda_kapsel import provide
from conda_kapsel.plugins.registry import PluginRegistry
from conda_kapsel.plugins.providers.conda_env import CondaEnvProvider

from tornado import gen

if platform.system() == 'Windows':
    script_dir = "Scripts"
else:
    script_dir = "bin"

conda_env_var = conda_api.conda_prefix_variable()


def test_find_by_class_name_conda_env():
    registry = PluginRegistry()
    found = registry.find_provider_by_class_name(class_name="CondaEnvProvider")
    assert found is not None
    assert isinstance(found, CondaEnvProvider)


def test_prepare_and_unprepare_project_scoped_env(monkeypatch):
    monkeypatch_conda_not_to_use_links(monkeypatch)

    def prepare_project_scoped_env(dirname):
        project = Project(dirname)
        fake_old_path = "foo" + os.pathsep + "bar"
Example #12
0
def test_conda_variable_when_have_only_default_env(monkeypatch):
    monkeypatch.setattr('os.environ', dict(CONDA_DEFAULT_ENV='foo'))
    assert conda_api.conda_prefix_variable() == 'CONDA_DEFAULT_ENV'
Example #13
0
def test_conda_variable_when_have_all_three(monkeypatch):
    monkeypatch.setattr('os.environ', dict(CONDA_ENV_PATH='foo', CONDA_DEFAULT_ENV='bar', CONDA_PREFIX='baz'))
    assert conda_api.conda_prefix_variable() == 'CONDA_PREFIX'
Example #14
0
def test_conda_variable_when_have_only_default_env(monkeypatch):
    monkeypatch.setattr('os.environ', dict(CONDA_DEFAULT_ENV='foo'))
    assert conda_api.conda_prefix_variable() == 'CONDA_DEFAULT_ENV'
Example #15
0
def test_conda_variable_when_not_in_conda(monkeypatch):
    monkeypatch.setattr('os.environ', dict())
    assert conda_api.conda_prefix_variable() == 'CONDA_PREFIX'
Example #16
0
 def _get_env_prefix(self, environ):
     # on unix, ENV_PATH is the prefix and DEFAULT_ENV can be just a name,
     # on windows DEFAULT_ENV is always the prefix
     return environ.get(conda_api.conda_prefix_variable(), None)
Example #17
0
# -*- coding: utf-8 -*-
# ----------------------------------------------------------------------------
# Copyright © 2016, Continuum Analytics, Inc. All rights reserved.
#
# The full license is in the file LICENSE.txt, distributed with this software.
# ----------------------------------------------------------------------------
from __future__ import absolute_import, print_function

from conda_kapsel.commands.variable_commands import main_add, main_remove
from conda_kapsel.commands.main import _parse_args_and_run_subcommand
from conda_kapsel.internal.test.tmpfile_utils import with_directory_contents_completing_project_file
from conda_kapsel.internal.simple_status import SimpleStatus
from conda_kapsel.internal import conda_api
from conda_kapsel.project_file import DEFAULT_PROJECT_FILENAME

PLATFORM_ENV_VAR = conda_api.conda_prefix_variable()


class Args(object):
    def __init__(self, vars_to_add=None, vars_to_remove=None, directory='.', default=None):
        self.directory = directory
        self.vars_to_add = vars_to_add
        self.vars_to_remove = vars_to_remove
        self.default = None


def test_add_variable_command(monkeypatch):

    params = []

    def mock_add_variables(project, _vars, defaults):
Example #18
0
def test_conda_variable_when_not_in_conda(monkeypatch):
    monkeypatch.setattr('os.environ', dict())
    assert conda_api.conda_prefix_variable() == 'CONDA_PREFIX'
Example #19
0
 def missing_env_vars_to_configure(self, requirement, environ, local_state_file):
     """Override superclass to require env prefix."""
     if self._get_env_prefix(environ) is not None:
         return ()
     else:
         return (conda_api.conda_prefix_variable(), )
Example #20
0
def test_conda_variable_when_have_all_three(monkeypatch):
    monkeypatch.setattr(
        'os.environ',
        dict(CONDA_ENV_PATH='foo', CONDA_DEFAULT_ENV='bar',
             CONDA_PREFIX='baz'))
    assert conda_api.conda_prefix_variable() == 'CONDA_PREFIX'
Example #21
0
import os

from conda_kapsel.test.project_utils import project_dir_disable_dedicated_env
from conda_kapsel.test.environ_utils import (minimal_environ,
                                             minimal_environ_no_conda_env)
from conda_kapsel.env_spec import EnvSpec
from conda_kapsel.local_state_file import LocalStateFile
from conda_kapsel.plugins.registry import PluginRegistry
from conda_kapsel.plugins.requirement import UserConfigOverrides
from conda_kapsel.plugins.requirements.conda_env import CondaEnvRequirement

from conda_kapsel.internal.test.tmpfile_utils import with_directory_contents
from conda_kapsel.internal import conda_api

conda_env_var = conda_api.conda_prefix_variable()


def _empty_default_requirement():
    return CondaEnvRequirement(
        registry=PluginRegistry(),
        env_specs=dict(default=EnvSpec('default', [], [])))


def test_env_var():
    registry = PluginRegistry()
    requirement = CondaEnvRequirement(registry)
    assert requirement.env_var == conda_env_var


def test_conda_env_title_and_description():