Skip to content

Commit

Permalink
Merge pull request #450 from AlbertDeFusco/adefusco/fix-449/sorted-ex…
Browse files Browse the repository at this point in the history
…tras

Protect against unordered extras in pip dependencies
  • Loading branch information
maresb authored Jul 8, 2023
2 parents f5fa092 + 682bce3 commit e3c7a19
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
4 changes: 4 additions & 0 deletions conda_lock/models/lock_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class _BaseDependency(StrictModel):
category: str = "main"
extras: List[str] = []

@validator("extras")
def sorted_extras(cls, v: List[str]) -> List[str]:
return sorted(v)


class VersionedDependency(_BaseDependency):
version: str
Expand Down
7 changes: 7 additions & 0 deletions tests/test-pypi-resolve-gh449/environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
dependencies:
- python=3.10
- pip
- pip:
- pydantic[email,dotenv]==1.10.10
channels:
- defaults
24 changes: 24 additions & 0 deletions tests/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

from conda_lock.conda_lock import run_lock
from conda_lock.invoke_conda import is_micromamba
from conda_lock.models.lock_spec import VersionedDependency
from conda_lock.src_parser import DEFAULT_PLATFORMS
from conda_lock.src_parser.environment_yaml import parse_environment_file


TEST_DIR = Path(__file__).parent
Expand Down Expand Up @@ -88,3 +91,24 @@ def test_run_lock_regression_gh155(
if is_micromamba(conda_exe):
monkeypatch.setenv("CONDA_FLAGS", "-v")
run_lock([pip_environment_regression_gh155], conda_exe=conda_exe)


@pytest.fixture
def pip_environment_regression_gh449(tmp_path: Path):
return clone_test_dir("test-pypi-resolve-gh449", tmp_path).joinpath(
"environment.yml"
)


def test_pip_environment_regression_gh449(pip_environment_regression_gh449: Path):
res = parse_environment_file(pip_environment_regression_gh449, DEFAULT_PLATFORMS)
for plat in DEFAULT_PLATFORMS:
assert [dep for dep in res.dependencies[plat] if dep.manager == "pip"] == [
VersionedDependency(
name="pydantic",
manager="pip",
category="main",
extras=["dotenv", "email"],
version="=1.10.10",
)
]

0 comments on commit e3c7a19

Please sign in to comment.