Skip to content

Commit

Permalink
Add lock versioning support
Browse files Browse the repository at this point in the history
  • Loading branch information
sdispater authored and abn committed Jul 21, 2020
1 parent f117a95 commit cd72aed
Show file tree
Hide file tree
Showing 30 changed files with 119 additions and 3 deletions.
7 changes: 5 additions & 2 deletions poetry/console/config/application_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ def register_command_loggers(

io = event.io

loggers = ["poetry.packages.package", "poetry.utils.password_manager"]
loggers = [
"poetry.packages.locker",
"poetry.packages.package",
"poetry.utils.password_manager",
]

loggers += command.loggers

Expand All @@ -65,7 +69,6 @@ def register_command_loggers(
logger = logging.getLogger(logger)

logger.handlers = [handler]
logger.propagate = False

level = logging.WARNING
if io.is_debug():
Expand Down
32 changes: 31 additions & 1 deletion poetry/packages/locker.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import logging
import re

from hashlib import sha256
Expand All @@ -13,13 +14,20 @@
import poetry.packages
import poetry.repositories

from poetry.semver import parse_constraint
from poetry.semver.version import Version
from poetry.utils._compat import Path
from poetry.utils.toml_file import TomlFile
from poetry.version.markers import parse_marker


logger = logging.getLogger(__name__)


class Locker(object):

_VERSION = "1.0"

_relevant_keys = ["dependencies", "dev-dependencies", "source", "extras"]

def __init__(self, lock, local_config): # type: (Path, dict) -> None
Expand Down Expand Up @@ -180,6 +188,7 @@ def set_lock_data(self, root, packages): # type: (...) -> bool
}

lock["metadata"] = {
"lock-version": self._VERSION,
"python-versions": root.python_versions,
"content-hash": self._content_hash,
"files": files,
Expand Down Expand Up @@ -222,10 +231,31 @@ def _get_lock_data(self): # type: () -> dict
raise RuntimeError("No lockfile found. Unable to read locked packages")

try:
return self._lock.read()
lock_data = self._lock.read()
except TOMLKitError as e:
raise RuntimeError("Unable to read the lock file ({}).".format(e))

lock_version = Version.parse(lock_data["metadata"].get("lock-version", "1.0"))
current_version = Version.parse(self._VERSION)
accepted_versions = parse_constraint(
"^{}".format(Version(current_version.major, current_version.minor))
)
lock_version_allowed = accepted_versions.allows(lock_version)
if lock_version_allowed and current_version < lock_version:
logger.warning(
"The lock file might not be compatible with the current version of Poetry.\n"
"Upgrade Poetry to ensure the lock file is read properly or, alternatively, "
"regenerate the lock file with the `poetry lock` command."
)
elif not lock_version_allowed:
raise RuntimeError(
"The lock file is not compatible with the current version of Poetry.\n"
"Upgrade Poetry to be able to read the lock file or, alternatively, "
"regenerate the lock file with the `poetry lock` command."
)

return lock_data

def _lock_packages(
self, packages
): # type: (List['poetry.packages.Package']) -> list
Expand Down
1 change: 1 addition & 0 deletions tests/installation/fixtures/extras-with-dependencies.test
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ foo = ["C"]

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

[metadata.files]
Expand Down
1 change: 1 addition & 0 deletions tests/installation/fixtures/extras.test
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ foo = ["D"]

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

[metadata.files]
Expand Down
1 change: 1 addition & 0 deletions tests/installation/fixtures/install-no-dev.test
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ python-versions = "*"

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

[metadata.files]
Expand Down
1 change: 1 addition & 0 deletions tests/installation/fixtures/no-dependencies.test
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package = []

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

[metadata.files]
1 change: 1 addition & 0 deletions tests/installation/fixtures/remove.test
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ python-versions = "*"

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

[metadata.files]
Expand Down
1 change: 1 addition & 0 deletions tests/installation/fixtures/update-with-lock.test
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ python-versions = "*"

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

[metadata.files]
Expand Down
1 change: 1 addition & 0 deletions tests/installation/fixtures/update-with-locked-extras.test
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ python-versions = "*"

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

[metadata.files]
Expand Down
1 change: 1 addition & 0 deletions tests/installation/fixtures/with-category-change.test
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ A = "^1.0"

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

[metadata.files]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ python = ">=3.6,<4.0"

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

[metadata.files]
Expand Down
1 change: 1 addition & 0 deletions tests/installation/fixtures/with-dependencies-extras.test
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ python-versions = "*"

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

[metadata.files]
Expand Down
1 change: 1 addition & 0 deletions tests/installation/fixtures/with-dependencies.test
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ python-versions = "*"

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

[metadata.files]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ url = "project_with_transitive_file_dependencies"

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

[metadata.files]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ url = "tests/fixtures/project_with_extras"

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

[metadata.files]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ python-versions = "*"

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

[metadata.files]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ python-versions = "*"

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

[metadata.files]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ python-versions = "*"

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

[metadata.files]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ url = "project_with_transitive_file_dependencies"

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

[metadata.files]
Expand Down
1 change: 1 addition & 0 deletions tests/installation/fixtures/with-file-dependency.test
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ python-versions = "*"

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

[metadata.files]
Expand Down
1 change: 1 addition & 0 deletions tests/installation/fixtures/with-multiple-updates.test
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ python-versions = "*"

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

[metadata.files]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ foo = ["A"]

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

[metadata.files]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ foo = ["A"]

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

[metadata.files]
Expand Down
1 change: 1 addition & 0 deletions tests/installation/fixtures/with-prereleases.test
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ python-versions = "*"

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

[metadata.files]
Expand Down
1 change: 1 addition & 0 deletions tests/installation/fixtures/with-pypi-repository.test
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ python-versions = "*"

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

[metadata.files]
Expand Down
1 change: 1 addition & 0 deletions tests/installation/fixtures/with-python-versions.test
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ python-versions = "~2.7 || ^3.3"

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

[metadata.files]
Expand Down
1 change: 1 addition & 0 deletions tests/installation/fixtures/with-sub-dependencies.test
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ python-versions = "*"

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

[metadata.files]
Expand Down
1 change: 1 addition & 0 deletions tests/installation/fixtures/with-url-dependency.test
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ python-versions = "*"

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

[metadata.files]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ url = "tests/fixtures/wheel_with_no_requires_dist/demo-0.1.0-py2.py3-none-any.wh

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

[metadata.files]
Expand Down
Loading

0 comments on commit cd72aed

Please sign in to comment.