Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def from_url(cls, url):
assert is_url(url), url
if not url.endswith(CONDA_TARBALL_EXTENSION) and '::' not in url:
raise CondaError("url '%s' is not a conda package" % url)
dist_details = cls.parse_dist_name(url)
if '::' in url:
url_no_tarball = url.rsplit('::', 1)[0]
platform = context.subdir
base_url = url_no_tarball.split('::')[0]
channel = text_type(Channel(base_url))
else:
url_no_tarball = url.rsplit('/', 1)[0]
platform = has_platform(url_no_tarball, context.known_subdirs)
base_url = url_no_tarball.rsplit('/', 1)[0] if platform else url_no_tarball
channel = Channel(base_url).canonical_name if platform else UNKNOWN_CHANNEL
return cls(channel=channel,
name=dist_details.name,
version=dist_details.version,
from ._vendor.auxlib.logz import stringify
response_details = (stringify(response) or '') if response else ''
url = maybe_unquote(url)
if isinstance(elapsed_time, timedelta):
elapsed_time = text_type(elapsed_time).split(':', 1)[-1]
if isinstance(reason, string_types):
reason = reason.upper()
super(CondaHTTPError, self).__init__(message, url=url, status_code=status_code,
reason=reason, elapsed_time=elapsed_time,
response_details=response_details,
caused_by=caused_by)
class CondaRevisionError(CondaError):
def __init__(self, message):
msg = "%s." % message
super(CondaRevisionError, self).__init__(msg)
class AuthenticationError(CondaError):
pass
class PackageNotFoundError(CondaError):
def __init__(self, bad_pkg, channel_urls=()):
from .resolve import dashlist
channels = dashlist(channel_urls)
if not channel_urls:
# -*- coding: utf-8 -*-
# Copyright (C) 2012 Anaconda, Inc
# SPDX-License-Identifier: BSD-3-Clause
from conda import CondaError
class CondaEnvException(CondaError):
def __init__(self, message, *args, **kwargs):
msg = "%s" % message
super(CondaEnvException, self).__init__(msg, *args, **kwargs)
class EnvironmentFileNotFound(CondaEnvException):
def __init__(self, filename, *args, **kwargs):
msg = "'{}' file not found".format(filename)
self.filename = filename
super(EnvironmentFileNotFound, self).__init__(msg, *args, **kwargs)
class EnvironmentFileExtensionNotValid(CondaEnvException):
def __init__(self, filename, *args, **kwargs):
msg = "'{}' file extension must be one of '.txt', '.yaml' or '.yml'".format(filename)
self.filename = filename
super(CondaIndexError, self).__init__(msg)
class CondaValueError(CondaError, ValueError):
def __init__(self, message, *args):
msg = '%s' % message
super(CondaValueError, self).__init__(msg)
class CondaTypeError(CondaError, TypeError):
def __init__(self, expected_type, received_type, optional_message):
msg = "Expected type '%s' and got type '%s'. %s"
super(CondaTypeError, self).__init__(msg)
class CondaHistoryError(CondaError):
def __init__(self, message):
msg = '%s' % message
super(CondaHistoryError, self).__init__(msg)
class CondaUpgradeError(CondaError):
def __init__(self, message):
msg = "%s" % message
super(CondaUpgradeError, self).__init__(msg)
class CondaVerificationError(CondaError):
def __init__(self, message):
super(CondaVerificationError, self).__init__(message)
solution = tuple(dist for dist in solution if dist not in inconsistent_dists)
# For the remaining specs in specs_map, add target to each spec. `target` is a reference
# to the package currently existing in the environment. Setting target instructs the
# solver to not disturb that package if it's not necessary.
# If the spec.name is being modified by inclusion in specs_to_add, we don't set `target`,
# since we *want* the solver to modify/update that package.
#
# TLDR: when working with MatchSpec objects,
# - to minimize the version change, set MatchSpec(name=name, target=dist.full_name)
# - to freeze the package, set all the components of MatchSpec individually
for pkg_name, spec in iteritems(specs_map):
matches_for_spec = tuple(dist for dist in solution if spec.match(index[dist]))
if matches_for_spec:
if len(matches_for_spec) != 1:
raise CondaError(dals("""
Conda encountered an error with your environment. Please report an issue
at https://github.com/conda/conda/issues/new. In your report, please include
the output of 'conda info' and 'conda list' for the active environment, along
with the command you invoked that resulted in this error.
pkg_name: %s
spec: %s
matches_for_spec: %s
""") % (pkg_name, spec,
dashlist((text_type(s) for s in matches_for_spec), indent=4)))
target_dist = matches_for_spec[0]
if deps_modifier == DepsModifier.FREEZE_INSTALLED:
new_spec = MatchSpec(index[target_dist])
else:
target = Dist(target_dist).full_name
new_spec = MatchSpec(spec, target=target)
specs_map[pkg_name] = new_spec
class CondaEnvException(CondaError):
def __init__(self, message, *args, **kwargs):
msg = "Conda Env Exception: %s" % message
super(CondaEnvException, self).__init__(msg, *args, **kwargs)
class EnvironmentFileNotFound(CondaEnvException):
def __init__(self, filename, *args, **kwargs):
msg = '{} file not found'.format(filename)
self.filename = filename
super(EnvironmentFileNotFound, self).__init__(msg, *args, **kwargs)
class NoBinstar(CondaError):
def __init__(self):
msg = 'The anaconda-client cli must be installed to perform this action'
super(NoBinstar, self).__init__(msg)
class AlreadyExist(CondaError):
def __init__(self):
msg = 'The environment path already exists'
super(AlreadyExist, self).__init__(msg)
class EnvironmentAlreadyInNotebook(CondaError):
def __init__(self, notebook, *args, **kwargs):
msg = "The notebook {} already has an environment"
super(EnvironmentAlreadyInNotebook, self).__init__(msg, *args, **kwargs)
super(NoBinstar, self).__init__(msg)
class AlreadyExist(CondaError):
def __init__(self):
msg = 'The environment path already exists'
super(AlreadyExist, self).__init__(msg)
class EnvironmentAlreadyInNotebook(CondaError):
def __init__(self, notebook, *args, **kwargs):
msg = "The notebook {} already has an environment"
super(EnvironmentAlreadyInNotebook, self).__init__(msg, *args, **kwargs)
class EnvironmentFileDoesNotExist(CondaError):
def __init__(self, handle, *args, **kwargs):
self.handle = handle
msg = "{} does not have an environment definition".format(handle)
super(EnvironmentFileDoesNotExist, self).__init__(msg, *args, **kwargs)
class EnvironmentFileNotDownloaded(CondaError):
def __init__(self, username, packagename, *args, **kwargs):
msg = '{}/{} file not downloaded'.format(username, packagename)
self.username = username
self.packagename = packagename
super(EnvironmentFileNotDownloaded, self).__init__(msg, *args, **kwargs)
class SpecNotFound(CondaError):
def __init__(self, msg, *args, **kwargs):
super(CondaKeyError, self).__init__(self.msg, *args)
class ChannelError(CondaError):
def __init__(self, message, *args):
msg = '%s' % message
super(ChannelError, self).__init__(msg)
class ChannelNotAllowed(ChannelError):
def __init__(self, message, *args):
msg = '%s' % message
super(ChannelNotAllowed, self).__init__(msg, *args)
class OperationNotAllowed(CondaError):
def __init__(self, message):
super(OperationNotAllowed, self).__init__(message)
class CondaImportError(CondaError, ImportError):
def __init__(self, message):
msg = '%s' % message
super(CondaImportError, self).__init__(msg)
class ParseError(CondaError):
def __init__(self, message):
msg = '%s' % message
super(ParseError, self).__init__(msg)
super(ChannelError, self).__init__(msg)
class ChannelNotAllowed(ChannelError):
def __init__(self, message, *args):
msg = '%s' % message
super(ChannelNotAllowed, self).__init__(msg, *args)
class OperationNotAllowed(CondaError):
def __init__(self, message):
super(OperationNotAllowed, self).__init__(message)
class CondaImportError(CondaError, ImportError):
def __init__(self, message):
msg = '%s' % message
super(CondaImportError, self).__init__(msg)
class ParseError(CondaError):
def __init__(self, message):
msg = '%s' % message
super(ParseError, self).__init__(msg)
class CouldntParseError(ParseError):
def __init__(self, reason):
self.reason = reason
super(CouldntParseError, self).__init__(self.args[0])
self.packagename = packagename
super(EnvironmentFileNotDownloaded, self).__init__(msg, *args, **kwargs)
class SpecNotFound(CondaError):
def __init__(self, msg, *args, **kwargs):
super(SpecNotFound, self).__init__(msg, *args, **kwargs)
class InvalidLoader(Exception):
def __init__(self, name):
msg = 'Unable to load installer for {}'.format(name)
super(InvalidLoader, self).__init__(msg)
class NBFormatNotInstalled(CondaError):
def __init__(self):
msg = """nbformat is not installed. Install it with:
conda install nbformat
"""
super(NBFormatNotInstalled, self).__init__(msg)