How to use the conda.cli.python_api.run_command function in conda

To help you get started, we’ve selected a few conda examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github conda / conda / tests / test_config.py View on Github external
-  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 == ''
github conda / conda / tests / test_config.py View on Github external
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 == ""
github conda / conda / tests / test_info.py View on Github external
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)
github conda / conda / tests / test_config.py View on Github external
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
github conda / conda / tests / cli / test_config.py View on Github external
--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 == ""
github conda / conda / tests / cli / test_main_info.py View on Github external
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"])
github conda / conda / tests / cli / test_config.py View on Github external
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']}
github conda / conda / tests / cli / test_config.py View on Github external
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 == ""
github microsoft / PTVS / Python / Product / Miniconda / Miniconda3-x64 / Lib / _nsis.py View on Github external
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"]
github cctbx / cctbx_project / libtbx / pkg_utils.py View on Github external
"management by convention, see https://github.com/cctbx/cctbx_project/issues/151", "",
            "Please update the following packages manually:",
            "  {action_list}",
            action_list=", ".join(action_list))
    return

  if os.getenv('LIBTBX_DISABLE_UPDATES') and os.getenv('LIBTBX_DISABLE_UPDATES').strip() not in ('0', ''):
    _notice("    WARNING: Can not automatically update conda environment", "",
            "Environment variable LIBTBX_DISABLE_UPDATES is set.",
            "Please update the following packages manually:",
            "  {action_list}",
            action_list=", ".join(action_list))
    return

  print("\nUpdating conda environment for packages:" + "".join("\n - " + a for a in action_list) + "\n")
  _, _, return_code = conda.cli.python_api.run_command(
    conda.cli.python_api.Commands.INSTALL,
    *action_list,
    stdout=None,
    stderr=None,
    use_exception_handler=True
  )
  if return_code:
    _notice("    WARNING: Could not automatically update conda environment", "",
            "Please check your environment manually.")