Skip to content

Commit

Permalink
Merge branch 'main' into meta-conda-lock
Browse files Browse the repository at this point in the history
  • Loading branch information
maresb authored Jun 10, 2023
2 parents d1f32d6 + d25cc37 commit a81236b
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 20 deletions.
10 changes: 2 additions & 8 deletions conda_lock/src_parser/pyproject_toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
URLDependency,
VersionedDependency,
)
from conda_lock.src_parser.conda_common import conda_spec_to_versioned_dep


POETRY_INVALID_EXTRA_LOC = (
Expand Down Expand Up @@ -278,15 +279,8 @@ def specification_with_dependencies(
["tool", "conda-lock", "dependencies"], toml_contents, {}
).items():
if isinstance(depattrs, str):
conda_version = depattrs
dependencies.append(
VersionedDependency(
name=depname,
version=conda_version,
manager="conda",
category="main",
extras=[],
)
conda_spec_to_versioned_dep(f"{depname} {depattrs}", "main")
)
elif isinstance(depattrs, collections.abc.Mapping):
if depattrs.get("source", None) == "pypi":
Expand Down
16 changes: 16 additions & 0 deletions tests/test-toml-channel/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[tool.poetry]
name = "conda-lock-test-poetry-optional"
version = "0.0.1"
description = ""
authors = ["conda-lock"]

[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"

[tool.conda-lock]
platforms = ["linux-64"]
channels = ["conda-forge"]

[tool.conda-lock.dependencies]
"comet_ml::comet_ml" = "3.32.0"
53 changes: 41 additions & 12 deletions tests/test_conda_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@

from glob import glob
from pathlib import Path
from typing import Any, Dict, List, Union
from typing import Any, ContextManager, Dict, List, Union
from unittest.mock import MagicMock
from urllib.parse import urldefrag, urlsplit

import filelock
import pytest
import yaml

from click.testing import CliRunner
from click.testing import Result as CliResult
from flaky import flaky
from freezegun import freeze_time

Expand Down Expand Up @@ -240,6 +242,11 @@ def pdm_pyproject_toml_default_pip(tmp_path: Path):
return clone_test_dir("test-pdm-default-pip", tmp_path).joinpath("pyproject.toml")


@pytest.fixture
def pyproject_channel_toml(tmp_path: Path):
return clone_test_dir("test-toml-channel", tmp_path).joinpath("pyproject.toml")


@pytest.fixture
def channel_inversion(tmp_path: Path):
"""Path to an environment.yaml that has a hardcoded channel in one of the dependencies"""
Expand Down Expand Up @@ -830,6 +837,17 @@ def test_parse_pdm_default_pip(pdm_pyproject_toml_default_pip: Path):
assert specs["click"].manager == "pip"


def test_parse_pyproject_channel_toml(pyproject_channel_toml: Path):
res = parse_pyproject_toml(pyproject_channel_toml, ["linux-64"])

specs = {
dep.name: typing.cast(VersionedDependency, dep)
for dep in res.dependencies["linux-64"]
}

assert specs["comet_ml"].manager == "conda"


def test_parse_poetry_invalid_optionals(pyproject_optional_toml: Path):
filename = pyproject_optional_toml.name

Expand Down Expand Up @@ -871,6 +889,15 @@ def test_run_lock(
run_lock([zlib_environment], conda_exe=conda_exe)


def test_run_lock_channel_toml(
monkeypatch: "pytest.MonkeyPatch", pyproject_channel_toml: Path, conda_exe: str
):
monkeypatch.chdir(pyproject_channel_toml.parent)
if is_micromamba(conda_exe):
monkeypatch.setenv("CONDA_FLAGS", "-v")
run_lock([pyproject_channel_toml], conda_exe=conda_exe)


def test_run_lock_with_input_metadata(
monkeypatch: "pytest.MonkeyPatch", zlib_environment: Path, conda_exe: str
):
Expand Down Expand Up @@ -1508,6 +1535,13 @@ def test_install(
f"Standalone conda @ '{conda_exe}' does not support materializing from environment files."
)

root_prefix = tmp_path / "root_prefix"
generated_lockfile_path = tmp_path / "generated_lockfiles"

root_prefix.mkdir(exist_ok=True)
generated_lockfile_path.mkdir(exist_ok=True)
monkeypatch.chdir(generated_lockfile_path)

package = "zlib"
platform = "linux-64"

Expand All @@ -1519,12 +1553,6 @@ def test_install(
+ "conda-linux-64-true.lock"
+ (".yml" if kind == "env" else "")
)
try:
os.remove(lock_filename)
except OSError:
pass

from click.testing import CliRunner

with capsys.disabled():
runner = CliRunner(mix_stderr=False)
Expand All @@ -1549,9 +1577,9 @@ def test_install(
print(result.stderr, file=sys.stderr)
assert result.exit_code == 0

env_name = "test_env"
prefix = root_prefix / "test_env"

def invoke_install(*extra_args: str):
def invoke_install(*extra_args: str) -> CliResult:
with capsys.disabled():
return runner.invoke(
main,
Expand All @@ -1560,13 +1588,14 @@ def invoke_install(*extra_args: str):
"--conda",
conda_exe,
"--prefix",
str(tmp_path / env_name),
str(prefix),
*extra_args,
lock_filename,
],
catch_exceptions=False,
)

context: ContextManager
if sys.platform.lower().startswith("linux"):
context = contextlib.nullcontext()
else:
Expand All @@ -1586,8 +1615,8 @@ def invoke_install(*extra_args: str):
if sys.platform.lower().startswith("linux"):
assert _check_package_installed(
package=package,
prefix=str(tmp_path / env_name),
), f"Package {package} does not exist in {tmp_path} environment"
prefix=str(prefix),
), f"Package {package} does not exist in {prefix} environment"


@pytest.mark.parametrize(
Expand Down

0 comments on commit a81236b

Please sign in to comment.