-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
option to fail if poetry.lock
doesn't match pyproject.toml
#5003
Comments
In my opinion, this feature would be counterintuitive and it wouldn't add much value. Lock files are used as the ultimate source of truth when installing/updating your project's dependencies. The fact that a lock file exists in your project, and that it's contents contain older or outdated versions of dependencies is perfectly valid and should never be considered an error. I think adding a command line option to remove the assertions made by a lock file would be confusing. The way I see it, poetry already gives you the tools to figure out if your locked environment is out of date. For example, you could update your CI to run |
I disagree. If I change/add a dependency in
I’m not asking for an option to remove the lock file’s assertions, only an option to fail if |
poetry.lock
is out of datepoetry.lock
doesn't match pyproject.toml
No, if you choose to commit your lock file this is not unexpected behavior and it's certainly not an error. As per the documentation...
It looks like the authors are pretty clear about the intended behavior-- if you don't want this behavior, don't commit your lock file. And this already happens...
If the version of a dependency in the lock file does not satisfy the constraints specified in the The example below shows that behavior...
🐟 ➜ poetry new test
Created package test in test
🐟 ➜ cd test/
🐟 ➜ poetry add "requests@<2.20.0"
Creating virtualenv test-CZsUjjpm-py3.9 in XXX
Updating dependencies
Resolving dependencies... (0.4s)
Writing lock file
Package operations: 13 installs, 0 updates, 0 removals
• Installing pyparsing (3.0.6)
• Installing attrs (21.4.0)
• Installing certifi (2021.10.8)
• Installing chardet (3.0.4)
• Installing idna (2.7)
• Installing more-itertools (8.12.0)
• Installing packaging (21.3)
• Installing pluggy (0.13.1)
• Installing py (1.11.0)
• Installing urllib3 (1.23)
• Installing wcwidth (0.2.5)
• Installing pytest (5.4.3)
• Installing requests (2.19.1)
🐟 ➜ sed -i '' "s/<2.20.0/>2.25.0/g" pyproject.toml
🐟 ➜ poetry install
Installing dependencies from lock file
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.
SolverProblemError
Because test depends on requests (>2.25.0) which doesn't match any versions, version solving failed.
at ~/Library/Application Support/pypoetry/venv/lib/python3.9/site-packages/poetry/puzzle/solver.py:241 in _solve
237│ packages = result.packages
238│ except OverrideNeeded as e:
239│ return self.solve_in_compatibility_mode(e.overrides, use_latest=use_latest)
240│ except SolveFailure as e:
→ 241│ raise SolverProblemError(e)
242│
243│ results = dict(
244│ depth_first_search(
245│ PackageNode(self._package, packages), aggregate_package_nodes
🐟 ➜ sed -i '' "s/>2.25.0/^2.0/g" pyproject.toml
🐟 ➜ poetry install
Installing dependencies from lock file
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.
No dependencies to install or update
Installing the current project: test (0.1.0) |
The |
This is great, but you're right in that it doesn't address OP's original issue. The dependencies in a lock file can satisfy the constraints specified in the To solve the original problem, I think the best approach is a combination of |
i just ran i just tried |
> poetry install
Installing dependencies from lock file
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.
SolverProblemError
Because test depends on flake8 (*) which doesn't match any versions, version solving failed.
at ~/.local/pipx/venvs/poetry/lib/python3.11/site-packages/poetry/puzzle/solver.py:241 in _solve
237│ packages = result.packages
238│ except OverrideNeeded as e:
239│ return self.solve_in_compatibility_mode(e.overrides, use_latest=use_latest)
240│ except SolveFailure as e:
→ 241│ raise SolverProblemError(e)
242│
243│ results = dict(
244│ depth_first_search(
245│ PackageNode(self._package, packages), aggregate_package_nodes That error message drove me insane! What a deeply confusing message, as it's using the version number from my pyproject file, but matching it against the lock file? Or at the bare minimum change the current error message to say where it's looking: - Because test depends on flake8 (*) which doesn't match any versions, version solving failed.
+ Because test depends on flake8 (*) which doesn't match any versions in the lock file, version solving failed. |
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 I am interested in the decision to add dependencies manually vs using @KotlinIsland agreed 😆 |
In general i find it easier to modify config files directly so I don’t have to go through the cli |
I normally use the UI of PyCharm which doesn't have a |
…sync. I'd like to ensure that when I'm using 'poetry install' in a CI pipeline that the lock file is up to date. This is possible at present by using: poetry lock --check && poetry install ... But I think it's a common enough use that providing it within the install command is still useful. Fixes python-poetry#5003. Currently, it emits a warning message
…sync. I'd like to ensure that when I'm using 'poetry install' in a CI pipeline that the lock file is up to date. This is possible at present by using: poetry lock --check && poetry install ... But I think it's a common enough use that providing it within the install command is still useful. Fixes python-poetry#5003.
I'm with @DetachHead on this issue to have it as a flag on @ashokdelphia has made a good first step MR |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
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: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
The text was updated successfully, but these errors were encountered: