Skip to content

Commit

Permalink
Fix compatibility check for lock files (#2717)
Browse files Browse the repository at this point in the history
  • Loading branch information
sdispater authored Jul 24, 2020
1 parent ef8b18a commit c2bab89
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
4 changes: 3 additions & 1 deletion poetry/packages/locker.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,10 @@ def _get_lock_data(self): # type: () -> dict

lock_version = Version.parse(lock_data["metadata"].get("lock-version", "1.0"))
current_version = Version.parse(self._VERSION)
# We expect the locker to be able to read lock files
# from the same semantic versioning range
accepted_versions = parse_constraint(
"^{}".format(Version(current_version.major, current_version.minor))
"^{}".format(Version(current_version.major, 0))
)
lock_version_allowed = accepted_versions.allows(lock_version)
if lock_version_allowed and current_version < lock_version:
Expand Down
26 changes: 26 additions & 0 deletions tests/packages/test_locker.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,3 +340,29 @@ def test_extras_dependencies_are_ordered(locker, root):
content = f.read()

assert expected == content


def test_locker_should_neither_emit_warnings_nor_raise_error_for_lower_compatible_versions(
locker, caplog
):
current_version = Version.parse(Locker._VERSION)
older_version = ".".join(
[str(current_version.major), str(current_version.minor - 1)]
)
content = """\
[metadata]
content-hash = "c3d07fca33fba542ef2b2a4d75bf5b48d892d21a830e2ad9c952ba5123a52f77"
lock-version = "{version}"
python-versions = "~2.7 || ^3.4"
[metadata.files]
""".format(
version=older_version
)
caplog.set_level(logging.WARNING, logger="poetry.packages.locker")

locker.lock.write(tomlkit.parse(content))

_ = locker.lock_data

assert 0 == len(caplog.records)

0 comments on commit c2bab89

Please sign in to comment.