Skip to content

Commit

Permalink
feat(cli): add --markers to add command (#9814)
Browse files Browse the repository at this point in the history
  • Loading branch information
finswimmer authored Oct 30, 2024
1 parent 2b72872 commit 111118a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
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"):
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}" """)

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

0 comments on commit 111118a

Please sign in to comment.