Exemplo n.º 1
0
def install(
    conda,
    mamba,
    micromamba,
    prefix,
    name,
    lock_file,
    auth,
    auth_file,
    validate_platform,
    log_level,
    dev,
    extras,
):
    """Perform a conda install"""
    logging.basicConfig(level=log_level)
    auth = json.loads(auth) if auth else read_json(
        auth_file) if auth_file else None
    _conda_exe = determine_conda_executable(conda,
                                            mamba=mamba,
                                            micromamba=micromamba)
    install_func = partial(do_conda_install,
                           conda=_conda_exe,
                           prefix=prefix,
                           name=name)
    if validate_platform and not lock_file.endswith(DEFAULT_LOCKFILE_NAME):
        lockfile = read_file(lock_file)
        try:
            do_validate_platform(lockfile)
        except PlatformValidationError as error:
            raise PlatformValidationError(
                error.args[0] +
                " Disable validation with `--no-validate-platform`.")
    with _render_lockfile_for_install(lock_file,
                                      include_dev_dependencies=dev,
                                      extras=extras) as lockfile:
        if auth:
            with _add_auth(read_file(lockfile), auth) as lockfile_with_auth:
                install_func(file=lockfile_with_auth)
        else:
            install_func(file=lockfile)
Exemplo n.º 2
0
def install(conda, mamba, micromamba, prefix, name, lock_file, auth_file):
    """Perform a conda install"""
    auth = read_json(auth_file) if auth_file else None
    _conda_exe = determine_conda_executable(conda,
                                            mamba=mamba,
                                            micromamba=micromamba)
    install_func = partial(do_conda_install,
                           conda=_conda_exe,
                           prefix=prefix,
                           name=name)
    if auth:
        lockfile = read_file(lock_file)
        with _add_auth(lockfile, auth) as lockfile_with_auth:
            install_func(file=lockfile_with_auth)
    else:
        install_func(file=lock_file)
Exemplo n.º 3
0
def lock(
    conda,
    mamba,
    micromamba,
    platform,
    channel_overrides,
    dev_dependencies,
    files,
    filename_template,
    strip_auth,
):
    """Generate fully reproducible lock files for conda environments.

    By default, the lock files are written to conda-{platform}.lock. These filenames can be customized using the
    --filename-template argument. The following tokens are available:

    \b
        platform: The platform this lock file was generated for (conda subdir).
        dev-dependencies: Whether or not dev dependencies are included in this lock file.
        spec-hash: A sha256 hash of the lock file spec.
        version: The version of conda-lock used to generate this lock file.
        timestamp: The approximate timestamp of the output file in ISO8601 basic format.
    """
    files = [pathlib.Path(file) for file in files]
    lock_func = partial(
        run_lock,
        environment_files=files,
        conda_exe=conda,
        platforms=platform,
        mamba=mamba,
        micromamba=micromamba,
        include_dev_dependencies=dev_dependencies,
        channel_overrides=channel_overrides,
    )
    if strip_auth:
        with tempfile.TemporaryDirectory() as tempdir:
            filename_template_temp = f"{tempdir}/{filename_template.split('/')[-1]}"
            lock_func(filename_template=filename_template_temp)
            filename_template_dir = "/".join(filename_template.split("/")[:-1])
            for file in os.listdir(tempdir):
                lockfile = read_file(os.path.join(tempdir, file))
                lockfile = _strip_auth_from_lockfile(lockfile)
                write_file(lockfile, os.path.join(filename_template_dir, file))
    else:
        lock_func(filename_template=filename_template)
Exemplo n.º 4
0
def lock(
    conda,
    mamba,
    micromamba,
    platform,
    channel_overrides,
    dev_dependencies,
    files,
    kind,
    filename_template,
    lockfile,
    strip_auth,
    extras,
    check_input_hash: bool,
    log_level,
    pdb,
    virtual_package_spec,
    update=None,
):
    """Generate fully reproducible lock files for conda environments.

    By default, the lock files are written to conda-{platform}.lock. These filenames can be customized using the
    --filename-template argument. The following tokens are available:

    \b
        platform: The platform this lock file was generated for (conda subdir).
        dev-dependencies: Whether or not dev dependencies are included in this lock file.
        input-hash: A sha256 hash of the lock file input specification.
        version: The version of conda-lock used to generate this lock file.
        timestamp: The approximate timestamp of the output file in ISO8601 basic format.
    """
    logging.basicConfig(level=log_level)

    if pdb:

        def handle_exception(exc_type, exc_value, exc_traceback):
            import pdb

            pdb.post_mortem(exc_traceback)

        sys.excepthook = handle_exception

    if not virtual_package_spec:
        candidates = [
            pathlib.Path("virtual-packages.yml"),
            pathlib.Path("virtual-packages.yaml"),
        ]
        for c in candidates:
            if c.exists():
                logger.info("Using virtual packages from %s", c)
                virtual_package_spec = c
                break
    else:
        virtual_package_spec = pathlib.Path(virtual_package_spec)

    files = [pathlib.Path(file) for file in files]
    extras = set(extras)
    lock_func = partial(
        run_lock,
        environment_files=files,
        conda_exe=conda,
        platforms=platform,
        mamba=mamba,
        micromamba=micromamba,
        include_dev_dependencies=dev_dependencies,
        channel_overrides=channel_overrides,
        kinds=kind,
        lockfile_path=pathlib.Path(lockfile),
        extras=extras,
        virtual_package_spec=virtual_package_spec,
        update=update,
    )
    if strip_auth:
        with tempfile.TemporaryDirectory() as tempdir:
            filename_template_temp = f"{tempdir}/{filename_template.split('/')[-1]}"
            lock_func(filename_template=filename_template_temp)
            filename_template_dir = "/".join(filename_template.split("/")[:-1])
            for file in os.listdir(tempdir):
                lockfile = read_file(os.path.join(tempdir, file))
                lockfile = _strip_auth_from_lockfile(lockfile)
                write_file(lockfile, os.path.join(filename_template_dir, file))
    else:
        lock_func(filename_template=filename_template,
                  check_input_hash=check_input_hash)