poetry init --author multiple authors fix #8864
Pull Request Check List
Resolves: #8864
Changed Authors option in init.py to multiple=True. This allows the user to input –author name1 –author name2, to the nth author name. This does change the output of this option from a string to a list, which impacts downstream code.
For init.py changed line 151, author, Is now authors as this variable corresponds to a potential list of authors instead of a string. Since we are now handling a list, line 157 has to change the vcs.config author created into a list, so downstream code will work with it.
Updated the is_interactive string, so multiple authors can be displayed (lines 164 to 168). Lines 166 to 169 handle user inputs to the is_interactive. If the user inputs nothing, then displayed authors should stay the same. If user enters “n” then author reverts to defaults. This is defined in the tests, removing this will cause errors where authors in the final file won't be set to defaults. Lines 172 and 173 handle the original line 165. This may be a different issue, not sure if user entering "n" should mean no to current input or no to entering a different author.
The layout function (248 init.py) now takes an entire list of authors, before it only took index 0. This required changes to layout, as it wasn’t coded to handle multiple author inputs.
Updated layout.py to take list inputs, line64, previously it only took str inputs. Added a handle for if user enters multiple or just 1 author as an --author input (lines 88 to 92 layout.py).
Now when creating the layout, a for loop is needed to iterate over the list of multiple authors the only change is wrapping the existing code handling authors in a for loop iterating over each author in the list (lines 148 to 157 layout.py)
In test_init.py added a new test to check for multiple author inputs. Simply copied test_predefined to create a 2 author input. The only change is line 911 and 912, and then changes to the expected output for the check (lines 926 and 927). The remaining code is copied from test_predefined.
Poetry run pytest successfully completes with only a threading error which I think is due to issues with my local environment setup -> tests/utils/test_threading.py::test_threading_atomic_cached_property_different_instances[value_functools_cache-24] - AssertionError: assert 11 == 24
- [x] Added tests for changed code. ------ Only Added 1 new test, that adds 2 authors, existing test check for 1 author, did not test 3 or more authors
- [No] Updated documentation for changed code. ------Code doesn't require a documentation change. Currently --author command is documented, and it seems the method of adding multiple commands (e.g --author name1 --author name2... --author nameX, is standard for these types of commands) Documentation could be added for extra clarification but doesn't seem required currently.
Summary by Sourcery
Enable passing multiple authors to the poetry init --author option by converting internal author handling from a single string to a list, updating prompts and layout generation accordingly, and adding a validation test.
New Features:
- Allow repeated
--authorflags to specify multiple project authors inpoetry init.
Enhancements:
- Refactor
init.pyandlayout.pyto store authors as a list and iterate when building the project configuration. - Update the interactive author prompt to display comma-separated defaults and correctly handle skipping or resetting authors.
Tests:
- Add
test_predefined_2_authorsto verify generation of two authors in the pyproject output.
Reviewer's Guide
This PR converts the single-author init workflow to support multiple --author options end-to-end: the CLI option is updated to collect lists, interactive prompts now display and validate multiple entries, the layout generator normalizes and iterates over author lists when building pyproject.toml, and a new test verifies the behavior.
File-Level Changes
| Change | Details | Files |
|---|---|---|
| Enable multiple --author options in the init command |
|
src/poetry/console/commands/init.py |
| Refactor layout to accept and process author lists |
|
src/poetry/layouts/layout.py |
| Add test for multiple authors in project init |
|
tests/console/commands/test_init.py |
Tips and commands
Interacting with Sourcery
-
Trigger a new review: Comment
@sourcery-ai reviewon the pull request. - Continue discussions: Reply directly to Sourcery's review comments.
-
Generate a GitHub issue from a review comment: Ask Sourcery to create an
issue from a review comment by replying to it. You can also reply to a
review comment with
@sourcery-ai issueto create an issue from it. -
Generate a pull request title: Write
@sourcery-aianywhere in the pull request title to generate a title at any time. You can also comment@sourcery-ai titleon the pull request to (re-)generate the title at any time. -
Generate a pull request summary: Write
@sourcery-ai summaryanywhere in the pull request body to generate a PR summary at any time exactly where you want it. You can also comment@sourcery-ai summaryon the pull request to (re-)generate the summary at any time. -
Generate reviewer's guide: Comment
@sourcery-ai guideon the pull request to (re-)generate the reviewer's guide at any time. -
Resolve all Sourcery comments: Comment
@sourcery-ai resolveon the pull request to resolve all Sourcery comments. Useful if you've already addressed all the comments and don't want to see them anymore. -
Dismiss all Sourcery reviews: Comment
@sourcery-ai dismisson the pull request to dismiss all existing Sourcery reviews. Especially useful if you want to start fresh with a new review - don't forget to comment@sourcery-ai reviewto trigger a new review!
Customizing Your Experience
Access your dashboard to:
- Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others.
- Change the review language.
- Add, remove or edit custom review instructions.
- Adjust other review settings.
Getting Help
- Contact our support team for questions or feedback.
- Visit our documentation for detailed guides and information.
- Keep in touch with the Sourcery team by following us on X/Twitter, LinkedIn or GitHub.