Beispiel #1
0
 def local_build_root(self):
     if self.bld_path:
         return expand(self.bld_path)
     elif self.root_writable:
         return join(self.root_dir, "conda-bld")
     else:
         return expand("~/conda-bld")
Beispiel #2
0
 def local_build_root(self):
     if self.bld_path:
         return expand(self.bld_path)
     elif self.root_writable:
         return join(self.root_dir, 'conda-bld')
     else:
         return expand('~/conda-bld')
Beispiel #3
0
def touch(path):
    path = expand(path)
    log.trace("touching path %s", path)
    if lexists(path):
        utime(path, None)
    else:
        open(path, 'a').close()
Beispiel #4
0
def get_filename(filename):
    """Expand filename if local path or return the url"""
    url_scheme = filename.split("://", 1)[0]
    if url_scheme in CONDA_SESSION_SCHEMES:
        return filename
    else:
        return expand(filename)
Beispiel #5
0
def execute(args, parser):
    name = args.remote_definition or args.name

    try:
        spec = install_specs.detect(name=name,
                                    filename=expand(args.file),
                                    directory=os.getcwd())
        env = spec.environment
    except exceptions.SpecNotFound:
        raise

    if not (args.name or args.prefix):
        if not env.name:
            # Note, this is a hack fofr get_prefix that assumes argparse results
            # TODO Refactor common.get_prefix
            name = os.environ.get('CONDA_DEFAULT_ENV', False)
            if not name:
                msg = "Unable to determine environment\n\n"
                msg += textwrap.dedent("""
                    Please re-run this command with one of the following options:

                    * Provide an environment name via --name or -n
                    * Re-run this command inside an activated conda environment."""
                                       ).lstrip()
                # TODO Add json support
                raise CondaEnvException(msg)

        # Note: stubbing out the args object as all of the
        # conda.cli.common code thinks that name will always
        # be specified.
        args.name = env.name

    prefix = get_prefix(args, search=False)
    # CAN'T Check with this function since it assumes we will create prefix.
    # cli_install.check_prefix(prefix, json=args.json)

    # TODO, add capability
    # common.ensure_override_channels_requires_channel(args)
    # channel_urls = args.channel or ()

    for installer_type, specs in env.dependencies.items():
        try:
            installer = get_installer(installer_type)
            installer.install(prefix, specs, args, env, prune=args.prune)
        except InvalidInstaller:
            sys.stderr.write(
                textwrap.dedent("""
                Unable to install package for {0}.

                Please double check and ensure you dependencies file has
                the correct spelling.  You might also try installing the
                conda-env-{0} package to see if provides the required
                installer.
                """).lstrip().format(installer_type))
            return -1

    touch_nonadmin(prefix)
    if not args.json:
        print(cli_install.print_activate(args.name if args.name else prefix))
def execute(args, parser):
    from conda.base.context import context
    name = args.remote_definition or args.name

    try:
        spec = specs.detect(name=name,
                            filename=expand(args.file),
                            directory=os.getcwd())
        env = spec.environment

        # FIXME conda code currently requires args to have a name or prefix
        # don't overwrite name if it's given. gh-254
        if args.prefix is None and args.name is None:
            args.name = env.name

    except exceptions.SpecNotFound:
        raise

    prefix = get_prefix(args, search=False)

    if args.force and prefix != context.root_prefix and os.path.exists(prefix):
        rm_rf(prefix)
    cli_install.check_prefix(prefix, json=args.json)

    # TODO, add capability
    # common.ensure_override_channels_requires_channel(args)
    # channel_urls = args.channel or ()

    result = {"conda": None, "pip": None}
    if len(env.dependencies.items()) == 0:
        installer_type = "conda"
        pkg_specs = []
        installer = get_installer(installer_type)
        result[installer_type] = installer.install(prefix, pkg_specs, args,
                                                   env)
    else:
        for installer_type, pkg_specs in env.dependencies.items():
            try:
                installer = get_installer(installer_type)
                result[installer_type] = installer.install(
                    prefix, pkg_specs, args, env)
            except InvalidInstaller:
                sys.stderr.write(
                    textwrap.dedent("""
                    Unable to install package for {0}.

                    Please double check and ensure your dependencies file has
                    the correct spelling.  You might also try installing the
                    conda-env-{0} package to see if provides the required
                    installer.
                    """).lstrip().format(installer_type))
                return -1

    touch_nonadmin(prefix)
    print_result(args, prefix, result)
