Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/conda/conda into priority
Browse files Browse the repository at this point in the history
Conflicts:
	tests/conda_env/support/notebook.ipynb
  • Loading branch information
HugoTian committed Aug 17, 2016
2 parents 3259a1d + ce75265 commit 4751d3a
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 7 deletions.
11 changes: 11 additions & 0 deletions conda_env/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ def load_from_directory(directory):
# TODO This should lean more on conda instead of divining it from the outside
# TODO tests!!!
def from_environment(name, prefix, no_builds=False, ignore_channels=False):
"""
Get environment object from prefix
Args:
name: The name of environment
prefix: The path of prefix
no_builds: Whether has build requirement
ignore_channels: whether ingore_channels
Returns: Environment obejct
"""
installed = install.linked(prefix, ignore_channels=ignore_channels)
conda_pkgs = copy(installed)
# json=True hides the output, data is added to installed
Expand Down
16 changes: 14 additions & 2 deletions conda_env/installers/conda.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,20 @@
def install(prefix, specs, args, env, prune=False):
# TODO: support all various ways this happens
# Including 'nodefaults' in the channels list disables the defaults
index = get_index(channel_urls=[chan for chan in env.channels
if chan != 'nodefaults'],
new_specs = []
channel_urls = set()
for elem in specs:
if "::" in elem:
channel_urls.add(elem.split("::")[0])
new_specs.append(elem.split("::")[-1])
else:
new_specs.append(elem)
specs = new_specs
channel_urls = list(channel_urls)
# TODO: support all various ways this happens
# Including 'nodefaults' in the channels list disables the defaults
index = get_index(channel_urls=channel_urls + [chan for chan in env.channels
if chan != 'nodefaults'],
prepend='nodefaults' not in env.channels)
actions = plan.install_actions(prefix, index, specs, prune=prune)

Expand Down
4 changes: 2 additions & 2 deletions conda_env/pip_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ def add_pip_installed(prefix, installed_pkgs, json=None, output=True):

# TODO Refactor so installed is a real list of objects/dicts
# instead of strings allowing for direct comparison
conda_names = {d.rsplit('-', 2)[0] for d in installed_pkgs}

# split :: to get rid of channel info
conda_names = {d.rsplit('-', 2)[0].split("::")[-1] for d in installed_pkgs}
for pip_pkg in installed(prefix, output=output):
if pip_pkg['name'] in conda_names and not 'path' in pip_pkg:
continue
Expand Down
2 changes: 1 addition & 1 deletion tests/conda_env/support/notebook.ipynb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"metadata": {"signature": "", "name": ""}, "worksheets": [{"cells": []}], "nbformat": 3, "nbformat_minor": 0}
{"metadata": {"signature": "", "name": ""}, "worksheets": [{"cells": []}], "nbformat": 3, "nbformat_minor": 0}
32 changes: 30 additions & 2 deletions tests/conda_env/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import os
import unittest
import tempfile
import sys
from shlex import split

from conda_env.exceptions import SpecNotFound
Expand All @@ -15,6 +14,7 @@
from conda.cli.main_create import configure_parser as conda_create_parser
from conda.cli.main_list import configure_parser as list_parser
from conda.cli.main_info import configure_parser as info_parser
from conda.cli.main_install import configure_parser as install_parser
from conda.cli.main import generate_parser

environment_1 = '''
Expand Down Expand Up @@ -49,7 +49,7 @@ class Commands:
LIST = "list"
CREATE = "create"
INFO = "info"

INSTALL = "install"

def run_env_command(command, prefix, *arguments):
"""
Expand Down Expand Up @@ -91,6 +91,7 @@ def run_env_command(command, prefix, *arguments):
Commands.CREATE: conda_create_parser,
Commands.LIST: list_parser,
Commands.INFO: info_parser,
Commands.INSTALL: install_parser
}


Expand Down Expand Up @@ -279,5 +280,32 @@ def test_list(self):
snowflake2, e = run_conda_command(Commands.LIST, test_env_name_2, "-e")
self.assertEqual(snowflake, snowflake2)

def test_export_muti_channel(self):
"""
Test conda env export
"""

run_conda_command(Commands.CREATE, test_env_name_2, "python")
self.assertTrue(env_is_created(test_env_name_2))

# install something from other channel not in config file
run_conda_command(Commands.INSTALL, test_env_name_2, "-c", "numba", "llvmlite")
snowflake, e, = run_env_command(Commands.ENV_EXPORT, test_env_name_2)

check1, e = run_conda_command(Commands.LIST, test_env_name_2, "--explicit")

with tempfile.NamedTemporaryFile(mode="w", suffix="yml", delete=False) as env_yaml:
env_yaml.write(snowflake)
env_yaml.flush()
env_yaml.close()
run_env_command(Commands.ENV_REMOVE, test_env_name_2)
self.assertFalse(env_is_created(test_env_name_2))
run_env_command(Commands.ENV_CREATE, env_yaml.name)
self.assertTrue(env_is_created(test_env_name_2))

# check explicit that we have same file
check2, e = run_conda_command(Commands.LIST, test_env_name_2, "--explicit")
self.assertEqual(check1, check2)

if __name__ == '__main__':
unittest.main()

0 comments on commit 4751d3a

Please sign in to comment.