Example #1
0
def test_info():
    conda_info_out, conda_info_err, rc = run_command(Commands.INFO)
    assert_equals(conda_info_err, '')
    for name in ['platform', 'conda version', 'root environment',
                 'default environment', 'envs directories', 'package cache',
                 'channel URLs', 'config file', 'offline mode']:
        assert_in(name, conda_info_out)

    conda_info_e_out, conda_info_e_err, rc = run_command(Commands.INFO, '-e')
    assert_in('root', conda_info_e_out)
    assert_equals(conda_info_e_err, '')

    conda_info_s_out, conda_info_s_err, rc = run_command(Commands.INFO, '-s')
    assert_equals(conda_info_s_err, '')
    for name in ['sys.version', 'sys.prefix', 'sys.executable', 'conda location',
                 'conda-build', 'CIO_TEST', 'CONDA_DEFAULT_ENV', 'PATH', 'PYTHONPATH']:
        assert_in(name, conda_info_s_out)
    if config.platform == 'linux':
        assert_in('LD_LIBRARY_PATH', conda_info_s_out)
    if config.platform == 'osx':
        assert_in('DYLD_LIBRARY_PATH', conda_info_s_out)

    conda_info_all_out, conda_info_all_err, rc = run_command(Commands.INFO, '--all')
    assert_equals(conda_info_all_err, '')
    assert_in(conda_info_out, conda_info_all_out)
    assert_in(conda_info_e_out, conda_info_all_out)
    assert_in(conda_info_s_out, conda_info_all_out)
Example #2
0
def test_info_root():
    stdout, stderr, rc = run_command(Commands.INFO, "--root")
    assert rc == 0
    assert not stderr
    assert isdir(stdout.strip())

    stdout, stderr, rc = run_command(Commands.INFO, "--root", "--json")
    assert rc == 0
    assert not stderr
    json_obj = json.loads(stdout.strip())
    assert isdir(json_obj["root_prefix"])
Example #3
0
def test_config_command_bad_args():
    with make_temp_condarc() as rc:
        stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc,
                                                  '--add', 'notarealkey', 'test',
                                                  use_exception_handler=True)
        assert stdout == ''

        stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc, '--set',
                                                  'notarealkey', 'true',
                                                  use_exception_handler=True)
        assert stdout == ''
Example #4
0
def test_invalid_config():
    condarc="""\
fgddgh
channels:
  - test
"""
    try:
        with make_temp_condarc(condarc) as rc:
            rc_path = rc
            run_command(Commands.CONFIG, '--file', rc, '--add', 'channels', 'test')
    except ConfigurationLoadError as err:
        assert "reason: invalid yaml at line" in err.message, err.message
Example #5
0
def test_info_unsafe_channels():
    url = "https://conda.anaconda.org/t/tk-123/a/b/c"
    with env_var("CONDA_CHANNELS", url):
        stdout, stderr, rc = run_command(Commands.INFO, "--unsafe-channels")
        assert rc == 0
        assert not stderr
        assert "tk-123" in stdout

        stdout, stderr, rc = run_command(Commands.INFO, "--unsafe-channels", "--json")
        assert rc == 0
        assert not stderr
        json_obj = json.loads(stdout.strip())
        assert url in json_obj["channels"]
Example #6
0
def test_info_package_json():
    out, err, rc = run_command(Commands.INFO, "--json", "itsdangerous=1.0.0=py37_0")

    out = json.loads(out)
    assert set(out.keys()) == {"itsdangerous=1.0.0=py37_0"}
    assert len(out["itsdangerous=1.0.0=py37_0"]) == 1
    assert isinstance(out["itsdangerous=1.0.0=py37_0"], list)

    out, err, rc = run_command(Commands.INFO, "--json", "itsdangerous")

    out = json.loads(out)
    assert set(out.keys()) == {"itsdangerous"}
    assert len(out["itsdangerous"]) > 1
    assert isinstance(out["itsdangerous"], list)
Example #7
0
def test_help_through_python_api():
    stdout, stderr, rc = run_command(Commands.HELP)
    assert rc == 0
    assert not stderr
    assert "\n    install" in stdout

    with pytest.raises(EnvironmentLocationNotFound):
        run_command(Commands.LIST, "-p", "not-a-real-path")

    stdout, stderr, rc = run_command(Commands.LIST, "-p", "not-a-real-path",
                                         use_exception_handler=True)
    assert rc == 1
    assert "Not a conda environment" in stderr
    assert not stdout
Example #8
0
def test_info_package_json():
    out, err, rc = run_command(Commands.INFO, "--json", "numpy=1.11.0=py35_0")

    out = json.loads(out)
    assert set(out.keys()) == {"numpy=1.11.0=py35_0"}
    assert len(out["numpy=1.11.0=py35_0"]) == 1
    assert isinstance(out["numpy=1.11.0=py35_0"], list)

    out, err, rc = run_command(Commands.INFO, "--json", "numpy")

    out = json.loads(out)
    assert set(out.keys()) == {"numpy"}
    assert len(out["numpy"]) > 1
    assert isinstance(out["numpy"], list)
Example #9
0
def test_invalid_config():
    condarc="""\
fgddgh
channels:
  - test
"""
    try:
        with make_temp_condarc(condarc) as rc:
            rc_path = rc
            run_command(Commands.CONFIG, '--file', rc, '--add', 'channels', 'test')
    except LoadError as err:
        error1 = "Load Error: in "
        error2 = "on line 1, column 8. Invalid YAML"
        assert error1 in err.message
        assert error2 in err.message
Example #10
0
def test_config_set():
    # Test the config set command
    # Make sure it accepts only boolean values for boolean keys and any value for string keys

    with make_temp_condarc() as rc:
        stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc,
                                                  '--set', 'always_yes', 'yes')

        assert stdout == ''
        assert stderr == ''

        stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc,
                                                  '--set', 'always_yes', 'no')

        assert stdout == ''
        assert stderr == ''
Example #11
0
def test_config_command_show():
    # test alphabetical yaml output
    with make_temp_condarc() as rc:
        stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc, '--show')
        output_keys = yaml_load(stdout).keys()

        assert stderr == ''
        assert sorted(output_keys) == [item for item in output_keys]
