-
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
introduce sync
command
#9801
base: main
Are you sure you want to change the base?
introduce sync
command
#9801
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,6 +63,7 @@ def _load() -> Command: | |
"run", | ||
"search", | ||
"show", | ||
"sync", | ||
"update", | ||
"version", | ||
# Cache commands | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
from typing import ClassVar | ||
|
||
from poetry.console.commands.install import InstallCommand | ||
|
||
|
||
if TYPE_CHECKING: | ||
from cleo.io.inputs.option import Option | ||
|
||
|
||
class SyncCommand(InstallCommand): | ||
name = "sync" | ||
description = "Update the project's environment according to the lockfile." | ||
|
||
options: ClassVar[list[Option]] = [ | ||
opt for opt in InstallCommand.options if opt.name != "sync" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we are introducing it as a command, maybe we could remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I want to avoid this breaking change because it would break a lot of CI scripts. (Most of our other breaking changes are not really relevant for most users or at least not relevant for CI.) But we can deprecate it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, let's deprecate it, but with a set date (June 2025 sounds reasonable). I'd like us to avoid a long-living deprecation we are stuck with forever. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, there is also Option a) Do not deprecate |
||
] | ||
|
||
help = """\ | ||
The <info>sync</info> command makes sure that the project's environment is in sync with | ||
the <comment>poetry.lock</> file. | ||
It is equivalent to running <info>poetry install --sync</info>. | ||
<info>poetry sync</info> | ||
By default, the above command will also install the current project. To install only the | ||
dependencies and not including the current project, run the command with the | ||
<info>--no-root</info> option like below: | ||
<info> poetry sync --no-root</info> | ||
If you want to use Poetry only for dependency management but not for packaging, | ||
you can set the "package-mode" to false in your pyproject.toml file. | ||
""" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
import pytest | ||
|
||
from cleo.exceptions import CleoNoSuchOptionError | ||
|
||
# import all tests from the install command | ||
# and run them for sync by overriding the command fixture | ||
from tests.console.commands.test_install import * # noqa: F403 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a nitpick to satisfy the mind goblins: I hate that we have to do that like this, but I don't see any better way. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dito. |
||
|
||
|
||
if TYPE_CHECKING: | ||
from cleo.testers.command_tester import CommandTester | ||
|
||
|
||
@pytest.fixture # type: ignore[no-redef] | ||
def command() -> str: | ||
return "sync" | ||
|
||
|
||
@pytest.mark.skip("Only relevant for `poetry install`") # type: ignore[no-redef] | ||
def test_sync_option_is_passed_to_the_installer() -> None: | ||
"""The only test from the install command that does not work for sync.""" | ||
|
||
|
||
def test_sync_option_not_available(tester: CommandTester) -> None: | ||
with pytest.raises(CleoNoSuchOptionError): | ||
tester.execute("--sync") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would avoid the direct reference to
poetry install
here. Explanation and an options list like for other commands, would be more open-ended and wouldn't be considered "breaking" if we decide to splitinstall
andsync
even more in the future.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I thought that too. I have just been too lazy so far, but I will make up for it.