Skip to content

feat(init): allow multiple author options#10939

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

feat(init): allow multiple author options#10939
Yijian6 wants to merge 2 commits into
python-poetry:mainfrom
Yijian6:init-multiple-authors

Conversation

@Yijian6

@Yijian6 Yijian6 commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Summary

  • allow repeated --author options for poetry init and poetry new
  • preserve the existing single-author interactive flow
  • document the repeatable option in the CLI reference

Context

Relates-to: #8864.

Tests

  • .venv\Scripts\python.exe -m pytest tests/console/commands/test_init.py tests/console/commands/test_new.py -q
  • .venv\Scripts\python.exe -m ruff check src/poetry/console/commands/init.py src/poetry/layouts/layout.py tests/console/commands/test_init.py tests/console/commands/test_new.py
  • .venv\Scripts\python.exe -m mypy src/poetry/console/commands/init.py src/poetry/layouts/layout.py tests/console/commands/test_init.py tests/console/commands/test_new.py

@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 2 issues, and left some high level feedback:

  • The new tests for multiple authors assert raw TOML snippets including exact spacing (e.g. {name = "Foo Bar",email = ...}), which is brittle to formatting changes; consider parsing pyproject.toml with tomlkit and asserting on the data structure instead.
  • The author/authors resolution logic in _init_pyproject (initial authors = self.option("author"), deriving author, interactive override, then reconciling authors again) is a bit convoluted; consider refactoring to build a single authors list in one place to make the flow and edge cases (e.g. skip, VCS defaults, multiple flags) clearer.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new tests for multiple authors assert raw TOML snippets including exact spacing (e.g. `{name = "Foo Bar",email = ...}`), which is brittle to formatting changes; consider parsing `pyproject.toml` with tomlkit and asserting on the data structure instead.
- The author/authors resolution logic in `_init_pyproject` (initial `authors = self.option("author")`, deriving `author`, interactive override, then reconciling `authors` again) is a bit convoluted; consider refactoring to build a single `authors` list in one place to make the flow and edge cases (e.g. skip, VCS defaults, multiple flags) clearer.

## Individual Comments

### Comment 1
<location path="tests/console/commands/test_init.py" line_range="882-891" />
<code_context>
     assert expected in output


+def test_noninteractive_multiple_authors(
+    tester: CommandTester, source_dir: Path
+) -> None:
+    tester.execute(
+        "--name my-package "
+        "--author 'Foo Bar <foo@example.com>' "
+        "--author 'Baz Qux <baz@example.com>'",
+        interactive=False,
+    )
+
+    expected = """\
+authors = [
+    {name = "Foo Bar",email = "foo@example.com"},
+    {name = "Baz Qux",email = "baz@example.com"}
+]
+"""
+
+    pyproject_file = source_dir / "pyproject.toml"
+    assert expected in pyproject_file.read_text(encoding="utf-8")
+
+
</code_context>
<issue_to_address>
**suggestion (testing):** Avoid brittle string matching for authors in pyproject; parse TOML and assert on the data structure instead.

This test asserts against a verbatim `authors` block, so any change in TOML formatting (spaces, line breaks, ordering) will cause a failure even if the authors are correct. Instead, read and parse `pyproject.toml` (e.g. with `tomllib`/`tomli` or Poetry’s TOML helpers) and assert on the parsed `project["authors"]` structure—comparing the list of name/email dicts or at least the extracted names/emails—so the test validates semantics rather than serialization details.

Suggested implementation:

```python
def test_noninteractive_multiple_authors(
    tester: CommandTester, source_dir: Path
) -> None:
    tester.execute(
        "--name my-package "
        "--author 'Foo Bar <foo@example.com>' "
        "--author 'Baz Qux <baz@example.com>'",
        interactive=False,
    )

    pyproject_file = source_dir / "pyproject.toml"
    content = pyproject_file.read_text(encoding="utf-8")

    data = tomllib.loads(content)
    authors = data["project"]["authors"]

    assert authors == [
        {"name": "Foo Bar", "email": "foo@example.com"},
        {"name": "Baz Qux", "email": "baz@example.com"},
    ]

```

You’ll also need to ensure TOML parsing is available and imported at the top of this test module, following the project’s existing convention. For example, either:
- `import tomllib` (Python 3.11+), or
- `import tomli as tomllib`, or
- use any existing Poetry/project TOML helper already used elsewhere in the tests and adjust `tomllib.loads` accordingly.
</issue_to_address>

### Comment 2
<location path="docs/cli.md" line_range="470" />
<code_context>
-* `--author`: Author of the package.
+* `--author`: Author of the package. Can be specified multiple times.
 * `--python` Compatible Python versions.
 * `--dependency`: Package to require with a version constraint. Should be in format `foo:1.0.0`.
 * `--dev-dependency`: Development requirements, see `--dependency`.
</code_context>
<issue_to_address>
**nitpick (typo):** Minor grammar tweak: "in the format" reads more naturally here.

Suggested implementation:

```
* `--dependency`: Package to require with a version constraint. Should be in the format `foo:1.0.0`.

```

```
* `--dependency`: Package to require with a version constraint. Should be in the format `foo:1.0.0`.

```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread tests/console/commands/test_init.py
Comment thread docs/cli.md Outdated
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.

1 participant