Example #12
0
def get_conda_envs_from_python_api():
    try:
        from conda.cli.python_api import run_command, Commands
    except (ImportError, OSError):
        return
    from json import loads
    c_stdout, c_stderr, return_code = run_command(Commands.INFO, "--json")
    json_conda_info = loads(c_stdout)
    return json_conda_info["envs"]
Example #13
0
def test_get_info_dict(cli_install_mock):
    # This test patches conda.cli.install.install to throw an artificial exception.
    # What we're looking for here is the proper behavior for how error reports work with
    # collecting `conda info` in this situation.
    with env_var('CONDA_REPORT_ERRORS', 'false', reset_context):
        out, err, rc = run_command(Commands.CREATE, "-n blargblargblarg blarg --dry-run --json",
                                   use_exception_handler=True)
        assert cli_install_mock.call_count == 1
        sys.stdout.write(out)
        sys.stderr.write(err)
        assert not err
        json_obj = json.loads(out)
        assert json_obj['conda_info']['conda_version']

        out, err, rc = run_command(Commands.CREATE, "-n blargblargblarg blarg --dry-run",
                                   use_exception_handler=True)
        sys.stderr.write(out)
        sys.stderr.write(err)
        assert "conda info could not be constructed" not in err
        assert not out
Example #14
0
def test_config_set():
    # Test the config set command
    # Make sure it accepts only boolean values for boolean keys and any value for string keys

    with make_temp_condarc() as rc:
        stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc,
                                                  '--set', 'always_yes', 'yes')
        assert stdout == ''
        assert stderr == ''
        with open(rc) as fh:
            content = yaml_load(fh.read())
            assert content['always_yes'] is True

        stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc,
                                                  '--set', 'always_yes', 'no')
        assert stdout == ''
        assert stderr == ''
        with open(rc) as fh:
            content = yaml_load(fh.read())
            assert content['always_yes'] is False

        stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc,
                                                  '--set', 'proxy_servers.http', '1.2.3.4:5678')
        assert stdout == ''
        assert stderr == ''
        with open(rc) as fh:
            content = yaml_load(fh.read())
            assert content['always_yes'] is False
            assert content['proxy_servers'] == {'http': '1.2.3.4:5678'}

        stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc,
                                                  '--set', 'ssl_verify', 'false')
        assert stdout == ''
        assert stderr == ''

        stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc,
                                                  '--get', 'ssl_verify')
        assert stdout.strip() == '--set ssl_verify False'
        assert stderr == ''
Example #15
0
def test_set_rc_string():
    # Test setting string keys in .condarc

    # We specifically test ssl_verify since it can be either a boolean or a string
    with make_temp_condarc() as rc:
        assert context.ssl_verify is True
        stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc,
                                                  '--set', 'ssl_verify', 'no')
        assert stdout == ''
        assert stderr == ''

        reset_context([rc])
        assert context.ssl_verify is False

        with NamedTemporaryFile() as tf:
            stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc,
                                                      '--set', 'ssl_verify', tf.name)
            assert stdout == ''
            assert stderr == ''

            reset_context([rc])
            assert context.ssl_verify == tf.name
Example #16
0
def test_info():
    conda_info_out, conda_info_err, rc = run_command(Commands.INFO)
    assert_equals(conda_info_err, '')
    for name in ['platform', 'conda version',
                 'envs directories', 'package cache',
                 'channel URLs', 'config file', 'offline mode']:
        assert_in(name, conda_info_out)

    conda_info_e_out, conda_info_e_err, rc = run_command(Commands.INFO, '-e')
    assert_in('base', conda_info_e_out)
    assert_equals(conda_info_e_err, '')

    conda_info_s_out, conda_info_s_err, rc = run_command(Commands.INFO, '-s')
    assert_equals(conda_info_s_err, '')
    for name in ['sys.version', 'sys.prefix', 'sys.executable', 'conda location',
                 'conda-build', 'PATH']:
        assert_in(name, conda_info_s_out)

    conda_info_all_out, conda_info_all_err, rc = run_command(Commands.INFO, '--all')
    assert_equals(conda_info_all_err, '')
    assert_in(conda_info_out, conda_info_all_out)
    assert_in(conda_info_e_out, conda_info_all_out)
    assert_in(conda_info_s_out, conda_info_all_out)
Example #17
0
def test_config_command_remove_force():
    # Finally, test --remove, --remove-key
    with make_temp_condarc() as rc:
        run_command(Commands.CONFIG, '--file', rc, '--add',
                          'channels', 'test')
        run_command(Commands.CONFIG, '--file', rc, '--set',
                          'always_yes', 'true')
        stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc,
                                           '--remove', 'channels', 'test')
        assert stdout == stderr == ''
        assert yaml_load(_read_test_condarc(rc)) == {'channels': ['defaults'],
                                                     'always_yes': True}

        stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc,
                                           '--remove', 'channels', 'test', use_exception_handler=True)
        assert stdout == ''
        assert "CondaKeyError: 'channels': 'test' is not in the 'channels' " \
               "key of the config file" in stderr

        stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc,
                                           '--remove', 'disallow', 'python', use_exception_handler=True)
        assert stdout == ''
        assert "CondaKeyError: 'disallow': key 'disallow' " \
               "is not in the config file" in stderr

        stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc,
                                           '--remove-key', 'always_yes')
        assert stdout == stderr == ''
        assert yaml_load(_read_test_condarc(rc)) == {'channels': ['defaults']}

        stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc,
                                           '--remove-key', 'always_yes', use_exception_handler=True)

        assert stdout == ''
        assert "CondaKeyError: 'always_yes': key 'always_yes' " \
               "is not in the config file" in stderr
Example #18
0
    def get_json(self, search_string):
        """
        Function takes search_string variable and returns results from the bioconda channel in JSON format

        """
        if run_command is None:
            raise Exception(
                f"Invalid search destination. {deps_error_message('conda')}")
        raw_out, err, exit_code = run_command('search',
                                              '-c',
                                              self.channel,
                                              search_string,
                                              use_exception_handler=True)
        if exit_code != 0:
            logging.info(f'Search failed with: {err}')
            return []
        return [{
            'package': n.split()[0],
            'version': n.split()[1],
            'build': n.split()[2]
        } for n in raw_out.split('\n')[2:-1]]
