How to use the conda.common.compat.text_type 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_install.py View on Github external
def test_yield_lines(tmpdir):
    tempfile = join(text_type(tmpdir), "testfile")
    _make_lines_file(tempfile)
    lines = list(yield_lines(tempfile))
    assert lines == ['line 1', 'line 2', 'line 4']
github conda / conda / conda / cli / activate.py View on Github external
from ..exceptions import ArgumentError
            raise ArgumentError("Invalid arguments to checkenv.  Need shell and env name/path")
        if len(sys_argv) > 4:
            from ..exceptions import ArgumentError
            raise ArgumentError("did not expect more than one argument.")
        if sys_argv[3].lower() == ROOT_ENV_NAME.lower():
            # no need to check root env and try to install a symlink there
            sys.exit(0)
            # raise CondaSystemExit

        # this should throw an error and exit if the env or path can't be found.
        try:
            prefix_from_arg(sys_argv[3], shell)
        except ValueError as e:
            from ..exceptions import CondaValueError
            raise CondaValueError(text_type(e))

        # # Make sure an env always has the conda symlink
        # try:
        #     from conda.base.context import context
        #     import conda.install
        #     conda.install.symlink_conda(prefix, context.root_prefix, shell)
        # except (IOError, OSError) as e:
        #     if e.errno == errno.EPERM or e.errno == errno.EACCES:
        #         msg = ("Cannot activate environment {0}.\n"
        #                "User does not have write access for conda symlinks."
        #                .format(sys.argv[2]))
        #         raise CondaEnvironmentError(msg)
        #     raise

        sys.exit(0)
        # raise CondaSystemExit
github conda / conda / conda / __init__.py View on Github external
def __str__(self):
        return '\n'.join(text_type(e) for e in self.errors) + '\n'
github conda / conda / conda / cli / main_search.py View on Github external
with Spinner("Loading channels", not context.verbosity and not context.quiet, context.json):
        spec_channel = spec.get_exact_value('channel')
        channel_urls = (spec_channel,) if spec_channel else context.channels

        matches = sorted(SubdirData.query_all(spec, channel_urls, subdirs),
                         key=lambda rec: (rec.name, VersionOrder(rec.version), rec.build))

    if not matches:
        channels_urls = tuple(calculate_channel_urls(
            channel_urls=context.channels,
            prepend=not args.override_channels,
            platform=subdirs[0],
            use_local=args.use_local,
        ))
        from ..exceptions import PackagesNotFoundError
        raise PackagesNotFoundError((text_type(spec),), channels_urls)

    if context.json:
        json_obj = defaultdict(list)
        for match in matches:
            json_obj[match.name].append(match)
        stdout_json(json_obj)

    elif args.info:
        for record in matches:
            pretty_record(record)

    else:
        builder = ['# %-13s %15s %15s  %-20s' % (
            "Name",
            "Version",
            "Build",
github conda / conda / conda / common / configuration.py View on Github external
def __repr__(self):
        return text_type(vars(self))
github conda / conda / conda / core / package_cache.py View on Github external
def all_writable(cls, pkgs_dirs=None):
        if pkgs_dirs is None:
            pkgs_dirs = context.pkgs_dirs
        writable_caches = tuple(filter(lambda c: c.is_writable,
                                       (PackageCache(pd) for pd in pkgs_dirs)))
        if not writable_caches:
            # TODO: raise NoWritablePackageCacheError()
            raise CondaError("No writable package cache directories found in\n"
                             "%s" % text_type(context.pkgs_dirs))
        return writable_caches
github conda / conda / conda / models / version.py View on Github external
def __new__(cls, spec):
        if isinstance(spec, cls):
            return spec

        self = object.__new__(cls)
        try:
            spec = int(spec)
        except ValueError:
            pass
        else:
            self.spec = spec
            self.match = self.exact_match_
            return self

        _spec = spec
        self.spec = spec = text_type(spec).strip()
        if spec == '*':
            self.match = self.triv_match_
        elif spec.startswith(('=', '<', '>', '!')):
            m = version_relation_re.match(spec)
            if m is None:
                raise InvalidVersionSpecError(spec)
            op, b = m.groups()
            self.op = opdict[op]
            self.cmp = VersionOrder(b)
            self.match = self.veval_match_
        elif spec.startswith('^') or spec.endswith('$'):
            if not spec.startswith('^') or not spec.endswith('$'):
                raise InvalidVersionSpecError(spec)
            self.regex = re.compile(spec)
            self.match = self.regex_match_
        elif hasattr(spec, 'match'):
github conda / conda / conda / __init__.py View on Github external
def __str__(self):
        try:
            return text_type(self.message % self._kwargs)
        except:
            debug_message = "\n".join((
                "class: " + self.__class__.__name__,
                "message:",
                self.message,
                "kwargs:",
                text_type(self._kwargs),
                "",
            ))
            print(debug_message, file=sys.stderr)
            raise
github conda / conda / conda / models / match_spec.py View on Github external
def __str__(self):
        builder = []
        brackets = []

        channel_matcher = self._match_components.get('channel')
        if channel_matcher and channel_matcher.exact_value:
            builder.append(text_type(channel_matcher))
        elif channel_matcher and not channel_matcher.matches_all:
            brackets.append("channel=%s" % text_type(channel_matcher))

        subdir_matcher = self._match_components.get('subdir')
        if subdir_matcher:
            if channel_matcher and channel_matcher.exact_value:
                builder.append('/%s' % subdir_matcher)
            else:
                brackets.append("subdir=%s" % subdir_matcher)

        name_matcher = self._match_components.get('name', '*')
        builder.append(('::%s' if builder else '%s') % name_matcher)

        version_exact = False
        version = self._match_components.get('version')
        if version:
            version = text_type(version)
            if any(s in version for s in '><$^|,'):
github conda / conda / conda / models / version.py View on Github external
def __repr__(self):
        # return "BuildNumberSpec('%s')" % self.spec
        return text_type(self.spec)