def test_resolve_dependencies_for_bogus_package_with_actual_conda(): with pytest.raises(conda_api.CondaError) as excinfo: conda_api.resolve_dependencies(['doesnotexistblahblah']) if hasattr(excinfo.value, 'json'): pprint(excinfo.value.json) exc_str = str(excinfo.value) assert 'Package not found' in exc_str or 'Package missing' in exc_str
def test_resolve_dependencies_for_bogus_package_with_actual_conda(): with pytest.raises(conda_api.CondaError) as excinfo: conda_api.resolve_dependencies(['doesnotexistblahblah']) if hasattr(excinfo.value, 'json'): pprint(excinfo.value.json) exc_str = str(excinfo.value) valid_strings = ('Package not found', 'Package missing', 'Packages missing', 'packages are not available') assert any(s in exc_str for s in valid_strings)
def test_resolve_dependencies_no_link_op(monkeypatch): def mock_call_conda(extra_args, json_mode, platform=None, stdout_callback=None, stderr_callback=None): return json.dumps({'actions': [{'SOMETHING': {}}]}) monkeypatch.setattr('anaconda_project.internal.conda_api._call_conda', mock_call_conda) with pytest.raises(conda_api.CondaError) as excinfo: conda_api.resolve_dependencies(['foo=1.0']) assert 'Could not understand JSON from Conda' in str(excinfo.value)
def test_resolve_dependencies_pass_through_channels(monkeypatch): def mock_call_conda(extra_args, json_mode, platform=None, stdout_callback=None, stderr_callback=None): assert '--channel' in extra_args assert 'abc' in extra_args assert 'nbc' in extra_args return json.dumps({ 'actions': [{ 'LINK': [{ 'base_url': None, 'build_number': 0, 'build_string': '0', 'channel': 'defaults', 'dist_name': 'mkl-2017.0.1-0', 'name': 'mkl', 'platform': None, 'version': '2017.0.1', 'with_features_depends': None }] }] }) monkeypatch.setattr('anaconda_project.internal.conda_api._call_conda', mock_call_conda) result = conda_api.resolve_dependencies(['foo=1.0'], channels=['abc', 'nbc']) assert [('mkl', '2017.0.1', '0')] == result
def resolve_dependencies(self, package_specs, channels, platforms): by_platform = {} current = conda_api.current_platform() resolve_for_platforms = list(platforms) # always resolve "current" first because it's confusing if # an error says resolution failed on another platform when # the real issue is that resolution will fail on all platforms. if current in resolve_for_platforms: resolve_for_platforms.remove(current) resolve_for_platforms = [current] + resolve_for_platforms for conda_platform in resolve_for_platforms: try: self._log_info("Resolving conda packages for %s" % conda_platform) deps = conda_api.resolve_dependencies(pkgs=package_specs, platform=conda_platform, channels=channels) except conda_api.CondaError as e: raise CondaManagerError("Error resolving for {}: {}".format( conda_platform, str(e))) locked_specs = ["%s=%s=%s" % dep for dep in deps] by_platform[conda_platform] = sorted(locked_specs) by_platform = _extract_common(by_platform) lock_set = CondaLockSet(package_specs_by_platform=by_platform, platforms=resolve_for_platforms) return lock_set
def test_resolve_dependencies_with_actual_conda_depending_on_conda(): try: result = conda_api.resolve_dependencies(['conda=4.3.21'], platform=None) except conda_api.CondaError as e: pprint(e.json) raise e names = [pkg[0] for pkg in result] assert 'conda' in names names_and_versions = [(pkg[0], pkg[1]) for pkg in result] assert ('conda', '4.3.21') in names_and_versions assert len(result) > 1 # conda has some dependencies so should be >1
def test_resolve_dependencies_with_actual_conda_current_platform(): try: result = conda_api.resolve_dependencies(['bokeh=0.12.4'], platform=None) except conda_api.CondaError as e: pprint(e.json) raise e names = [pkg[0] for pkg in result] assert 'bokeh' in names names_and_versions = [(pkg[0], pkg[1]) for pkg in result] assert ('bokeh', '0.12.4') in names_and_versions assert len(result) > 1 # bokeh has some dependencies so should be >1
def test_resolve_msys2_dependencies_with_actual_conda(p): try: result = conda_api.resolve_dependencies( ['m2-msys2-runtime=2.5.0.17080.65c939c'], platform=p) except conda_api.CondaError as e: print("*** Dependency resolution failed on %s" % p) pprint(e.json) raise e names = [pkg[0] for pkg in result] assert 'm2-msys2-runtime' in names names_and_versions = [(pkg[0], pkg[1]) for pkg in result] assert ('m2-msys2-runtime', '2.5.0.17080.65c939c') in names_and_versions assert len(result) > 1 # requests has some dependencies so should be >1 print("Dependency resolution test OK on %s" % p)
def test_resolve_dependencies_ignores_rmtree_failure(monkeypatch): def mock_call_conda(extra_args, json_mode, platform, stdout_callback=None, stderr_callback=None): return json.dumps({ 'actions': [{ 'LINK': [{ 'base_url': None, 'build_number': 0, 'build_string': '0', 'channel': 'defaults', 'dist_name': 'mkl-2017.0.1-0', 'name': 'mkl', 'platform': None, 'version': '2017.0.1', 'with_features_depends': None }] }] }) monkeypatch.setattr('anaconda_project.internal.conda_api._call_conda', mock_call_conda) def mock_isdir(*args, **kwargs): return True monkeypatch.setattr('os.path.isdir', mock_isdir) called = dict() def mock_rmtree(*args, **kwargs): called['yes'] = True raise Exception("did not rm the tree") monkeypatch.setattr('shutil.rmtree', mock_rmtree) result = conda_api.resolve_dependencies(['foo=1.0']) assert 'yes' in called assert [('mkl', '2017.0.1', '0')] == result
def test_resolve_dependencies_with_actual_conda_other_platforms(): for p in conda_api.default_platforms_plus_32_bit: if p == conda_api.current_platform(): print( "Skipping dependency resolution test on current platform %s" % p) continue try: result = conda_api.resolve_dependencies(['bokeh=0.12.4'], platform=p) except conda_api.CondaError as e: print("*** Dependency resolution failed on %s" % p) pprint(e.json) raise e names = [pkg[0] for pkg in result] assert 'bokeh' in names names_and_versions = [(pkg[0], pkg[1]) for pkg in result] assert ('bokeh', '0.12.4') in names_and_versions assert len(result) > 1 # bokeh has some dependencies so should be >1 print("Dependency resolution test OK on %s" % p)
def test_resolve_dependencies_with_conda_43_json(monkeypatch): def mock_call_conda(extra_args, json_mode, platform=None, stdout_callback=None, stderr_callback=None): old_json = { 'actions': [{ 'LINK': [{ 'base_url': None, 'build_number': 0, 'build_string': '0', 'channel': 'defaults', 'dist_name': 'mkl-2017.0.1-0', 'name': 'mkl', 'platform': None, 'version': '2017.0.1', 'with_features_depends': None }, { 'base_url': None, 'build_number': 1, 'build_string': '1', 'channel': 'defaults', 'dist_name': 'openssl-1.0.2k-1', 'name': 'openssl', 'platform': None, 'version': '1.0.2k', 'with_features_depends': None }, { 'base_url': None, 'build_number': 2, 'build_string': '2', 'channel': 'defaults', 'dist_name': 'readline-6.2-2', 'name': 'readline', 'platform': None, 'version': '6.2', 'with_features_depends': None }, { 'base_url': None, 'build_number': 0, 'build_string': '0', 'channel': 'defaults', 'dist_name': 'sqlite-3.13.0-0', 'name': 'sqlite', 'platform': None, 'version': '3.13.0', 'with_features_depends': None }, { 'base_url': None, 'build_number': 0, 'build_string': '0', 'channel': 'defaults', 'dist_name': 'tk-8.5.18-0', 'name': 'tk', 'platform': None, 'version': '8.5.18', 'with_features_depends': None }, { 'base_url': None, 'build_number': 0, 'build_string': '0', 'channel': 'defaults', 'dist_name': 'yaml-0.1.6-0', 'name': 'yaml', 'platform': None, 'version': '0.1.6', 'with_features_depends': None }, { 'base_url': None, 'build_number': 3, 'build_string': '3', 'channel': 'defaults', 'dist_name': 'zlib-1.2.8-3', 'name': 'zlib', 'platform': None, 'version': '1.2.8', 'with_features_depends': None }, { 'base_url': None, 'build_number': 0, 'build_string': '0', 'channel': 'defaults', 'dist_name': 'python-2.7.13-0', 'name': 'python', 'platform': None, 'version': '2.7.13', 'with_features_depends': None }, { 'base_url': None, 'build_number': 0, 'build_string': 'py27_0', 'channel': 'defaults', 'dist_name': 'backports-1.0-py27_0', 'name': 'backports', 'platform': None, 'version': '1.0', 'with_features_depends': None }, { 'base_url': None, 'build_number': 0, 'build_string': 'py27_0', 'channel': 'defaults', 'dist_name': 'backports_abc-0.5-py27_0', 'name': 'backports_abc', 'platform': None, 'version': '0.5', 'with_features_depends': None }, { 'base_url': None, 'build_number': 0, 'build_string': 'py27_0', 'channel': 'defaults', 'dist_name': 'futures-3.0.5-py27_0', 'name': 'futures', 'platform': None, 'version': '3.0.5', 'with_features_depends': None }, { 'base_url': None, 'build_number': 2, 'build_string': 'py27_2', 'channel': 'defaults', 'dist_name': 'markupsafe-0.23-py27_2', 'name': 'markupsafe', 'platform': None, 'version': '0.23', 'with_features_depends': None }, { 'base_url': None, 'build_number': 0, 'build_string': 'py27_0', 'channel': 'defaults', 'dist_name': 'numpy-1.12.0-py27_0', 'name': 'numpy', 'platform': None, 'version': '1.12.0', 'with_features_depends': None }, { 'base_url': None, 'build_number': 0, 'build_string': 'py27_0', 'channel': 'defaults', 'dist_name': 'pyyaml-3.12-py27_0', 'name': 'pyyaml', 'platform': None, 'version': '3.12', 'with_features_depends': None }, { 'base_url': None, 'build_number': 0, 'build_string': 'py27_0', 'channel': 'defaults', 'dist_name': 'requests-2.13.0-py27_0', 'name': 'requests', 'platform': None, 'version': '2.13.0', 'with_features_depends': None }, { 'base_url': None, 'build_number': 0, 'build_string': 'py27_0', 'channel': 'defaults', 'dist_name': 'setuptools-27.2.0-py27_0', 'name': 'setuptools', 'platform': None, 'version': '27.2.0', 'with_features_depends': None }, { 'base_url': None, 'build_number': 0, 'build_string': 'py27_0', 'channel': 'defaults', 'dist_name': 'six-1.10.0-py27_0', 'name': 'six', 'platform': None, 'version': '1.10.0', 'with_features_depends': None }, { 'base_url': None, 'build_number': 0, 'build_string': 'py27_0', 'channel': 'defaults', 'dist_name': 'wheel-0.29.0-py27_0', 'name': 'wheel', 'platform': None, 'version': '0.29.0', 'with_features_depends': None }, { 'base_url': None, 'build_number': 0, 'build_string': 'py27_0', 'channel': 'defaults', 'dist_name': 'jinja2-2.9.5-py27_0', 'name': 'jinja2', 'platform': None, 'version': '2.9.5', 'with_features_depends': None }, { 'base_url': None, 'build_number': 1, 'build_string': 'py27_1', 'channel': 'defaults', 'dist_name': 'pip-9.0.1-py27_1', 'name': 'pip', 'platform': None, 'version': '9.0.1', 'with_features_depends': None }, { 'base_url': None, 'build_number': 0, 'build_string': 'py27_0', 'channel': 'defaults', 'dist_name': 'python-dateutil-2.6.0-py27_0', 'name': 'python-dateutil', 'platform': None, 'version': '2.6.0', 'with_features_depends': None }, { 'base_url': None, 'build_number': 0, 'build_string': 'py27_0', 'channel': 'defaults', 'dist_name': 'singledispatch-3.4.0.3-py27_0', 'name': 'singledispatch', 'platform': None, 'version': '3.4.0.3', 'with_features_depends': None }, { 'base_url': None, 'build_number': 1, 'build_string': 'py27_1', 'channel': 'defaults', 'dist_name': 'ssl_match_hostname-3.4.0.2-py27_1', 'name': 'ssl_match_hostname', 'platform': None, 'version': '3.4.0.2', 'with_features_depends': None }, { 'base_url': None, 'build_number': 0, 'build_string': 'py27_0', 'channel': 'defaults', 'dist_name': 'tornado-4.4.2-py27_0', 'name': 'tornado', 'platform': None, 'version': '4.4.2', 'with_features_depends': None }, { 'base_url': None, 'build_number': 0, 'build_string': 'py27_0', 'channel': 'defaults', 'dist_name': 'bokeh-0.12.4-py27_0', 'name': 'bokeh', 'platform': None, 'version': '0.12.4', 'with_features_depends': None }], 'PREFIX': '/tmp/kapsel_resolve__7_udcjm', 'SYMLINK_CONDA': ['/home/hp/bin/anaconda2'], 'op_order': [ 'CHECK_FETCH', 'RM_FETCHED', 'FETCH', 'CHECK_EXTRACT', 'RM_EXTRACTED', 'EXTRACT', 'UNLINK', 'LINK', 'SYMLINK_CONDA' ] }], 'dry_run': True, 'success': True } return json.dumps(old_json) monkeypatch.setattr('anaconda_project.internal.conda_api._call_conda', mock_call_conda) try: result = conda_api.resolve_dependencies(['bokeh=0.12.4']) except conda_api.CondaError as e: pprint(e.json) raise e names = [pkg[0] for pkg in result] assert 'bokeh' in names names_and_versions = [(pkg[0], pkg[1]) for pkg in result] assert ('bokeh', '0.12.4') in names_and_versions assert len(result) > 1 # bokeh has some dependencies so should be >1
def do_test(dirname): with pytest.raises(TypeError) as excinfo: conda_api.resolve_dependencies(pkgs=[]) assert 'must specify a list' in repr(excinfo.value)
def test_resolve_dependencies_with_conda_41_json(monkeypatch): def mock_call_conda(extra_args, json_mode, platform=None, stdout_callback=None, stderr_callback=None): old_json = { 'actions': { 'EXTRACT': [ 'mkl-2017.0.1-0', 'openssl-1.0.2k-1', 'xz-5.2.2-1', 'python-3.6.0-0', 'markupsafe-0.23-py36_2', 'numpy-1.12.0-py36_0', 'pyyaml-3.12-py36_0', 'requests-2.13.0-py36_0', 'setuptools-27.2.0-py36_0', 'six-1.10.0-py36_0', 'tornado-4.4.2-py36_0', 'wheel-0.29.0-py36_0', 'jinja2-2.9.5-py36_0', 'pip-9.0.1-py36_1', 'python-dateutil-2.6.0-py36_0', 'bokeh-0.12.4-py36_0' ], 'FETCH': [ 'mkl-2017.0.1-0', 'openssl-1.0.2k-1', 'xz-5.2.2-1', 'python-3.6.0-0', 'markupsafe-0.23-py36_2', 'numpy-1.12.0-py36_0', 'pyyaml-3.12-py36_0', 'requests-2.13.0-py36_0', 'setuptools-27.2.0-py36_0', 'six-1.10.0-py36_0', 'tornado-4.4.2-py36_0', 'wheel-0.29.0-py36_0', 'jinja2-2.9.5-py36_0', 'pip-9.0.1-py36_1', 'python-dateutil-2.6.0-py36_0', 'bokeh-0.12.4-py36_0' ], 'LINK': [ 'mkl-2017.0.1-0 2', 'openssl-1.0.2k-1 2', 'readline-6.2-2 2', 'sqlite-3.13.0-0 2', 'tk-8.5.18-0 2', 'xz-5.2.2-1 2', 'yaml-0.1.6-0 2', 'zlib-1.2.8-3 2', 'python-3.6.0-0 2', 'markupsafe-0.23-py36_2 2', 'numpy-1.12.0-py36_0 2', 'pyyaml-3.12-py36_0 2', 'requests-2.13.0-py36_0 2', 'setuptools-27.2.0-py36_0 2', 'six-1.10.0-py36_0 2', 'tornado-4.4.2-py36_0 2', 'wheel-0.29.0-py36_0 2', 'jinja2-2.9.5-py36_0 2', 'pip-9.0.1-py36_1 2', 'python-dateutil-2.6.0-py36_0 2', 'bokeh-0.12.4-py36_0 2' ], 'PREFIX': '/tmp/kapsel_resolve_luiqsjla', 'SYMLINK_CONDA': ['/home/hp/bin/anaconda3_4.1.11'], 'op_order': [ 'RM_FETCHED', 'FETCH', 'RM_EXTRACTED', 'EXTRACT', 'UNLINK', 'LINK', 'SYMLINK_CONDA' ] }, 'dry_run': True, 'success': True } return json.dumps(old_json) monkeypatch.setattr('anaconda_project.internal.conda_api._call_conda', mock_call_conda) try: result = conda_api.resolve_dependencies(['bokeh=0.12.4']) except conda_api.CondaError as e: pprint(e.json) raise e names = [pkg[0] for pkg in result] assert 'bokeh' in names names_and_versions = [(pkg[0], pkg[1]) for pkg in result] assert ('bokeh', '0.12.4') in names_and_versions assert len(result) > 1 # bokeh has some dependencies so should be >1