Fix publish --build prompt behavior in non-interactive mode#10769
Conversation
Reviewer's GuideAdjusts the publish command to respect non-interactive mode when build artifacts already exist, and adds a regression test ensuring the confirmation prompt is skipped while the build/publish flow still runs. Sequence diagram for non-interactive publish --build with existing artifactssequenceDiagram
actor User
participant CLI
participant PublishCommand
participant IO
participant Publisher
User->>CLI: poetry publish --build --no-interaction
CLI->>PublishCommand: handle()
PublishCommand->>PublishCommand: option("build") == True
PublishCommand->>Publisher: check files
Publisher-->>PublishCommand: files list (non empty)
PublishCommand->>IO: is_interactive()
IO-->>PublishCommand: False
Note over PublishCommand: Condition publisher.files and IO.is_interactive() fails
PublishCommand->>Publisher: build()
Publisher-->>PublishCommand: build result
PublishCommand->>Publisher: publish()
Publisher-->>PublishCommand: publish result
PublishCommand-->>CLI: exit code 0
CLI-->>User: Command completed without prompt
Flow diagram for publish --build prompt and abort logicflowchart TD
A[Start handle] --> B{option build is True}
B -- No --> Z[Proceed with publish without build]
B -- Yes --> C{publisher.files is non empty}
C -- No --> D[Run build]
D --> E[Run publish]
E --> F[Return success]
C -- Yes --> G{IO is_interactive is True}
G -- No --> D
G -- Yes --> H{confirm Build anyway}
H -- Yes --> D
H -- No --> I[Print Aborted]
I --> J[Return failure]
Z --> E
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="tests/console/commands/test_publish.py" line_range="221-230" />
<code_context>
assert "- Uploading simple_project-1.2.3-py2.py3-none-any.whl" in error
+
+
+def test_publish_build_no_interaction_skips_confirmation(
+ app_tester: ApplicationTester, mocker: MockerFixture
+) -> None:
+ mocker.patch(
+ "poetry.publishing.publisher.Publisher.files",
+ new_callable=PropertyMock,
+ return_value=[Path("dist/simple_project-1.2.3-py2.py3-none-any.whl")],
+ )
+ confirm = mocker.patch("poetry.console.commands.publish.PublishCommand.confirm")
+ command_call = mocker.patch("poetry.console.commands.publish.PublishCommand.call")
+ publisher_publish = mocker.patch("poetry.publishing.Publisher.publish")
+
+ exit_code = app_tester.execute("publish --build --no-interaction --dry-run")
+
+ assert exit_code == 0
+ confirm.assert_not_called()
+ command_call.assert_called_once_with("build", args="--output dist")
+ assert publisher_publish.call_count == 1
</code_context>
<issue_to_address>
**suggestion (testing):** Also assert that the confirmation prompt text is not present in the command output
To better cover the user-facing behavior, please also assert that the confirmation prompt text (e.g. "Build anyway?") does not appear in stdout/stderr when running with `--no-interaction`, by capturing the `app_tester` output as done in other tests.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
Addressed in 8614fbc.
Targeted validation:
|
|
What's the difference between this and #10768? |
|
Great question.
The code path fix is the same, but To avoid split discussion, I’ll close |
8614fbc to
e34c55a
Compare
|
Rebased this branch on the latest Validation in this environment:
No functional changes beyond the rebase. |
|
Pushed follow-up commit What changed
Validation
|
|
Quick follow-up on the red CI:\n\n- The only failing check in the latest run is Windows (Python 3.12) / pytest, with a single failure in ests/utils/env/test_env.py::test_call_does_not_block_on_full_pipe[sys.stderr].\n- I tried to rerun failed jobs, but GitHub rejected it from my account (Must have admin rights to Repository).\n\nI did run focused local validation on this branch:\n- python -m pytest tests/console/commands/test_publish.py::test_publish_build_no_interaction_skips_confirmation -vv ✅\n- python -m pytest tests/console/commands/test_publish.py::test_publish_dist_dir_and_build_options -vv ✅ (3 cases)\n- python -m pytest tests/utils/env/test_env.py::test_call_does_not_block_on_full_pipe[sys.stderr] -vv ✅ (passes locally on Windows/Python 3.14)\n\nGiven the failure pattern (1/2964 tests), this looks potentially environment/flaky rather than a deterministic regression from this patch, but I can investigate further if you want me to chase it specifically under a 3.12 setup. |
|
Pushed follow-up commit What changed
Targeted validation
Both pass locally on this branch. |
publish --build prompt behavior in non-interactive mode
6720290 to
1a0fe5d
Compare
|
Documentation Updates 3 document(s) were updated by changes in this PR: cliView Changes@@ -735,6 +735,12 @@
It can also build the package if you pass it the `--build` option.
{{% note %}}
+When using `--build` with existing artifacts in the dist directory:
+- In interactive mode, Poetry prompts "There are X files ready for publishing in dist. Build anyway?" and waits for confirmation.
+- In non-interactive mode (with `--no-interaction`), Poetry displays a warning message and proceeds with the build without prompting.
+{{% /note %}}
+
+{{% note %}}
See [Publishable Repositories]({{< relref "repositories/#publishable-repositories" >}}) for more information
on how to configure and use publishable repositories.
{{% /note %}}librariesView Changes@@ -116,6 +116,8 @@
If you want to build and publish your packages together,
just pass the `--build` option.
+
+If you run `publish --build` and Poetry finds existing artifacts in the `dist/` directory, it will prompt you in interactive mode asking if you want to build anyway. To skip this prompt in automated environments (like CI/CD), use the `--no-interaction` flag: `poetry publish --build --no-interaction`. In non-interactive mode, Poetry will display a warning about existing artifacts but proceed with rebuilding.
{{% /note %}}
Once this is done, your library will be available to anyone.repositoriesView Changes@@ -105,6 +105,18 @@
poetry publish --build --repository foo-pub
```
+{{% note %}}
+
+If artifacts already exist in the `dist/` directory, Poetry will prompt before rebuilding when running in interactive mode. For CI/CD or automated workflows, add the `--no-interaction` flag to skip the prompt:
+
+```bash
+poetry publish --build --repository foo-pub --no-interaction
+```
+
+In non-interactive mode, Poetry displays a warning about existing artifacts but proceeds with the build and publish.
+
+{{% /note %}}
+
## Package Sources
By default, if you have not configured any primary source, |
(cherry picked from commit 0b81284)
Pull Request Check List
Resolves: #10760
Summary
--no-interactioninpoetry publish --buildwhendist/already contains artifacts.Testing
poetry run pytest tests/console/commands/test_publish.py -qdist/artifacts under non-interactive execution.Summary by Sourcery
Tests:
poetry publish --build --no-interactionskips the confirmation prompt and still performs the build/publish flow when artifacts already exist indist/.