Skip to content
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

feat(cli): add --markers to add command #9814

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ about dependency groups.
* `--optional`: Add as an optional dependency to an extra.
* `--python`: Python version for which the dependency must be installed.
* `--platform`: Platforms for which the dependency must be installed.
* `--markers`: Environment markers which describe when the dependency should be installed.
* `--source`: Name of the source to use to install the package.
* `--allow-prereleases`: Accept prereleases.
* `--dry-run`: Output the operations but do not execute anything (implicitly enables `--verbose`).
Expand Down
9 changes: 9 additions & 0 deletions src/poetry/console/commands/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ class AddCommand(InstallerCommand, InitCommand):
"Platforms for which the dependency must be installed.",
flag=False,
),
option(
"markers",
None,
"Environment markers which describe when the dependency should be installed.",
flag=False,
),
option(
"source",
None,
Expand Down Expand Up @@ -263,6 +269,9 @@ def handle(self) -> int:
if self.option("platform"):
constraint["platform"] = self.option("platform")

if self.option("markers"):
Secrus marked this conversation as resolved.
Show resolved Hide resolved
constraint["markers"] = self.option("markers")

if self.option("source"):
constraint["source"] = self.option("source")

Expand Down
12 changes: 12 additions & 0 deletions tests/console/commands/test_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,18 @@ def test_add_constraint_dependencies(tester: CommandTester) -> None:
assert tester.command.installer.executor.installations_count == 2


def test_add_with_markers(app: PoetryTestApplication, tester: CommandTester) -> None:
marker = "python_version <= '3.4' or sys_platform == 'win32'"
tester.execute(f"""cachy --markers "{marker}" """)
Secrus marked this conversation as resolved.
Show resolved Hide resolved

pyproject: dict[str, Any] = app.poetry.file.read()
content = pyproject["tool"]["poetry"]

assert "cachy" in content["dependencies"]
assert content["dependencies"]["cachy"]["version"] == "^0.2.0"
assert content["dependencies"]["cachy"]["markers"] == marker


def test_add_git_constraint(
app: PoetryTestApplication,
tester: CommandTester,
Expand Down
Loading