Exemplo n.º 1
0
def test_current_platform_unsupported_by_lock_set(monkeypatch):
    lock_set = CondaLockSet(package_specs_by_platform={'all': []},
                            platforms=[])
    spec = EnvSpec(name='myenv',
                   conda_packages=['ipython'],
                   pip_packages=['flake8'],
                   channels=[],
                   platforms=conda_api.default_platforms_with_current(),
                   lock_set=lock_set)

    def do_test(dirname):
        envdir = os.path.join(dirname, spec.name)

        manager = DefaultCondaManager(frontend=NullFrontend())

        deviations = manager.find_environment_deviations(envdir, spec)

        error = "Env spec 'myenv' does not have the current platform %s in the lock file" % conda_api.current_platform(
        )
        assert error == deviations.summary

        with pytest.raises(CondaManagerError) as excinfo:
            manager.fix_environment_deviations(envdir,
                                               spec,
                                               deviations=deviations)
        assert str(
            excinfo.value).startswith("Unable to update environment at ")

    with_directory_contents(dict(), do_test)
Exemplo n.º 2
0
    def _fill_default_content(self, as_json):
        as_json['name'] = os.path.basename(os.path.dirname(self.filename))
        as_json['platforms'].extend(conda_api.default_platforms_with_current())

        assert self._default_env_specs_func is not None
        default_env_specs = self._default_env_specs_func()
        assert default_env_specs is not None
        for env_spec in default_env_specs:
            as_json['env_specs'][env_spec.name] = env_spec.to_json()

        if len(default_env_specs) == 1:
            # if there's only one env spec, keep it for name/description
            # and put the packages and channels up in the global sections
            spec_name = next(iter(as_json['env_specs']))
            spec_json = as_json['env_specs'][spec_name]

            def move_list_elements(src, dest):
                # we want to preserve the dest list object with comments
                del dest[:]
                dest.extend(src)
                del src[:]

            if 'packages' in spec_json:
                move_list_elements(spec_json['packages'], as_json['packages'])
            if 'channels' in spec_json:
                move_list_elements(spec_json['channels'], as_json['channels'])
            if 'platforms' in spec_json:
                move_list_elements(spec_json['platforms'],
                                   as_json['platforms'])
Exemplo n.º 3
0
def _anaconda_default_env_spec(shared_base_spec):
    if shared_base_spec is None:
        inherit_from = ()
    else:
        inherit_from = (shared_base_spec, )
    return EnvSpec(name="default",
                   conda_packages=_default_env_spec_packages(),
                   channels=[],
                   platforms=conda_api.default_platforms_with_current(),
                   description="Default environment spec for running commands",
                   inherit_from_names=(),
                   inherit_from=inherit_from)
Exemplo n.º 4
0
    def _default_content(self):
        header = (
            "This is an Anaconda project file.\n" + "\n" + "Here you can describe your project and how to run it.\n" +
            "Use `anaconda-project run` to run the project.\n" +
            "The file is in YAML format, please see http://www.yaml.org/start.html for more.\n")
        sections = OrderedDict()

        sections['name'] = ("Set the 'name' key to name your project\n")

        sections['icon'] = ("Set the 'icon' key to give your project an icon\n")

        sections['description'] = ("Set a one-sentence-or-so 'description' key with project details\n")

        sections['commands'] = ("In the commands section, list your runnable scripts, notebooks, and other code.\n" +
                                "Use `anaconda-project add-command` to add commands.\n")

        sections['variables'] = ("In the variables section, list any environment variables your code depends on.\n"
                                 "Use `anaconda-project add-variable` to add variables.\n")

        sections['services'] = (
            "In the services section, list any services that should be\n" + "available before your code runs.\n" +
            "Use `anaconda-project add-service` to add services.\n")

        sections['downloads'] = ("In the downloads section, list any URLs to download to local files\n" +
                                 "before your code runs.\n" + "Use `anaconda-project add-download` to add downloads.\n")

        sections['packages'] = ("In the packages section, list any packages that must be installed\n" +
                                "before your code runs.\n" + "Use `anaconda-project add-packages` to add packages.\n")

        sections['channels'] = ("In the channels section, list any Conda channel URLs to be searched\n" +
                                "for packages.\n" + "\n" + "For example,\n" + "\n" + "channels:\n" + "   - mychannel\n")

        sections['platforms'] = ("In the platforms section, list platforms the project should work on\n" +
                                 "Examples: \"linux-64\", \"osx-64\", \"win-64\"\n" +
                                 "Use `anaconda-project add-platforms` to add platforms.\n")

        sections['env_specs'] = (
            "You can define multiple, named environment specs.\n" + "Each inherits any global packages or channels,\n" +
            "but can have its own unique ones also.\n" +
            "Use `anaconda-project add-env-spec` to add environment specs.\n")

        assert self._default_env_specs_func is not None
        default_env_specs = self._default_env_specs_func()
        assert default_env_specs is not None

        # we make a big string and then parse it because I can't figure out the
        # ruamel.yaml API to insert comments in front of map keys.
        def comment_out(comment):
            return ("# " + "\n# ".join(comment.split("\n")) + "\n").replace("# \n", "#\n")

        to_parse = comment_out(header)
        for section_name, comment in sections.items():
            # future: this is if/else is silly, we should be
            # assigning these bodies up above when we assign the
            # comments.
            if section_name == 'name':
                default_name = os.path.basename(os.path.dirname(self.filename))
                section_body = " " + json.dumps(default_name)
            elif section_name in ('icon', 'description'):
                section_body = ""  # empty body means null, not empty string
            elif section_name in ('channels', 'packages'):
                section_body = "  []"
            elif section_name == 'platforms':
                platforms = conda_api.default_platforms_with_current()
                section_body = "  [" + ", ".join(platforms) + "]"
            else:
                section_body = "  {}"
            to_parse = to_parse + "\n#\n" + comment_out(comment) + section_name + ":\n" + section_body + "\n\n\n"

        as_json = ryaml.load(to_parse, Loader=ryaml.RoundTripLoader)

        for env_spec in default_env_specs:
            as_json['env_specs'][env_spec.name] = env_spec.to_json()

        if len(default_env_specs) == 1:
            # if there's only one env spec, keep it for name/description
            # and put the packages and channels up in the global sections
            spec_name = next(iter(as_json['env_specs']))
            spec_json = as_json['env_specs'][spec_name]

            def move_list_elements(src, dest):
                # we want to preserve the dest list object with comments
                del dest[:]
                dest.extend(src)
                del src[:]

            if 'packages' in spec_json:
                move_list_elements(spec_json['packages'], as_json['packages'])
            if 'channels' in spec_json:
                move_list_elements(spec_json['channels'], as_json['channels'])
            if 'platforms' in spec_json:
                move_list_elements(spec_json['platforms'], as_json['platforms'])

        return as_json