Example #19
0
def getCondaPackages():
    """Get products and their versions from the conda environment.

    Returns
    -------
    packages : `dict`
        Keys (type `str`) are product names; values (type `str`) are their
        versions.

    Notes
    -----
    Returns empty result if a conda environment is not in use or can not
    be queried.
    """

    try:
        import json
        from conda.cli.python_api import Commands, run_command
    except ImportError:
        return {}

    # Get the installed package list
    versions_json = run_command(Commands.LIST, "--json")
    packages = {
        pkg["name"]: pkg["version"]
        for pkg in json.loads(versions_json[0])
    }

    # Try to work out the conda environment name and include it as a fake
    # package. The "obvious" way of running "conda info --json" does give
    # access to the active_prefix but takes about 2 seconds to run.
    # The equivalent to the code above would be:
    #    info_json = run_command(Commands.INFO, "--json")
    # As a comporomise look for the env name in the path to the python
    # executable
    match = re.search(r"/envs/(.*?)/bin/", sys.executable)
    if match:
        packages["conda_env"] = match.group(1)

    return packages
Example #20
0
def get_package_list():
    """Get list of currently installed packages
    
    Runs 'conda list -e' to get the currently installed
    packages.
    
    Returns:
        bytes -- Output of 'conda list -e'
    """
    try:
        import conda.cli.python_api as cli
        return cli.run_command('list', "-e")[0].encode('utf-8')

    except ModuleNotFoundError:

        import subprocess

        try:
            result = subprocess.run(['conda', 'list', '-e'],
                                    stdout=subprocess.PIPE)
            return result.stdout
        except FileNotFoundError:
            return None
Example #21
0
    def check_ldd(self, path: str, env: str):
        """Run ldd on executables and libraries in a path, and find uses of a
        system version of libraries containing the package name

        Args:
            path: The path to a directory of (or a single) executables or
                    libraries
            env: The conda environment in which to run ldd
        """

        # '|| exit 0' prevents ldd from failing due to non executables
        stdout, stderr, code = run_command(Commands.RUN, "-n", env, "ldd",
                                           path, "||", "exit", "0")
        log.debug(f"ldd stdout: '{stdout}', stderr: '{stderr}', code: {code}")
        for line in stdout.split("\n"):
            if re.search(".*/usr/lib/.*", line):
                if self.sub_packages():
                    for sub in self.sub_packages():
                        if re.search(f'.*{sub}.*', line):
                            raise LibError(line)
                else:
                    if re.search(f".*{self.name()}.*", line):
                        raise LibError(line)
Example #22
0
def test_get_boolean_value():
    with make_temp_condarc(CONDARC_BASE) as rc:
        stdout, stderr, _ = run_command(Commands.CONFIG, '--file', rc, '--get',
                                        'changeps1')
        assert stdout.strip() == "--set changeps1 False"
        assert stderr == ""
Example #23
0
else:
    extra_requires = ['openexr>=1.3.0']
    dependency_links = [
        'https://github.com/jamesbowman/openexrpython/tarball/master#egg=openexr-1.3.0'
    ]
    package_data = {
        "sh": ["libsh.cpython-" + version_string + "m-x86_64-linux-gnu.so"],
        "tools3d":
        ["libspharm.cpython-" + version_string + "m-x86_64-linux-gnu.so"]
    }

conda_install_packages = [
    'numpy', 'scipy', 'imageio', 'tqdm', 'cffi', 'astropy', 'pandas', 'xarray',
    'matplotlib'
]
out = Conda.run_command("install", conda_install_packages)

