未验证 提交 9716c1ce 编写于 作者: F Frost Ming 提交者: GitHub

Merge pull request #34 from frostming/feature/33

Reuse pinned candidates during `pdm install`
Pinned candidates in lock file are reused when relocking during `pdm install`.
......@@ -103,10 +103,15 @@ def lock(project):
)
@pass_project
def install(project, sections, dev, default, lock):
if lock and not (
project.lockfile_file.is_file() and project.is_lockfile_hash_match()
):
actions.do_lock(project)
if lock:
if not project.lockfile_file.exists():
context.io.echo("Lock file does not exist, trying to generate one...")
actions.do_lock(project, strategy="all")
elif not project.is_lockfile_hash_match():
context.io.echo(
"Lock file hash doesn't match pyproject.toml, regenerating..."
)
actions.do_lock(project, strategy="reuse")
actions.do_sync(project, sections, dev, default, False, False)
......
......@@ -177,7 +177,7 @@ class Project:
return {}
section = section or "default"
result = {}
for package in [dict(p) for p in self.lockfile["package"]]:
for package in [dict(p) for p in self.lockfile.get("package", [])]:
if section != "__all__" and section not in package["sections"]:
continue
version = package.get("version")
......
......@@ -6,6 +6,7 @@ from pathlib import Path
import pytest
from click.testing import CliRunner
from pdm.cli import actions, commands
from pdm.models.requirements import parse_requirement
@pytest.fixture()
......@@ -124,3 +125,16 @@ def test_use_command(project, invoke):
project.write_pyproject()
result = invoke(["use", "2.7"], obj=project)
assert result.exit_code == 1
def test_install_with_lockfile(project, invoke, working_set, repository):
result = invoke(["lock"], obj=project)
assert result.exit_code == 0
result = invoke(["install"], obj=project)
assert "Lock file" not in result.output
project.add_dependencies({"pytz": parse_requirement("pytz")})
result = invoke(["install"], obj=project)
assert "Lock file hash doesn't match" in result.output
assert "pytz" in project.get_locked_candidates()
assert project.is_lockfile_hash_match()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册