Beispiel #7
0
def touch(path):
    # returns
    #   True if the file did not exist but was created
    #   False if the file already existed
    path = expand(path)
    log.trace("touching path %s", path)
    if lexists(path):
        utime(path, None)
        return True
    else:
        open(path, 'a').close()
        return False
Beispiel #8
0
def execute(args, parser):
    from conda.base.context import context
    name = args.remote_definition or args.name

    try:
        spec = specs.detect(name=name, filename=expand(args.file),
                            directory=os.getcwd())
        env = spec.environment

        # FIXME conda code currently requires args to have a name or prefix
        # don't overwrite name if it's given. gh-254
        if args.prefix is None and args.name is None:
            args.name = env.name

    except exceptions.SpecNotFound:
        raise

    prefix = get_prefix(args, search=False)

    if args.force and prefix != context.root_prefix and os.path.exists(prefix):
        rm_rf(prefix)
    cli_install.check_prefix(prefix, json=args.json)

    # TODO, add capability
    # common.ensure_override_channels_requires_channel(args)
    # channel_urls = args.channel or ()

    # # special case for empty environment
    # if not env.dependencies:
    #     from conda.install import symlink_conda
    #     symlink_conda(prefix, context.root_dir)

    for installer_type, pkg_specs in env.dependencies.items():
        try:
            installer = get_installer(installer_type)
            installer.install(prefix, pkg_specs, args, env)
        except InvalidInstaller:
            sys.stderr.write(textwrap.dedent("""
                Unable to install package for {0}.

                Please double check and ensure your dependencies file has
                the correct spelling.  You might also try installing the
                conda-env-{0} package to see if provides the required
                installer.
                """).lstrip().format(installer_type)
            )
            return -1

    touch_nonadmin(prefix)
    delete_trash()
    if not args.json:
        cli_install.print_activate(args.name if args.name else prefix)
Beispiel #9
0
def execute(args, parser):
    name = args.remote_definition or args.name

    try:
        spec = install_specs.detect(name=name, filename=expand(args.file),
                                    directory=os.getcwd())
        env = spec.environment
    except exceptions.SpecNotFound:
        raise

    if not (args.name or args.prefix):
        if not env.name:
                    # Note, this is a hack fofr get_prefix that assumes argparse results
            # TODO Refactor common.get_prefix
            name = os.environ.get('CONDA_DEFAULT_ENV', False)
            if not name:
                msg = "Unable to determine environment\n\n"
                msg += textwrap.dedent("""
                    Please re-run this command with one of the following options:

                    * Provide an environment name via --name or -n
                    * Re-run this command inside an activated conda environment.""").lstrip()
                # TODO Add json support
                raise CondaEnvException(msg)

        # Note: stubbing out the args object as all of the
        # conda.cli.common code thinks that name will always
        # be specified.
        args.name = env.name

    prefix = get_prefix(args, search=False)
    # CAN'T Check with this function since it assumes we will create prefix.
    # cli_install.check_prefix(prefix, json=args.json)

    # TODO, add capability
    # common.ensure_override_channels_requires_channel(args)
    # channel_urls = args.channel or ()

    # create installers before running any of them
    # to avoid failure to import after the file being deleted
    # e.g. due to conda_env being upgraded or Python version switched.
    installers = {}

    for installer_type in env.dependencies:
        try:
            installers[installer_type] = get_installer(installer_type)
        except InvalidInstaller as e:
            sys.stderr.write(textwrap.dedent("""
                Unable to install package for {0}.

                Please double check and ensure you dependencies file has
                the correct spelling.  You might also try installing the
                conda-env-{0} package to see if provides the required
                installer.
                """).lstrip().format(installer_type)
            )
            return -1

    for installer_type, specs in env.dependencies.items():
        installer = installers[installer_type]
        installer.install(prefix, specs, args, env)

    touch_nonadmin(prefix)
    cli_install.print_activate(args.name if args.name else prefix)
Beispiel #10
0
 def test_local_build_root_default_rc(self):
     if context.root_writable:
         assert context.local_build_root == join(context.root_prefix,
                                                 'conda-bld')
     else:
         assert context.local_build_root == expand('~/conda-bld')