setup(
    name='skylibs',
    description=
    ('Tools to read, write, perform projections and handle LDR/HDR environment maps (IBL).'
     ),
    author='Bruno Marques, Original author: Yannick Hold',
    author_email='*****@*****.**',
    license="LGPLv3",
    url='https://github.com/bdorta/skylibs',
    version='0.5',
    packages=[
        'ezexr', 'envmap', 'hdrio', 'hdrtools', 'hdrtools/tonemapping', 'sh',
        'skydb', 'tools3d'
    ],
Example #24
0
def install_app(app_name):

    package_name = app_name + "-app"

    channels, _, _ = run_command("config", "--show", "channels", "--json")
    if "conda-forge" not in channels:
        run_command("config", "--add", "channels", "conda-forge")
        print("Warning: conda-forge channel added!")

    if app_name not in known_apps_with_app_package:
        print(f"Checking if package {package_name} exists...")
        try:
            result = run_command("search", package_name, "--json")
        except Exception:
            package_name = app_name
            try:
                result = run_command("search", package_name, "--json")
            except Exception:
                print("An exception occurred during the conda search. "
                      "It maybe that the package does not exist")
                sys.exit(1)

        print(f"Package {package_name} found!")

    print("Running conda info... ", end="", flush=True)
    conda_data = get_conda_data()
    print("done")
    path_root = conda_data["root_prefix"]

    if conda_data["root_writable"]:
        if os.name == "nt":
            # quickfix: I wasn't able to permanently set the PATH on Windows
            path_bin = Path(path_root) / "condabin"
        else:
            path_bin = Path(path_root) / "condabin/app"
    else:
        if not os.name == "nt":
            path_bin = Path.home() / ".local/bin/conda-app"
        else:
            print("\nError: conda-app cannot be used on Windows when "
                  "conda root is not writable. "
                  "You can retry with miniconda installed "
                  "only for you (not globally).")
            sys.exit(1)

    path_bin.mkdir(exist_ok=True, parents=True)

    export_path_posix = f"export PATH={path_bin}:$PATH\n"
    # bash
    modif_config_file(bash_config, export_path_posix)

    # zsh
    modif_config_file(Path.home() / ".zshrc", export_path_posix)

    # fish
    modif_config_file(
        Path.home() / ".config/fish/config.fish",
        f"set -gx PATH {path_bin} $PATH\n",
    )

    env_names = get_env_names(conda_data)
    env_name = "_env_" + app_name
    env_path = Path(path_root) / "envs" / env_name

    if env_name not in env_names:
        print(
            f"Create conda environment {env_name} "
            f"with package {package_name}... ",
            end="",
            flush=True,
        )

        result = run_command("create", "-n", env_name, package_name, "--json")
        try:
            data_create = json.loads(result[0])
        except json.decoder.JSONDecodeError:
            print(
                "\nwarning: json.decoder.JSONDecodeError "
                "(`conda create --json` produces text that can't be loaded as json!)"
            )
            prefix = None
            for line in result[0].split("\n"):
                if '"prefix":' in line:
                    prefix = line.split('"prefix": "')[1].split('"')[0]
                    break
            if prefix is None:
                raise
        else:
            prefix = data_create["prefix"]

        env_path = Path(prefix)

        print("done")

        if app_name == "mercurial":
            path_home_hgrc = Path.home() / ".hgrc"
            if not path_home_hgrc.exists():
                print("Filling ~/.hgrc with reasonable default "
                      "(edit to fill correct username and email address!)")
                with open(path_home_hgrc, "w") as file:
                    file.write(default_hgrc)

        try:
            commands = commands_app[app_name]
        except KeyError:
            commands = [app_name]

        for command in commands:
            if os.name == "nt":
                with open(path_bin / (command + ".bat"), "w") as file:
                    file.write("@echo off\n"
                               f"call conda activate {env_name}\n"
                               f"{command} %*\n"
                               "call conda deactivate\n")
            else:
                path_command = env_path / "bin" / command
                path_symlink = path_bin / command
                if path_symlink.exists():
                    path_symlink.unlink()
                path_symlink.symlink_to(path_command)

        if os.name == "nt":
            txt = "T"
        else:
            txt = "Open a new terminal and t"

        print(f"{app_name} should now be installed in\n{env_path}\n" + txt +
              f"he command(s) {commands} should be available.")

        add_to_app_list(app_name)
    else:
        print(f"environment {env_name} already exists in \n{env_path}\n"
              f"To reinstall or update {app_name}, first uninstall it with:\n"
              f"conda-app uninstall {app_name}")
Example #25
0
def get_conda_data():
    result = run_command("info", "--json")
    return json.loads(result[0])
Example #26
0
## Import required Libraries
import conda.cli.python_api as Conda
import sys
import json
from datetime import datetime
import os

packages = []

## Preparing package names as raw json file
with open('raw_list.json', 'w') as fp:
    temp = Conda.run_command(Conda.Commands.LIST, '--json')
    fp.write(temp[0])

## Processing json file and extracting package names
with open('raw_list.json') as fp:
    dic = json.load(fp)
for names in dic:
    packages.append(names.get('name'))

## Starting package updation
start_time = datetime.now()
for package_name in packages:
    print('Updating Package ' + package_name)
    line_break = '\n---------------------------------------------\n'
    try:
        print(f'start time :{datetime.now()}')
        temp = Conda.run_command(Conda.Commands.UPDATE, package_name)
        if 'already installed' in temp[0]:
            with open('logs.txt', 'a') as fp:
                fp.write(package_name + ' Package already Installed ')
Example #27
0
def test_config_command_basics():

        # Test that creating the file adds the defaults channel
    with make_temp_condarc() as rc:
        stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc, '--add',
                                                  'channels', 'test')
        assert stdout == stderr == ''
        assert _read_test_condarc(rc) == """\
channels:
  - test
  - defaults
"""
        print(_read_test_condarc(rc))
        print(_read_test_condarc(rc))
        print(_read_test_condarc(rc))

    with make_temp_condarc() as rc:
        # When defaults is explicitly given, it should not be added
        stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc, '--add',
                                                  'channels', 'test', '--add', 'channels',
                                                  'defaults', use_exception_handler=True)
        assert stdout == ''
        assert stderr.strip() == "Warning: 'defaults' already in 'channels' list, moving to the top"
        assert _read_test_condarc(rc) == """\
channels:
  - defaults
  - test
"""
    # Duplicate keys should not be added twice
    with make_temp_condarc() as rc:
        stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc, '--add',
                                                  'channels', 'test')
        assert stdout == stderr == ''
        stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc, '--add',
                                                  'channels', 'test', use_exception_handler=True)
        assert stdout == ''
        assert stderr.strip() == "Warning: 'test' already in 'channels' list, moving to the top"
        assert _read_test_condarc(rc) == """\
channels:
  - test
  - defaults
"""

    # Test append
    with make_temp_condarc() as rc:
        stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc, '--add',
                                                  'channels', 'test')
        assert stdout == stderr == ''
        stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc, '--append',
                                                  'channels', 'test', use_exception_handler=True)
        assert stdout == ''
        assert stderr.strip() == "Warning: 'test' already in 'channels' list, moving to the bottom"
        assert _read_test_condarc(rc) == """\
channels:
  - defaults
  - test
"""

    # Test duoble remove of defaults
    with make_temp_condarc() as rc:
        stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc, '--remove',
                                                  'channels', 'defaults')
        assert stdout == stderr == ''
        stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc, '--remove',
                                                  'channels', 'defaults',
                                                  use_exception_handler=True)
        assert stdout == ''
        assert "CondaKeyError: 'channels': 'defaults' is not in the 'channels' " \
               "key of the config file" in stderr

    # Test creating a new file with --set
    with make_temp_condarc() as rc:
        stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc,
                                                  '--set', 'always_yes', 'true')
        assert stdout == stderr == ''
        assert _read_test_condarc(rc) == """\
pkgs_dir = os.path.join(sys.prefix, 'pkgs')

channel_map = {
    'free': 'https://repo.anaconda.com/pkgs/free',
    'main': 'https://repo.anaconda.com/pkgs/main',
    'r': 'https://repo.anaconda.com/pkgs/r',
    'conda-forge': 'https://conda.anaconda.org/conda-forge',
    'bioconda': 'https://conda.anaconda.org/bioconda',
}

with env_vars({
        "CONDA_PKGS_DIRS": os.path.join('repos', 'main', subdir),
}):
    try:
        python_api.run_command("create", "-n", "fakeenv", "--download-only",
                               "python", "mkl")
    except:
        pass
    if sys.platform != "win32":
        try:
            python_api.run_command("create", "-n", "fakeenv",
                                   "--download-only", "libopenblas")
        except:
            pass

for chan, url in channel_map.items():
    for _subdir in (subdir, 'noarch'):
        subdir_path = os.path.join('repos', chan, _subdir)
        if not os.path.exists(subdir_path):
            os.makedirs(subdir_path)
        for fn in ("repodata.json", "repodata.json.bz2"):
Example #29
0
def check_remote_conda(pkg_name):
    """Search conda remote for all moose-libmesh package information."""
    search_tuple = run_command(Commands.SEARCH, ['-f', pkg_name, '--json'])
    if search_tuple[2] > 0:
        return None
    return latest_remote_libmesh_version(search_tuple[0])
Example #30
0
def build_conda_pack(base_path, tmp, hexrd_package_channel,
                     hexrdgui_output_folder):
    # First build the hexrdgui package
    recipe_path = str(base_path / '..' / 'conda.recipe')
    config = Config()
    config.channel = ['cjh1', 'anaconda', 'conda-forge']
    config.channel_urls = ['cjh1', 'anaconda', 'conda-forge']

    if hexrdgui_output_folder is not None:
        config.output_folder = hexrdgui_output_folder

    if hexrd_package_channel is not None:
        config.channel.insert(0, 'hexrd-channel')
        config.channel_urls.insert(0, hexrd_package_channel)

    # Determine the latest hexrd version in the hexrd_package_channel
    # (release or pre-release), and force that hexrd version to be used.
    params = [
        Conda.Commands.SEARCH,
        '--channel',
        hexrd_package_channel,
        '--json',
        'hexrd',
    ]
    output = Conda.run_command(*params)
    results = json.loads(output[0])
    hexrd_version = results['hexrd'][-1]['version']
    config.variant['hexrd_version'] = hexrd_version

    config.CONDA_PY = '38'
    logger.info('Building hexrdgui conda package.')
    CondaBuild.build(recipe_path, config=config)

    logger.info('Creating new conda environment.')
    # Now create a new environment to install the package into
    env_prefix = str(tmp / package_env_name)

    channels = ['--channel', 'anaconda', '--channel', 'conda-forge']

    # For the mac we need to use our own version of Python built with the
    # latest SDK. See https://github.com/HEXRD/hexrdgui/issues/505 for
    # more details. So we add the HEXRD channel that has our Python package.
    if platform.system() == 'Darwin':
        channels = ['--channel', 'HEXRD'] + channels

    Conda.run_command(Conda.Commands.CREATE, '--prefix', env_prefix, *channels,
                      'python=3.8.4')

    hexrdgui_output_folder_uri = Path(
        hexrdgui_output_folder).absolute().as_uri()

    logger.info('Installing hexrdgui into new environment.')
    # Install hexrdgui into new environment
    params = [
        Conda.Commands.INSTALL, '--prefix', env_prefix, '--channel',
        hexrdgui_output_folder_uri, '--channel', hexrd_package_channel,
        '--channel', 'cjh1', '--channel', 'anaconda', '--channel',
        'conda-forge', f'hexrd=={hexrd_version}', 'hexrdgui'
    ]
    Conda.run_command(*params)

    # Override the libgfortran so we get a version that is
    # build with a SDK that is acceptable to the notary!
    if platform.system() == 'Darwin':
        params = [
            Conda.Commands.INSTALL, '--prefix', env_prefix, '--channel',
            'conda-forge', 'libgfortran=4.0.0'
        ]
        Conda.run_command(*params)

    logger.info('Generating tar from environment using conda-pack.')
    # Now use conda-pack to create relocatable archive
    archive_path = str(tmp / ('hexrdgui.%s' % archive_format))
    CondaPack.pack(prefix=env_prefix,
                   output=archive_path,
                   format=archive_format)

    return archive_path
Example #31
0
def test_get_map_subkey(key, value):
    with make_temp_condarc(CONDARC_MAPS) as rc:
        stdout, stderr, _ = run_command(Commands.CONFIG, '--file', rc, '--get',
                                        key)
        assert stdout.strip() == f"--set {key} {value}"
        assert stderr == ""
def build_parcel():
    jinja_env = Environment(loader=FileSystemLoader('templates'))

    (jpy_version, parcel_version) = get_version()

    # Create the JupyterHub Environment
    render_environment_yaml(jinja_env, jpy_version=jpy_version)
    with open('environment.yml') as f:
        conda_env = yaml.load(f, Loader=yaml.Loader)
    check_call(
        'conda env create --force -p {name}'.format(**conda_env).split(' '))

    # Get the complete list of installed packages
    components = json.loads(
        run_command(Commands.LIST, '--json', '-p', conda_env['name'])[0])
    jpy_version = [
        x['version'] for x in components if x['name'] == conda_env['name']
    ][0]

    # Create the meta folder under the conda-environment
    meta_dir = os.path.join(conda_env['name'], 'meta')
    os.makedirs(meta_dir, exist_ok=True)

    # Create the meta/parcel.json file
    parcel_template = jinja_env.get_template('parcel.yaml')
    parcel_rendered = parcel_template.render(conda_env=conda_env,
                                             jpy_version=jpy_version,
                                             parcel_version=parcel_version,
                                             components=components)
    parcel_dict = yaml.load(parcel_rendered, Loader=yaml.Loader)

    parcel_json = os.path.join(meta_dir, 'parcel.json')
    with open(parcel_json, 'w') as f:
        json.dump(parcel_dict, f)

    print(check_output(['validator.sh', '-p', parcel_json]).decode('utf-8'))

    # Create the scripts.defines file (a.k.a. activate script)
    shutil.copy('env.sh',
                os.path.join(meta_dir, parcel_dict['scripts']['defines']))

    # Use conda-pack to create the .parcel file
    if os.path.exists('parcels'):
        shutil.rmtree('parcels')
    os.makedirs('parcels', exist_ok=True)
    parcel_fqn = '{name}-{version}'.format(**parcel_dict)
    parcel_file = conda_pack.pack(prefix=conda_env['name'],
                                  output='%s-distro.parcel' % parcel_fqn,
                                  arcroot=parcel_fqn,
                                  dest_prefix='/opt/cloudera/parcels/%s' %
                                  parcel_fqn,
                                  format="tar.gz",
                                  force=True)

    # Link generated file to selected distros
    distros = ['el6', 'el7']
    for distro in distros:
        dest_name = 'parcels/{}-{}.parcel'.format(parcel_fqn, distro)
        os.symlink('../%s-distro.parcel' % parcel_fqn, dest_name)
        check_call(['validator.sh', '-f', dest_name])

    # Generate the parcel manifest file
    print(check_output(['make_manifest.py', 'parcels']).decode('utf-8'))
Example #33
0
def test_config_command_parser():
    # Now test the YAML "parser"
    # Channels is normal content.
    # create_default_packages has extra spaces in list items
    condarc = """\
