Skip to content

Commit

Permalink
Bump lockfile format to 2.0
Browse files Browse the repository at this point in the history
don't write package files out twice
  • Loading branch information
dimbleby authored and radoering committed Sep 24, 2022
1 parent f9e80ff commit e7f7f46
Show file tree
Hide file tree
Showing 36 changed files with 63 additions and 405 deletions.
11 changes: 3 additions & 8 deletions src/poetry/packages/locker.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@


class Locker:
_VERSION = "1.2"
_VERSION = "2.0"
_READ_VERSION_RANGE = ">=1,<3"

_legacy_keys = ["dependencies", "source", "extras", "dev-dependencies"]
_relevant_keys = [*_legacy_keys, "group"]
Expand Down Expand Up @@ -258,8 +259,6 @@ def set_lock_data(self, root: Package, packages: list[Package]) -> bool:
"lock-version": self._VERSION,
"python-versions": root.python_versions,
"content-hash": self._content_hash,
# TODO stop writing files here, this is deprecated.
"files": files,
}

if not self.is_locked() or lock != self.lock_data:
Expand Down Expand Up @@ -307,11 +306,7 @@ def _get_lock_data(self) -> TOMLDocument:
metadata = cast("Table", lock_data["metadata"])
lock_version = Version.parse(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(
f"^{Version.from_parts(current_version.major, 0)}"
)
accepted_versions = parse_constraint(self._READ_VERSION_RANGE)
lock_version_allowed = accepted_versions.allows(lock_version)
if lock_version_allowed and current_version < lock_version:
logger.warning(
Expand Down
2 changes: 1 addition & 1 deletion tests/console/commands/test_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def test_lock_no_update(

assert len(packages) == len(locked_repository.packages)

assert locker.lock_data["metadata"].get("lock-version") == "1.2"
assert locker.lock_data["metadata"].get("lock-version") == "2.0"

for package in packages:
assert locked_repository.find_packages(package.to_dependency())
50 changes: 1 addition & 49 deletions tests/fixtures/outdated_lock/poetry.lock

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

50 changes: 1 addition & 49 deletions tests/fixtures/up_to_date_lock/poetry.lock

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

8 changes: 1 addition & 7 deletions tests/installation/fixtures/extras-with-dependencies.test
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,5 @@ foo = ["C"]

[metadata]
python-versions = "*"
lock-version = "1.2"
lock-version = "2.0"
content-hash = "123456789"

[metadata.files]
A = []
B = []
C = []
D = []
8 changes: 1 addition & 7 deletions tests/installation/fixtures/extras.test
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,5 @@ foo = ["D"]

[metadata]
python-versions = "*"
lock-version = "1.2"
lock-version = "2.0"
content-hash = "123456789"

[metadata.files]
A = []
B = []
C = []
D = []
7 changes: 1 addition & 6 deletions tests/installation/fixtures/install-no-dev.test
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,5 @@ files = []

[metadata]
python-versions = "*"
lock-version = "1.2"
lock-version = "2.0"
content-hash = "123456789"

[metadata.files]
"A" = []
"B" = []
"C" = []
4 changes: 1 addition & 3 deletions tests/installation/fixtures/no-dependencies.test
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@ package = []

[metadata]
python-versions = "*"
lock-version = "1.2"
lock-version = "2.0"
content-hash = "123456789"

[metadata.files]
5 changes: 1 addition & 4 deletions tests/installation/fixtures/remove.test
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,5 @@ files = []

[metadata]
python-versions = "*"
lock-version = "1.2"
lock-version = "2.0"
content-hash = "123456789"

[metadata.files]
"A" = []
5 changes: 1 addition & 4 deletions tests/installation/fixtures/update-with-lock.test
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,5 @@ files = []

[metadata]
python-versions = "*"
lock-version = "1.2"
lock-version = "2.0"
content-hash = "123456789"

[metadata.files]
"A" = []
8 changes: 1 addition & 7 deletions tests/installation/fixtures/update-with-locked-extras.test
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,5 @@ files = []

[metadata]
python-versions = "*"
lock-version = "1.2"
lock-version = "2.0"
content-hash = "123456789"

[metadata.files]
"A" = []
"B" = []
"C" = []
"D" = []
6 changes: 1 addition & 5 deletions tests/installation/fixtures/with-category-change.test
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,5 @@ A = "^1.0"

[metadata]
python-versions = "*"
lock-version = "1.2"
lock-version = "2.0"
content-hash = "123456789"

[metadata.files]
"A" = []
"B" = []
5 changes: 1 addition & 4 deletions tests/installation/fixtures/with-conditional-dependency.test
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,5 @@ python = ">=3.6,<4.0"

[metadata]
python-versions = "~2.7 || ^3.4"
lock-version = "1.2"
lock-version = "2.0"
content-hash = "123456789"

[metadata.files]
A = []
7 changes: 1 addition & 6 deletions tests/installation/fixtures/with-dependencies-extras.test
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,5 @@ files = []

[metadata]
python-versions = "*"
lock-version = "1.2"
lock-version = "2.0"
content-hash = "123456789"

[metadata.files]
"A" = []
"B" = []
"C" = []
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,5 @@ files = []

[metadata]
python-versions = "*"
lock-version = "1.2"
lock-version = "2.0"
content-hash = "123456789"

[metadata.files]
"A" = []
"B" = []
"C" = []
6 changes: 1 addition & 5 deletions tests/installation/fixtures/with-dependencies.test
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,5 @@ files = []

[metadata]
python-versions = "*"
lock-version = "1.2"
lock-version = "2.0"
content-hash = "123456789"

[metadata.files]
"A" = []
"B" = []
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,5 @@ url = "project_with_transitive_file_dependencies"

[metadata]
content-hash = "123456789"
lock-version = "1.2"
lock-version = "2.0"
python-versions = "*"

[metadata.files]
demo = [
{file = "demo-0.1.0-py2.py3-none-any.whl", hash = "sha256:70e704135718fffbcbf61ed1fc45933cfd86951a744b681000eaaa75da31f17a"},
]
inner-directory-project = []
pendulum = []
project-with-extras = []
project-with-transitive-directory-dependencies = []
project-with-transitive-file-dependencies = []
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,5 @@ url = "tests/fixtures/project_with_extras"

[metadata]
content-hash = "123456789"
lock-version = "1.2"
lock-version = "2.0"
python-versions = "*"

[metadata.files]
project-with-extras = []
pendulum = []
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,5 @@ pendulum = ">=1.4.4"

[metadata]
python-versions = "*"
lock-version = "1.2"
lock-version = "2.0"
content-hash = "123456789"

[metadata.files]
cachy = []
project-with-setup = []
pendulum = []
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,5 @@ files = []

[metadata]
python-versions = "*"
lock-version = "1.2"
lock-version = "2.0"
content-hash = "123456789"

[metadata.files]
A = []
B = []
C = []
7 changes: 1 addition & 6 deletions tests/installation/fixtures/with-duplicate-dependencies.test
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,5 @@ files = []

[metadata]
python-versions = "*"
lock-version = "1.2"
lock-version = "2.0"
content-hash = "123456789"

[metadata.files]
A = []
B = []
C = []
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,5 @@ url = "project_with_transitive_file_dependencies"

[metadata]
content-hash = "123456789"
lock-version = "1.2"
lock-version = "2.0"
python-versions = "*"

[metadata.files]
demo = [
{file = "demo-0.1.0-py2.py3-none-any.whl", hash = "sha256:70e704135718fffbcbf61ed1fc45933cfd86951a744b681000eaaa75da31f17a"},
]
inner-directory-project = []
pendulum = []
project-with-transitive-file-dependencies = []
8 changes: 1 addition & 7 deletions tests/installation/fixtures/with-file-dependency.test
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,5 @@ files = []

[metadata]
python-versions = "*"
lock-version = "1.2"
lock-version = "2.0"
content-hash = "123456789"

[metadata.files]
demo = [
{file = "demo-0.1.0-py2.py3-none-any.whl", hash = "sha256:70e704135718fffbcbf61ed1fc45933cfd86951a744b681000eaaa75da31f17a"},
]
pendulum = []
7 changes: 1 addition & 6 deletions tests/installation/fixtures/with-multiple-updates.test
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,5 @@ files = []

[metadata]
python-versions = "~2.7 || ^3.4"
lock-version = "1.2"
lock-version = "2.0"
content-hash = "123456789"

[metadata.files]
A = []
B = []
C = []
Loading

0 comments on commit e7f7f46

Please sign in to comment.