Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compatibility check for lock files #2717

Merged
merged 1 commit into from
Jul 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)