channels:
  - test
  - defaults

create_default_packages :
  -  ipython
  -  numpy

changeps1: false

# Here is a comment
always_yes: true
"""
    # First verify that this itself is valid YAML
    assert yaml_load(condarc) == {'channels': ['test', 'defaults'],
                                  'create_default_packages': ['ipython', 'numpy'],
                                  'changeps1': False,
                                  'always_yes': True}

    with make_temp_condarc(condarc) as rc:
        stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc, '--get', use_exception_handler=True)
        print(stdout)
        assert stdout.strip() == """\
--set always_yes True
--set changeps1 False
--add channels 'defaults'   # lowest priority
--add channels 'test'   # highest priority
--add create_default_packages 'numpy'
--add create_default_packages 'ipython'\
"""
        with open(rc, 'r') as fh:
            print(fh.read())

        stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc, '--prepend',
                                                  'channels', 'mychannel')
        assert stdout == stderr == ''

        with open(rc, 'r') as fh:
            print(fh.read())

        assert _read_test_condarc(rc) == """\
channels:
  - mychannel
  - test
  - defaults

create_default_packages:
  - ipython
  - numpy

changeps1: false

# Here is a comment
always_yes: true
"""

        stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc,
                                           '--set', 'changeps1', 'true')

        assert stdout == stderr == ''

        assert _read_test_condarc(rc)== """\
