Skip to content

Commit

Permalink
Merge pull request #547 from maresb/fix-warning
Browse files Browse the repository at this point in the history
Fix warning and increase coverage of install command
  • Loading branch information
maresb authored Nov 13, 2023
2 parents c18d8f2 + fcdadc9 commit b2df9ad
Show file tree
Hide file tree
Showing 4 changed files with 877 additions and 54 deletions.
69 changes: 57 additions & 12 deletions conda_lock/conda_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ def render_lockfile_for_platform( # noqa: C901
extras: Optional[AbstractSet[str]],
kind: Union[Literal["env"], Literal["explicit"]],
platform: str,
suppress_warning_for_pip_and_explicit: bool = False,
) -> List[str]:
"""
Render lock content into a single-platform lockfile that can be installed
Expand All @@ -588,7 +589,9 @@ def render_lockfile_for_platform( # noqa: C901
Lockfile format (explicit or env)
platform :
Target platform
suppress_warning_for_pip_and_explicit :
When rendering internally for `conda-lock install`, we should suppress
the warning about pip dependencies not being supported by all tools.
"""
lockfile_contents = [
"# Generated by conda-lock.",
Expand Down Expand Up @@ -696,9 +699,10 @@ def sanitize_lockfile_line(line: str) -> str:
]
)

if len(pip_deps) > 0:
if len(pip_deps) > 0 and not suppress_warning_for_pip_and_explicit:
logger.warning(
"WARNING: installation of pip dependencies is only supported by the "
"WARNING: installation of pip dependencies from explicit lockfiles "
"is only supported by the "
"'conda-lock install' and 'micromamba install' commands. Other tools "
"may silently ignore them. For portability, we recommend using the "
"newer unified lockfile format (i.e. removing the --kind=explicit "
Expand Down Expand Up @@ -1010,6 +1014,7 @@ def _render_lockfile_for_install(
platform=platform,
include_dev_dependencies=include_dev_dependencies,
extras=extras,
suppress_warning_for_pip_and_explicit=True,
)
with temporary_file_with_contents("\n".join(content) + "\n") as path:
yield path
Expand Down Expand Up @@ -1386,23 +1391,33 @@ def lock(
)


DEFAULT_INSTALL_OPT_MAMBA = HAVE_MAMBA
DEFAULT_INSTALL_OPT_MICROMAMBA = False
DEFAULT_INSTALL_OPT_COPY = False
DEFAULT_INSTALL_OPT_VALIDATE_PLATFORM = True
DEFAULT_INSTALL_OPT_LOG_LEVEL = "INFO"
DEFAULT_INSTALL_OPT_DEV = True
DEFAULT_INSTALL_OPT_LOCK_FILE = pathlib.Path(DEFAULT_LOCKFILE_NAME)


@main.command("install")
@click.option(
"--conda", default=None, help="path (or name) of the conda/mamba executable to use."
)
@click.option(
"--mamba/--no-mamba",
default=HAVE_MAMBA,
default=DEFAULT_INSTALL_OPT_MAMBA,
help="don't attempt to use or install mamba.",
)
@click.option(
"--micromamba/--no-micromamba",
default=False,
default=DEFAULT_INSTALL_OPT_MICROMAMBA,
help="don't attempt to use or install micromamba.",
)
@click.option(
"--copy",
is_flag=True,
default=DEFAULT_INSTALL_OPT_COPY,
help=(
"Install using `--copy` to prevent links. "
"This is useful for building containers"
Expand All @@ -1418,19 +1433,19 @@ def lock(
@click.option("--auth-file", help="Path to the authentication file.", default="")
@click.option(
"--validate-platform/--no-validate-platform",
default=True,
default=DEFAULT_INSTALL_OPT_VALIDATE_PLATFORM,
help="Whether the platform compatibility between your lockfile and the host system should be validated.",
)
@click.option(
"--log-level",
help="Log level.",
default="INFO",
default=DEFAULT_INSTALL_OPT_LOG_LEVEL,
type=click.Choice(["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]),
)
@click.option(
"--dev/--no-dev",
is_flag=True,
default=True,
default=DEFAULT_INSTALL_OPT_DEV,
help="install dev dependencies from the lockfile (where applicable)",
)
@click.option(
Expand All @@ -1440,11 +1455,9 @@ def lock(
default=[],
help="include extra dependencies from the lockfile (where applicable)",
)
@click.argument(
"lock-file", default=pathlib.Path(DEFAULT_LOCKFILE_NAME), type=click.Path()
)
@click.argument("lock-file", default=DEFAULT_INSTALL_OPT_LOCK_FILE, type=click.Path())
@click.pass_context
def install(
def click_install(
ctx: click.Context,
conda: Optional[str],
mamba: bool,
Expand All @@ -1468,6 +1481,38 @@ def install(

"""Perform a conda install"""
logging.basicConfig(level=log_level)
install(
conda=conda,
mamba=mamba,
micromamba=micromamba,
copy=copy,
prefix=prefix,
name=name,
lock_file=lock_file,
auth=auth,
auth_file=auth_file,
validate_platform=validate_platform,
dev=dev,
extras=extras,
)


def install(
conda: Optional[str] = None,
mamba: bool = DEFAULT_INSTALL_OPT_MAMBA,
micromamba: bool = DEFAULT_INSTALL_OPT_MICROMAMBA,
copy: bool = DEFAULT_INSTALL_OPT_COPY,
prefix: Optional[str] = None,
name: Optional[str] = None,
lock_file: pathlib.Path = DEFAULT_INSTALL_OPT_LOCK_FILE,
auth: Optional[str] = None,
auth_file: Optional[PathLike] = None,
validate_platform: bool = DEFAULT_INSTALL_OPT_VALIDATE_PLATFORM,
dev: bool = DEFAULT_INSTALL_OPT_DEV,
extras: Optional[List[str]] = None,
) -> None:
if extras is None:
extras = []
_auth = (
yaml.safe_load(auth) if auth else read_json(auth_file) if auth_file else None
)
Expand Down
Loading

0 comments on commit b2df9ad

Please sign in to comment.