Skip to content

Commit

Permalink
Ignore pip packages in constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosnewmar committed Jan 2, 2024
1 parent 77ea64e commit d86cac8
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/conda_devenv/devenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ def process_constraints_into_dependencies(yaml_dict: YAMLData) -> None:
return

dependency_names = {
PackageSpecifier.parse(dep).name for dep in yaml_dict["dependencies"]
PackageSpecifier.parse(dep).name for dep in yaml_dict["dependencies"] if isinstance(dep, str)
}

added_dependencies = [
Expand Down
24 changes: 24 additions & 0 deletions tests/test_load_yaml_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ def test_load_yaml_dict(datadir) -> None:
assert set(environment["PATH"]) == {"b_path", "a_path"}


def test_load_yaml_dict_with_pip(datadir) -> None:
conda_yaml_dict = load_yaml_dict(datadir / "d.yml")
dependencies = conda_yaml_dict["dependencies"]
assert dependencies == ['a_dependency', {'pip': ['d_dependency']}]


def test_load_yaml_dict_with_wrong_definition_at_environment_key(datadir) -> None:
filename = datadir / "a_wrong_definition_at_environment.yml"
with pytest.raises(ValueError) as e:
Expand Down Expand Up @@ -250,6 +256,24 @@ def test_constraints_respected(self) -> None:
"attrs >=20",
]

def test_constraints_respected_with_pip(self) -> None:
"""
Constraints are declared as dependency if they are explicitly declared.
"""
data = {
"dependencies": ["attrs >19", "boltons", "pytest>=6", {"pip": ["lupa >= 1.14"]}],
"constraints": ["pytest >7", "attrs >=20", "requests <2"],
}
process_constraints_into_dependencies(data)
assert data["dependencies"] == [
"attrs >19",
"boltons",
"pytest>=6",
{'pip': ['lupa >= 1.14']},
"pytest >7",
"attrs >=20",
]

def test_integration(self, tmp_path: Path) -> None:
utils_fn = tmp_path / "common-utils.devenv.yml"
utils_fn.write_text(
Expand Down
8 changes: 8 additions & 0 deletions tests/test_load_yaml_dict/d.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: d
dependencies:
- a_dependency
- pip:
- d_dependency
environment:
PATH:
- a_path
2 changes: 2 additions & 0 deletions tests/test_locking.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def test_create_and_update_lock_files(
- pytest
- wincom # [win]
- shmem # [unix]
- pip:
- lupa
"""
)
)
Expand Down
2 changes: 2 additions & 0 deletions tests/test_locking/expected.linux-64.lock_environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ dependencies:
- flock
- pytest
- shmem
- pip:
- lupa
environment: {}
name: foo-py310
platforms:
Expand Down
2 changes: 2 additions & 0 deletions tests/test_locking/expected.win-64.lock_environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ dependencies:
- pytest
- pywin32
- wincom
- pip:
- lupa
environment: {}
name: foo-py310
platforms:
Expand Down

0 comments on commit d86cac8

Please sign in to comment.