channels:
  - mychannel
  - test
  - defaults

create_default_packages:
  - ipython
  - numpy

changeps1: true

# Here is a comment
always_yes: true
"""

        # Test adding a new list key. We couldn't test this above because it
        # doesn't work yet with odd whitespace
    condarc = """\
channels:
  - test
  - defaults

always_yes: true
"""

    with make_temp_condarc(condarc) as rc:
        stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc, '--add',
                                           'disallowed_packages', 'perl')
        assert stdout == stderr == ''
        assert _read_test_condarc(rc) == condarc + """\
Example #34
0
def test_config_command_get():
    # Test --get
    condarc = """\
channels:
  - test
  - defaults

create_default_packages:
  - ipython
  - numpy

changeps1: false

always_yes: true

invalid_key: true

channel_alias: http://alpha.conda.anaconda.org
"""
    with make_temp_condarc(condarc) as rc:
        stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc, '--get', use_exception_handler=True)
        assert stdout.strip() == """\
--set always_yes True
--set changeps1 False
--set channel_alias http://alpha.conda.anaconda.org
--add channels 'defaults'   # lowest priority
--add channels 'test'   # highest priority
--add create_default_packages 'numpy'
--add create_default_packages 'ipython'\
"""
        assert stderr.strip() == "unknown key invalid_key"

        stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc,
                                           '--get', 'channels')

        assert stdout.strip() == """\
--add channels 'defaults'   # lowest priority
--add channels 'test'   # highest priority\
"""
        assert stderr == ""

        stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc,
                                           '--get', 'changeps1')

        assert stdout.strip() == """\
--set changeps1 False\
"""
        assert stderr == ""

        stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc,
                                           '--get', 'changeps1', 'channels')

        assert stdout.strip() == """\
--set changeps1 False
--add channels 'defaults'   # lowest priority
--add channels 'test'   # highest priority\
"""
        assert stderr == ""

        stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc, '--get', 'allow_softlinks')

        assert stdout == ""
        assert stderr == ""

        stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc, '--get', 'always_softlink')

        assert stdout == ""
        assert stderr == ""

        stdout, stderr, return_code = run_command(Commands.CONFIG, '--file', rc, '--get', 'track_features')

        assert stdout == ""
        assert stderr == ""
Example #35
0
import conda.cli.python_api as Conda
import sys

###################################################################################################
# The below is roughly equivalent to:
#   conda install -y 'args-go-here' 'no-whitespace-splitting-occurs' 'square-brackets-optional'

(stdout_str, stderr_str, return_code_int) = Conda.run_command(
    Conda.Commands.INSTALL,  # alternatively, you can just say "install"
    # ...it's probably safer long-term to use the Commands class though
    # Commands include:
    #  CLEAN,CONFIG,CREATE,INFO,INSTALL,HELP,LIST,REMOVE,SEARCH,UPDATE,RUN
    [
        'args-go-here', 'no-whitespace-splitting-occurs',
        'square-brackets-optional'
    ],
    use_exception_handler=
    True,  # Defaults to False, use that if you want to handle your own exceptions
    stdout=sys.stdout,  # Defaults to being returned as a str (stdout_str)
    stderr=sys.stderr,  # Also defaults to being returned as str (stderr_str)
    search_path=Conda.
    SEARCH_PATH  # this is the default; adding only for illustrative purposes
)
###################################################################################################

#https://stackoverflow.com/questions/41767340/using-conda-install-within-a-python-script

