Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
python-poetry
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
python-poetry
Commits
cd72aed8
Commit
cd72aed8
authored
Jul 21, 2020
by
Sébastien Eustace
Committed by
Arun Babu Neelicattu
Jul 21, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add lock versioning support
parent
f117a955
Show whitespace changes
Inline
Side-by-side
Showing
30 changed files
with
119 additions
and
3 deletions
+119
-3
poetry/console/config/application_config.py
+5
-2
poetry/packages/locker.py
+31
-1
tests/installation/fixtures/extras-with-dependencies.test
+1
-0
tests/installation/fixtures/extras.test
+1
-0
tests/installation/fixtures/install-no-dev.test
+1
-0
tests/installation/fixtures/no-dependencies.test
+1
-0
tests/installation/fixtures/remove.test
+1
-0
tests/installation/fixtures/update-with-lock.test
+1
-0
tests/installation/fixtures/update-with-locked-extras.test
+1
-0
tests/installation/fixtures/with-category-change.test
+1
-0
tests/installation/fixtures/with-conditional-dependency.test
+1
-0
tests/installation/fixtures/with-dependencies-extras.test
+1
-0
tests/installation/fixtures/with-dependencies.test
+1
-0
tests/installation/fixtures/with-directory-dependency-poetry-transitive.test
+1
-0
tests/installation/fixtures/with-directory-dependency-poetry.test
+1
-0
tests/installation/fixtures/with-directory-dependency-setuptools.test
+1
-0
tests/installation/fixtures/with-duplicate-dependencies-update.test
+1
-0
tests/installation/fixtures/with-duplicate-dependencies.test
+1
-0
tests/installation/fixtures/with-file-dependency-transitive.test
+1
-0
tests/installation/fixtures/with-file-dependency.test
+1
-0
tests/installation/fixtures/with-multiple-updates.test
+1
-0
tests/installation/fixtures/with-optional-dependencies.test
+1
-0
tests/installation/fixtures/with-platform-dependencies.test
+1
-0
tests/installation/fixtures/with-prereleases.test
+1
-0
tests/installation/fixtures/with-pypi-repository.test
+1
-0
tests/installation/fixtures/with-python-versions.test
+1
-0
tests/installation/fixtures/with-sub-dependencies.test
+1
-0
tests/installation/fixtures/with-url-dependency.test
+1
-0
tests/installation/fixtures/with-wheel-dependency-no-requires-dist.test
+1
-0
tests/packages/test_locker.py
+56
-0
No files found.
poetry/console/config/application_config.py
View file @
cd72aed8
...
...
@@ -54,7 +54,11 @@ class ApplicationConfig(BaseApplicationConfig):
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
...
...
@@ -65,7 +69,6 @@ class ApplicationConfig(BaseApplicationConfig):
logger
=
logging
.
getLogger
(
logger
)
logger
.
handlers
=
[
handler
]
logger
.
propagate
=
False
level
=
logging
.
WARNING
if
io
.
is_debug
():
...
...
poetry/packages/locker.py
View file @
cd72aed8
import
json
import
logging
import
re
from
hashlib
import
sha256
...
...
@@ -13,13 +14,20 @@ from tomlkit.exceptions import TOMLKitError
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
...
...
@@ -180,6 +188,7 @@ class Locker(object):
}
lock
[
"metadata"
]
=
{
"lock-version"
:
self
.
_VERSION
,
"python-versions"
:
root
.
python_versions
,
"content-hash"
:
self
.
_content_hash
,
"files"
:
files
,
...
...
@@ -222,10 +231,31 @@ class Locker(object):
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
...
...
tests/installation/fixtures/extras-with-dependencies.test
View file @
cd72aed8
...
...
@@ -38,6 +38,7 @@ foo = ["C"]
[
metadata
]
python
-
versions
=
"*"
lock
-
version
=
"1.0"
content
-
hash
=
"123456789"
[
metadata
.
files
]
...
...
tests/installation/fixtures/extras.test
View file @
cd72aed8
...
...
@@ -35,6 +35,7 @@ foo = ["D"]
[
metadata
]
python
-
versions
=
"*"
lock
-
version
=
"1.0"
content
-
hash
=
"123456789"
[
metadata
.
files
]
...
...
tests/installation/fixtures/install-no-dev.test
View file @
cd72aed8
...
...
@@ -24,6 +24,7 @@ python-versions = "*"
[
metadata
]
python
-
versions
=
"*"
lock
-
version
=
"1.0"
content
-
hash
=
"123456789"
[
metadata
.
files
]
...
...
tests/installation/fixtures/no-dependencies.test
View file @
cd72aed8
...
...
@@ -2,6 +2,7 @@ package = []
[
metadata
]
python
-
versions
=
"*"
lock
-
version
=
"1.0"
content
-
hash
=
"123456789"
[
metadata
.
files
]
tests/installation/fixtures/remove.test
View file @
cd72aed8
...
...
@@ -8,6 +8,7 @@ python-versions = "*"
[
metadata
]
python
-
versions
=
"*"
lock
-
version
=
"1.0"
content
-
hash
=
"123456789"
[
metadata
.
files
]
...
...
tests/installation/fixtures/update-with-lock.test
View file @
cd72aed8
...
...
@@ -8,6 +8,7 @@ python-versions = "*"
[
metadata
]
python
-
versions
=
"*"
lock
-
version
=
"1.0"
content
-
hash
=
"123456789"
[
metadata
.
files
]
...
...
tests/installation/fixtures/update-with-locked-extras.test
View file @
cd72aed8
...
...
@@ -40,6 +40,7 @@ python-versions = "*"
[
metadata
]
python
-
versions
=
"*"
lock
-
version
=
"1.0"
content
-
hash
=
"123456789"
[
metadata
.
files
]
...
...
tests/installation/fixtures/with-category-change.test
View file @
cd72aed8
...
...
@@ -19,6 +19,7 @@ A = "^1.0"
[
metadata
]
python
-
versions
=
"*"
lock
-
version
=
"1.0"
content
-
hash
=
"123456789"
[
metadata
.
files
]
...
...
tests/installation/fixtures/with-conditional-dependency.test
View file @
cd72aed8
...
...
@@ -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
]
...
...
tests/installation/fixtures/with-dependencies-extras.test
View file @
cd72aed8
...
...
@@ -30,6 +30,7 @@ python-versions = "*"
[
metadata
]
python
-
versions
=
"*"
lock
-
version
=
"1.0"
content
-
hash
=
"123456789"
[
metadata
.
files
]
...
...
tests/installation/fixtures/with-dependencies.test
View file @
cd72aed8
...
...
@@ -16,6 +16,7 @@ python-versions = "*"
[
metadata
]
python
-
versions
=
"*"
lock
-
version
=
"1.0"
content
-
hash
=
"123456789"
[
metadata
.
files
]
...
...
tests/installation/fixtures/with-directory-dependency-poetry-transitive.test
View file @
cd72aed8
...
...
@@ -96,6 +96,7 @@ url = "project_with_transitive_file_dependencies"
[
metadata
]
content
-
hash
=
"123456789"
lock
-
version
=
"1.0"
python
-
versions
=
"*"
[
metadata
.
files
]
...
...
tests/installation/fixtures/with-directory-dependency-poetry.test
View file @
cd72aed8
...
...
@@ -29,6 +29,7 @@ url = "tests/fixtures/project_with_extras"
[
metadata
]
content
-
hash
=
"123456789"
lock
-
version
=
"1.0"
python
-
versions
=
"*"
[
metadata
.
files
]
...
...
tests/installation/fixtures/with-directory-dependency-setuptools.test
View file @
cd72aed8
...
...
@@ -34,6 +34,7 @@ python-versions = "*"
[
metadata
]
python
-
versions
=
"*"
lock
-
version
=
"1.0"
content
-
hash
=
"123456789"
[
metadata
.
files
]
...
...
tests/installation/fixtures/with-duplicate-dependencies-update.test
View file @
cd72aed8
...
...
@@ -31,6 +31,7 @@ python-versions = "*"
[
metadata
]
python
-
versions
=
"*"
lock
-
version
=
"1.0"
content
-
hash
=
"123456789"
[
metadata
.
files
]
...
...
tests/installation/fixtures/with-duplicate-dependencies.test
View file @
cd72aed8
...
...
@@ -56,6 +56,7 @@ python-versions = "*"
[
metadata
]
python
-
versions
=
"*"
lock
-
version
=
"1.0"
content
-
hash
=
"123456789"
[
metadata
.
files
]
...
...
tests/installation/fixtures/with-file-dependency-transitive.test
View file @
cd72aed8
...
...
@@ -60,6 +60,7 @@ url = "project_with_transitive_file_dependencies"
[
metadata
]
content
-
hash
=
"123456789"
lock
-
version
=
"1.0"
python
-
versions
=
"*"
[
metadata
.
files
]
...
...
tests/installation/fixtures/with-file-dependency.test
View file @
cd72aed8
...
...
@@ -28,6 +28,7 @@ python-versions = "*"
[
metadata
]
python
-
versions
=
"*"
lock
-
version
=
"1.0"
content
-
hash
=
"123456789"
[
metadata
.
files
]
...
...
tests/installation/fixtures/with-multiple-updates.test
View file @
cd72aed8
...
...
@@ -49,6 +49,7 @@ python-versions = "*"
[
metadata
]
python
-
versions
=
"~2.7 || ^3.4"
lock
-
version
=
"1.0"
content
-
hash
=
"123456789"
[
metadata
.
files
]
...
...
tests/installation/fixtures/with-optional-dependencies.test
View file @
cd72aed8
...
...
@@ -32,6 +32,7 @@ foo = ["A"]
[
metadata
]
python
-
versions
=
"~2.7 || ^3.4"
lock
-
version
=
"1.0"
content
-
hash
=
"123456789"
[
metadata
.
files
]
...
...
tests/installation/fixtures/with-platform-dependencies.test
View file @
cd72aed8
...
...
@@ -41,6 +41,7 @@ foo = ["A"]
[
metadata
]
python
-
versions
=
"*"
lock
-
version
=
"1.0"
content
-
hash
=
"123456789"
[
metadata
.
files
]
...
...
tests/installation/fixtures/with-prereleases.test
View file @
cd72aed8
...
...
@@ -16,6 +16,7 @@ python-versions = "*"
[
metadata
]
python
-
versions
=
"*"
lock
-
version
=
"1.0"
content
-
hash
=
"123456789"
[
metadata
.
files
]
...
...
tests/installation/fixtures/with-pypi-repository.test
View file @
cd72aed8
...
...
@@ -84,6 +84,7 @@ python-versions = "*"
[
metadata
]
python
-
versions
=
"*"
lock
-
version
=
"1.0"
content
-
hash
=
"123456789"
[
metadata
.
files
]
...
...
tests/installation/fixtures/with-python-versions.test
View file @
cd72aed8
...
...
@@ -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
]
...
...
tests/installation/fixtures/with-sub-dependencies.test
View file @
cd72aed8
...
...
@@ -38,6 +38,7 @@ python-versions = "*"
[
metadata
]
python
-
versions
=
"*"
lock
-
version
=
"1.0"
content
-
hash
=
"123456789"
[
metadata
.
files
]
...
...
tests/installation/fixtures/with-url-dependency.test
View file @
cd72aed8
...
...
@@ -28,6 +28,7 @@ python-versions = "*"
[
metadata
]
python
-
versions
=
"*"
lock
-
version
=
"1.0"
content
-
hash
=
"123456789"
[
metadata
.
files
]
...
...
tests/installation/fixtures/with-wheel-dependency-no-requires-dist.test
View file @
cd72aed8
...
...
@@ -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
]
...
...
tests/packages/test_locker.py
View file @
cd72aed8
import
logging
import
tempfile
import
pytest
...
...
@@ -56,6 +57,7 @@ version = "1.2"
[metadata]
content-hash = "115cf985d932e9bf5f540555bbdd75decbb62cac81e399375fc19f6277f8c1d8"
lock-version = "1.0"
python-versions = "*"
[metadata.files]
...
...
@@ -93,6 +95,7 @@ redis = ["redis (>=2.10.5)"]
[metadata]
content-hash = "c3d07fca33fba542ef2b2a4d75bf5b48d892d21a830e2ad9c952ba5123a52f77"
lock-version = "1.0"
python-versions = "~2.7 || ^3.4"
[metadata.files]
...
...
@@ -132,6 +135,7 @@ version = "1.0.0"
[metadata]
content-hash = "115cf985d932e9bf5f540555bbdd75decbb62cac81e399375fc19f6277f8c1d8"
lock-version = "1.0"
python-versions = "*"
[metadata.files]
...
...
@@ -171,6 +175,7 @@ foo = ["B (>=1.0.0)"]
[metadata]
content-hash = "115cf985d932e9bf5f540555bbdd75decbb62cac81e399375fc19f6277f8c1d8"
lock-version = "1.0"
python-versions = "*"
[metadata.files]
...
...
@@ -200,6 +205,7 @@ foo = ["bar"]
[metadata]
content-hash = "115cf985d932e9bf5f540555bbdd75decbb62cac81e399375fc19f6277f8c1d8"
lock-version = "1.0"
python-versions = "*"
[metadata.files]
...
...
@@ -239,6 +245,7 @@ url = "https://foo.bar"
[metadata]
content-hash = "115cf985d932e9bf5f540555bbdd75decbb62cac81e399375fc19f6277f8c1d8"
lock-version = "1.0"
python-versions = "*"
[metadata.files]
...
...
@@ -246,3 +253,52 @@ A = []
"""
assert
expected
==
content
def
test_locker_should_emit_warnings_if_lock_version_is_newer_but_allowed
(
locker
,
caplog
):
content
=
"""
\
[metadata]
content-hash = "c3d07fca33fba542ef2b2a4d75bf5b48d892d21a830e2ad9c952ba5123a52f77"
lock-version = "1.1"
python-versions = "~2.7 || ^3.4"
[metadata.files]
"""
caplog
.
set_level
(
logging
.
WARNING
,
logger
=
"poetry.packages.locker"
)
locker
.
lock
.
write
(
tomlkit
.
parse
(
content
))
_
=
locker
.
lock_data
assert
1
==
len
(
caplog
.
records
)
record
=
caplog
.
records
[
0
]
assert
"WARNING"
==
record
.
levelname
expected
=
"""
\
The lock file might not be compatible with the current version of Poetry.
Upgrade Poetry to ensure the lock file is read properly or, alternatively,
\
regenerate the lock file with the `poetry lock` command.
\
"""
assert
expected
==
record
.
message
def
test_locker_should_raise_an_error_if_lock_version_is_newer_and_not_allowed
(
locker
,
caplog
):
content
=
"""
\
[metadata]
content-hash = "c3d07fca33fba542ef2b2a4d75bf5b48d892d21a830e2ad9c952ba5123a52f77"
lock-version = "2.0"
python-versions = "~2.7 || ^3.4"
[metadata.files]
"""
caplog
.
set_level
(
logging
.
WARNING
,
logger
=
"poetry.packages.locker"
)
locker
.
lock
.
write
(
tomlkit
.
parse
(
content
))
with
pytest
.
raises
(
RuntimeError
,
match
=
"^The lock file is not compatible"
):
_
=
locker
.
lock_data
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment