Skip to content

Commit

Permalink
Add poetry version used to generate lock file
Browse files Browse the repository at this point in the history
Co-authored-by: Randy Döring <30527984+radoering@users.noreply.github.com>
  • Loading branch information
pfouque and radoering committed Jan 21, 2023
1 parent ccd09a2 commit f99198c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/poetry/packages/locker.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from tomlkit import inline_table
from tomlkit import table

from poetry.__version__ import __version__
from poetry.utils._compat import tomllib


Expand All @@ -40,8 +41,8 @@
logger = logging.getLogger(__name__)
_GENERATED_IDENTIFIER = "@" + "generated"
GENERATED_COMMENT = (
f"This file is automatically {_GENERATED_IDENTIFIER} by Poetry and should not be"
" changed by hand."
f"This file is automatically {_GENERATED_IDENTIFIER} by Poetry"
f" {__version__} and should not be changed by hand."
)


Expand Down
27 changes: 27 additions & 0 deletions tests/packages/test_locker.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from poetry.core.packages.package import Package
from poetry.core.packages.project_package import ProjectPackage

from poetry.__version__ import __version__
from poetry.factory import Factory
from poetry.packages.locker import GENERATED_COMMENT
from poetry.packages.locker import Locker
Expand Down Expand Up @@ -1169,3 +1170,29 @@ def test_lock_file_resolves_file_url_symlinks(root: ProjectPackage):
""" # noqa: E800

assert content == expected


def test_lockfile_is_not_rewritten_if_only_poetry_version_changed(
locker: Locker, root: ProjectPackage
) -> None:
generated_comment_old_version = GENERATED_COMMENT.replace(__version__, "1.3.2")
assert generated_comment_old_version != GENERATED_COMMENT
old_content = f"""\
# {generated_comment_old_version}
package = []
[metadata]
lock-version = "2.0"
python-versions = "*"
content-hash = "115cf985d932e9bf5f540555bbdd75decbb62cac81e399375fc19f6277f8c1d8"
""" # noqa: E800

with open(locker.lock, "w", encoding="utf-8") as f:
f.write(old_content)

assert not locker.set_lock_data(root, [])

with locker.lock.open(encoding="utf-8") as f:
content = f.read()

assert content == old_content

0 comments on commit f99198c

Please sign in to comment.