#import conda.cli
#conda.cli.main('conda', 'install',  '-y', 'numpy')
Example #36
0
    def show_about_dialog(self):

        # Initializes the message box.
        about_dialog = PyMod_QMessageBox(self.get_qt_parent())
        about_dialog.setIcon(QtWidgets.QMessageBox.Information)
        about_dialog.setWindowTitle(self.pymod_plugin_name)

        # Sets the main text.
        about_dialog.setText("Version: %s" % self.pymod_version + "." + self.pymod_revision)
        infomative_text = ('Copyright (C): 2020 Giacomo Janson, Alessandro Paiardini\n'
                           'Copyright (C): 2016 Giacomo Janson, Chengxin Zhang, Alessandro Paiardini'
                           '\n\nFor information on PyMod %s visit:\n'
                           '  http://schubert.bio.uniroma1.it/pymod/\n\n'
                           'Or send us an email at:\n %s' % (self.pymod_version, self.developer_email))
        about_dialog.setInformativeText(infomative_text)

        # Adds detailed information.
        pymod_plugin_path = os.path.dirname(os.path.dirname(pymod_lib.__file__))

        try:
            import PyQt5
            pyqt5_version = PyQt5.QtCore.PYQT_VERSION_STR
        except:
            pyqt5_version = "-"

        try:
            from pymol import Qt
            pymol_pyqt_name = Qt.PYQT_NAME
        except:
            pymol_pyqt_name = "-"

        try:
            import Bio
            biopython_version = Bio.__version__
        except:
            biopython_version = "-"

        try:
            import numpy
            numpy_version = numpy.__version__
        except:
            numpy_version = "-"

        try:
            import modeller
            modeller_version = modeller.__version__
            modeller_path = repr(modeller.__path__)
        except:
            modeller_version = "-"
            modeller_path = "-"

        try:
            import conda
            import conda.cli.python_api as conda_api
            conda_version = conda.__version__
            if self.DEVELOP:
                conda_info_dict = json.loads(conda_api.run_command(conda_api.Commands.INFO, "--json")[0])
                conda_info_text = "\n# Conda\n"
                for k in sorted(conda_info_dict.keys()):
                    conda_info_text += "- %s: %s\n" % (k, repr(conda_info_dict[k]))
        except:
            conda_version = "-"
            conda_info_dict = {}
            conda_info_text = ""

        has_pymol_conda = str(hasattr(pymol, "externing") and hasattr(pymol.externing, "conda"))

        def _get_path_string(path):
            _path = path
            if os.path.isdir(_path):
                return _path
            else:
                return _path + " (not found)"

        additional_text = ("# PyMod\n"
                           "- Version: " + self.pymod_version + "\n"
                           "- Revision: " + self.pymod_revision + "\n"
                           "- Plugin path: " + _get_path_string(pymod_plugin_path) + " \n"
                           "- Config directory: " + _get_path_string(self.cfg_directory_path) + "\n"
                           "- PyMod Directory: " + _get_path_string(self.current_pymod_dirpath) + "\n"
                           "- Current PyMod project: " + _get_path_string(self.current_project_dirpath) + "\n\n"

                           "# PyMOL\n"
                           "- Version: " + str(pymol.cmd.get_version()[0]) + "\n"
                           "- Path: " + sys.executable + "\n"
                           "- Qt: " + str(pymol_pyqt_name) + "\n"
                           "- Has Conda: " + has_pymol_conda + "\n\n"

                           "# Python\n"
                           "- Version: " + str(sys.version) + "\n"
                           "- Arch: " + pmos.get_python_architecture() + "\n"
                           "- Path: " + sys.executable + "\n\n"

                           "# Operating system\n"
                           "- Platform: " + sys.platform + "\n"
                           "- Arch: " + pmos.get_os_architecture() + "\n\n"

                           "# Python libs\n"
                           "- PyQt5: " + pyqt5_version + "\n"
                           "- Conda version: " + conda_version + "\n"
                           "- Numpy version: " + numpy_version + "\n"
                           "- Biopython version: " + biopython_version + "\n"
                           "- MODELLER version: " + modeller_version + "\n"
                           "- MODELLER path: " + modeller_path + "\n"
                          )

        if self.DEVELOP:
            additional_text += conda_info_text

        about_dialog.setDetailedText(additional_text)

        # Actually shows the message box.
        about_dialog.setModal(True)
        about_dialog.exec_()
Example #37
0
def test_config_command_get():
    # Test --get
    condarc = """\
channels:
  - test
  - defaults

create_default_packages:
  - ipython
  - numpy

changeps1: false

always_yes: true

invalid_key: true

channel_alias: http://alpha.conda.anaconda.org
"""
    with make_temp_condarc(condarc) as rc:
        stdout, stderr, return_code = run_command(Commands.CONFIG,
                                                  '--file',
                                                  rc,
                                                  '--get',
                                                  use_exception_handler=True)
        assert stdout.strip() == """\
--set always_yes True
--set changeps1 False
--set channel_alias http://alpha.conda.anaconda.org
--add channels 'defaults'   # lowest priority
--add channels 'test'   # highest priority
--add create_default_packages 'numpy'
--add create_default_packages 'ipython'\
"""
        assert stderr.strip() == "unknown key invalid_key"

        stdout, stderr, return_code = run_command(Commands.CONFIG, '--file',
                                                  rc, '--get', 'channels')

        assert stdout.strip() == """\
--add channels 'defaults'   # lowest priority
--add channels 'test'   # highest priority\
"""
        assert stderr == ""

        stdout, stderr, return_code = run_command(Commands.CONFIG, '--file',
                                                  rc, '--get', 'changeps1')

        assert stdout.strip() == """\
--set changeps1 False\
"""
        assert stderr == ""

        stdout, stderr, return_code = run_command(Commands.CONFIG, '--file',
                                                  rc, '--get', 'changeps1',
                                                  'channels')

        assert stdout.strip() == """\
--set changeps1 False
--add channels 'defaults'   # lowest priority
--add channels 'test'   # highest priority\
"""
        assert stderr == ""

        stdout, stderr, return_code = run_command(Commands.CONFIG, '--file',
                                                  rc, '--get',
                                                  'allow_softlinks')

        assert stdout == ""
        assert stderr == ""

        stdout, stderr, return_code = run_command(Commands.CONFIG, '--file',
                                                  rc, '--get',
                                                  'always_softlink')

        assert stdout == ""
        assert stderr == ""

        stdout, stderr, return_code = run_command(Commands.CONFIG, '--file',
                                                  rc, '--get',
                                                  'track_features')

        assert stdout == ""
        assert stderr == ""
Example #38
0
def test_cli_args_as_list():
    out, err, rc = run_command(Commands.CONFIG,
                               ["--show", "add_anaconda_token"])
    assert rc == 0
Example #39
0
def test_get_unconfigured_key():
    with make_temp_condarc(CONDARC_BASE) as rc:
        stdout, stderr, _ = run_command(Commands.CONFIG, '--file', rc, '--get',
                                        'allow_softlinks')
        assert stdout == ""
        assert stderr == ""
