Skip to content

Allow multiple authors in poetry init and poetry new - #11091

Closed
fahadhewad wants to merge 2 commits into
python-poetry:mainfrom
fahadhewad:init-multiple-authors
Closed

fahadhewad wants to merge 2 commits into
python-poetry:mainfrom
fahadhewad:init-multiple-authors

Conversation

@fahadhewad

Copy link
Copy Markdown

Pull Request Check List

Resolves: #8864

Fixes #8864.

The --author option of poetry init was declared as a single value option, so passing it twice kept only the last value, and passing a comma separated list wrote a malformed email address into pyproject.toml. Neither case reported an error.

poetry init -n --name demo --author "Alice <alice@example.com>" --author "Bob <bob@example.com>"

Before this change the command above wrote

authors = [
    {name = "Bob",email = "bob@example.com"}
]

and it now writes

authors = [
    {name = "Alice",email = "alice@example.com"},
    {name = "Bob",email = "bob@example.com"}
]

--author is now declared as a multiple option, the same way --dependency and --dev-dependency already are, and Layout takes a list of authors instead of a single one. poetry new reuses the option from InitCommand, so it accepts several authors as well. In interactive mode only the first author is prompted for, and any further author given on the command line is kept, so runs with a single author behave as before.

  • Added tests for changed code.
  • Updated documentation for changed code.

The --author option was declared as a single value option, so passing it
twice kept only the last value, and passing a comma separated list wrote a
malformed email address into pyproject.toml. Neither case reported an error.

Declare --author as a multiple option, the same way --dependency and
--dev-dependency are declared, and let Layout take a list of authors instead
of one. poetry new reuses the option from InitCommand, so it accepts several
authors too. In interactive mode only the first author is prompted for, and
any further author given on the command line is kept.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/poetry/console/commands/init.py" line_range="173" />
<code_context>
             author = self.ask(question)
-
-        authors = [author] if author else []
+            authors = [author, *authors[1:]] if author else []

         license_name = self.option("license")
</code_context>
<issue_to_address>
**issue (bug_risk):** When an interactive user answers `n` to skip the first author, `authors` is set to an empty list, so every additional author supplied on the command line is discarded instead of being retained.

**Triggers:** When `poetry init` or `poetry new` runs interactively with multiple `--author` options and the user skips the prompted first author.

**Suggested fix:** Preserve the remaining authors in the false branch, for example by assigning `authors = authors[1:]` when `author` is empty.

```suggestion
            authors = [author, *authors[1:]] if author else authors[1:]
```
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 1 finding to address first, and if the author handling is wrong, poetry init or poetry new could write incorrect author metadata into a generated pyproject.toml. Reverting the change would not alter projects already generated, but the metadata is bounded and can be corrected or regenerated.

Blocking findings: src/poetry/console/commands/init.py:173


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread src/poetry/console/commands/init.py Outdated
@dimbleby

Copy link
Copy Markdown
Contributor

#8864 (comment)

Answering n to the interactive author prompt set the author list to empty,
so any further author passed with --author on the command line was dropped.
Only the prompted first author should be skipped.

Drop just the first entry instead, and add a regression test covering an
interactive run that skips the prompted author while a second one is given
on the command line.
@fahadhewad fahadhewad closed this Oct 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

poetry init --author doesn't seem to allow multiple authors on Windows

2 participants