question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

option to fail if `poetry.lock` doesn't match `pyproject.toml`

See original GitHub issue
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • I have searched the documentation and believe that my question is not covered.

steps

1: add dependencies and run poetry update 2: change dependencies and run poetry install

expected

The command fails as you will install dependencies that are not reflecting the project configuration

actual

All you get is a warning

Feature Request

currently when you run poetry install with an outdated lock file, you get this warning:

Warning: The lock file is not up to date with the latest changes in pyproject.toml. You may be getting outdated dependencies. Run update to update them.

it would be nice if there was an option to make this an error instead of a warning. in my case i want the CI to fail if poetry.lock is outdated.

the warning can be easily missed when running in CI

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:17
  • Comments:10 (8 by maintainers)

github_iconTop GitHub Comments

4reactions
DetachHeadcommented, Jan 11, 2022

In my opinion, this feature would be counterintuitive and it wouldn’t add much value.

I disagree. If I change/add a dependency in pyproject.toml and forget to run poetry update, I’ll experience unexpected behaviour where the cause won’t be immediately obvious. Other similar tools such as npm and gradle fail when the lock file is outdated

I think adding a command line option to remove the assertions made by a lock file would be confusing

I’m not asking for an option to remove the lock file’s assertions, only an option to fail if pyproject.toml contradicts those assertions

2reactions
glencairncommented, Jan 14, 2022

If the version of a dependency in the lock file does not satisfy the constraints specified in the pyproject.toml file, you will get an error when running poetry install (the error description is pretty bad though). Just because a locked dependency is out of date does not mean that it violates your project’s constraints.

i just ran poetry install where the pyproject.toml has new dependencies in it that are not present at all in the poetry.lock file. i would expect an error message when poetry install isn’t going to install all of the dependencies specified in pyproject.toml because as you said it does not satisfy the constraints specified in the pyproject.toml file

i just tried poetry lock --check and it picks up this issue

Ah, I see. My example was only addressing the case where the version of an existing dependency is changed manually. I had not considered the case where a new dependency is added manually and not via poetry add. But I agree with you, poetry should be able to identify when a dependency specified in the pyproject.toml file doesn’t exist in a lock file when running poetry install.

I am interested in the decision to add dependencies manually vs using poetry add. It’s definitely a valid workflow but could you elaborate on why you prefer that workflow?


@KotlinIsland agreed 😆

Read more comments on GitHub >

github_iconTop Results From Across the Web

Warning: The lock file is not up to date with the latest changes ...
I am getting the following error: Warning: The lock file is not up to date with the latest changes in pyproject. toml. You...
Read more >
Commands | master | Documentation | Poetry - Python ...
The install command reads the pyproject.toml file from the current project, resolves the ... and ensure it matches the lock file – use...
Read more >
Dependency Management With Python Poetry
When you run the poetry add command, Poetry automatically updates pyproject.toml and pins the resolved versions in the poetry.lock file. However ...
Read more >
A Poetic Apology. Or Why Should You Use Poetry to Manage…
lock file already exists, if you now run poetry install then Poetry will resolve and install dependencies using the versions specified in such...
Read more >
Dependency scanning fails for setuptools project that ... - GitLab
pyproject.toml is no longer specific to Poetry, so it should be removed from the definition of PackageManagerPoetry . // PackageManagerPoetry ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found