feat(init): allow multiple author options#10939
Open
Yijian6 wants to merge 2 commits into
Open
Conversation
There was a problem hiding this comment.
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 parsingpyproject.tomlwith tomlkit and asserting on the data structure instead. - The author/authors resolution logic in
_init_pyproject(initialauthors = self.option("author"), derivingauthor, interactive override, then reconcilingauthorsagain) is a bit convoluted; consider refactoring to build a singleauthorslist 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>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
--authoroptions forpoetry initandpoetry newContext
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