Example #40
0
def test_config_command_basics():

    # Test that creating the file adds the defaults channel
    with make_temp_condarc() as rc:
        stdout, stderr, return_code = run_command(Commands.CONFIG, '--file',
                                                  rc, '--add', 'channels',
                                                  'test')
        assert stdout == stderr == ''
        assert _read_test_condarc(rc) == """\
channels:
  - test
  - defaults
"""
        print(_read_test_condarc(rc))
        print(_read_test_condarc(rc))
        print(_read_test_condarc(rc))

    with make_temp_condarc() as rc:
        # When defaults is explicitly given, it should not be added
        stdout, stderr, return_code = run_command(Commands.CONFIG,
                                                  '--file',
                                                  rc,
                                                  '--add',
                                                  'channels',
                                                  'test',
                                                  '--add',
                                                  'channels',
                                                  'defaults',
                                                  use_exception_handler=True)
        assert stdout == ''
        assert stderr.strip(
        ) == "Warning: 'defaults' already in 'channels' list, moving to the top"
        assert _read_test_condarc(rc) == """\
channels:
  - defaults
  - test
"""
    # Duplicate keys should not be added twice
    with make_temp_condarc() as rc:
        stdout, stderr, return_code = run_command(Commands.CONFIG, '--file',
                                                  rc, '--add', 'channels',
                                                  'test')
        assert stdout == stderr == ''
        stdout, stderr, return_code = run_command(Commands.CONFIG,
                                                  '--file',
                                                  rc,
                                                  '--add',
                                                  'channels',
                                                  'test',
                                                  use_exception_handler=True)
        assert stdout == ''
        assert stderr.strip(
        ) == "Warning: 'test' already in 'channels' list, moving to the top"
        assert _read_test_condarc(rc) == """\
channels:
  - test
  - defaults
"""

    # Test append
    with make_temp_condarc() as rc:
        stdout, stderr, return_code = run_command(Commands.CONFIG, '--file',
                                                  rc, '--add', 'channels',
                                                  'test')
        assert stdout == stderr == ''
        stdout, stderr, return_code = run_command(Commands.CONFIG,
                                                  '--file',
                                                  rc,
                                                  '--append',
                                                  'channels',
                                                  'test',
                                                  use_exception_handler=True)
        assert stdout == ''
        assert stderr.strip(
        ) == "Warning: 'test' already in 'channels' list, moving to the bottom"
        assert _read_test_condarc(rc) == """\
channels:
  - defaults
  - test
"""

    # Test duoble remove of defaults
    with make_temp_condarc() as rc:
        stdout, stderr, return_code = run_command(Commands.CONFIG, '--file',
                                                  rc, '--remove', 'channels',
                                                  'defaults')
        assert stdout == stderr == ''
        stdout, stderr, return_code = run_command(Commands.CONFIG,
                                                  '--file',
                                                  rc,
                                                  '--remove',
                                                  'channels',
                                                  'defaults',
                                                  use_exception_handler=True)
        assert stdout == ''
        assert "CondaKeyError: 'channels': 'defaults' is not in the 'channels' " \
               "key of the config file" in stderr

    # Test creating a new file with --set
    with make_temp_condarc() as rc:
        stdout, stderr, return_code = run_command(Commands.CONFIG, '--file',
                                                  rc, '--set', 'always_yes',
                                                  'true')
        assert stdout == stderr == ''
        assert _read_test_condarc(rc) == """\
Example #41
0
def test_cli_args_as_strings():
    out, err, rc = run_command(Commands.CONFIG, "--show", "add_anaconda_token")
    assert rc == 0
Example #42
0
def test_config_command_parser():
    # Now test the YAML "parser"
    # Channels is normal content.
    # create_default_packages has extra spaces in list items
    condarc = """\
channels:
  - test
  - defaults

create_default_packages :
  -  ipython
  -  numpy

changeps1: false

# Here is a comment
always_yes: true
"""
    # First verify that this itself is valid YAML
    assert yaml_load(condarc) == {
        'channels': ['test', 'defaults'],
        'create_default_packages': ['ipython', 'numpy'],
        'changeps1': False,
        'always_yes': True
    }

    with make_temp_condarc(condarc) as rc:
        stdout, stderr, return_code = run_command(Commands.CONFIG,
                                                  '--file',
                                                  rc,
                                                  '--get',
                                                  use_exception_handler=True)
        print(stdout)
        assert stdout.strip() == """\
--set always_yes True
--set changeps1 False
--add channels 'defaults'   # lowest priority
--add channels 'test'   # highest priority
--add create_default_packages 'numpy'
--add create_default_packages 'ipython'\
"""
        with open(rc, 'r') as fh:
            print(fh.read())

        stdout, stderr, return_code = run_command(Commands.CONFIG, '--file',
                                                  rc, '--prepend', 'channels',
                                                  'mychannel')
        assert stdout == stderr == ''

        with open(rc, 'r') as fh:
            print(fh.read())

        assert _read_test_condarc(rc) == """\
channels:
  - mychannel
  - test
  - defaults

create_default_packages:
  - ipython
  - numpy

changeps1: false

# Here is a comment
always_yes: true
"""

        stdout, stderr, return_code = run_command(Commands.CONFIG, '--file',
                                                  rc, '--set', 'changeps1',
                                                  'true')

        assert stdout == stderr == ''

        assert _read_test_condarc(rc) == """\
channels:
  - mychannel
  - test
  - defaults

create_default_packages:
  - ipython
  - numpy

changeps1: true

# Here is a comment
always_yes: true
"""

        # Test adding a new list key. We couldn't test this above because it
        # doesn't work yet with odd whitespace
    condarc = """\
channels:
  - test
  - defaults

always_yes: true
"""

    with make_temp_condarc(condarc) as rc:
        stdout, stderr, return_code = run_command(Commands.CONFIG, '--file',
                                                  rc, '--add', 'disallow',
                                                  'perl')
        assert stdout == stderr == ''
        assert _read_test_condarc(rc) == condarc + """\
Example #43
0
import os
import cPickle
import copy
from cStringIO import StringIO

if not hasattr(sys,'frozen'):
    RELATIVE_LIB_PATH = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
    sys.path.append(RELATIVE_LIB_PATH)
else:
    RELATIVE_LIB_PATH = os.path.dirname(sys.eexecutable)

import conda.cli.python_api as Conda

#This grabs stuff from anaconda only!
os.environ['PYTHONIOENCODING'] = 'UTF-8'
x = Conda.run_command('list')[0].splitlines()
yy = set(sorted(map(lambda xx:str(xx.split(' ')[0]),x)))

#This is equivalent to running pip list
import pkg_resources
jj = set(sorted([p.project_name for p in pkg_resources.working_set]))

#This is something that I don’t really understand..
uu = {i.split('.')[0] for i in sys.modules}

stackpack = yy.union(jj.union(uu))

def updateSourceFile(fname):
    fname = os.path.realpath(fname)
    if os.path.splitext(fname)[1] == '.py':
        thedict = {'stack':[],