Skip to content

Commit

Permalink
fix #6 (#7)
Browse files Browse the repository at this point in the history
* fix #6

* add test
  • Loading branch information
sigma67 authored Feb 16, 2024
1 parent a3691dd commit 3a5c146
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/pdm_build_locked/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ def handle(self, project: Project, options: argparse.Namespace) -> None:
locked_group_name = get_locked_group_name(group)

locked_packages = self._get_locked_packages(project, group)
optional_dependencies[locked_group_name] = locked_packages
if locked_packages:
optional_dependencies[locked_group_name] = locked_packages

# write to pyproject
# get reference to optional-dependencies in project.pyproject, or create it if it doesn't exist
Expand Down
96 changes: 96 additions & 0 deletions tests/data/empty/pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions tests/data/empty/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[project]
name = "test-pdm"
version = "0.1.0"
dynamic = ["optional-dependencies"]
dependencies = []
requires-python = ">=3.10"

[tool.pdm.dev-dependencies]
test = ["pytest"]
25 changes: 25 additions & 0 deletions tests/unit/test_build_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,28 @@ def test_build_locked_invalid(pdm: PDMCallable, data_base_path: Path, temp_dir:
]
result = pdm(cmd)
assert "PdmException" in result.stderr


@pytest.mark.usefixtures("assert_pyproject_unmodified")
@pytest.mark.parametrize("test_project", ["empty"])
def test_build_locked_empty(pdm: PDMCallable, data_base_path: Path, temp_dir: Path, test_project: str) -> None:
"""this project's lockfile has empty dependencies and dynamic optional-dependencies
doesn't make sense to use the plugin in this case - but it should work nevertheless
Args:
pdm: PDM runner fixture
data_base_path: path to tests/data
temp_dir: path to tests/_temp/... temporary directory
test_project: path to test project
"""
project_path = data_base_path.joinpath(test_project)
cmd = [
"build",
"--locked",
"--project",
project_path.as_posix(),
"--dest",
temp_dir.as_posix(),
]
result = pdm(cmd)
assert result.exit_code == 0

0 comments on commit 3a5c146

Please sign in to comment.