Skip to content

Conversation

@kaminskj
Copy link

@kaminskj kaminskj commented May 20, 2025

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

  • 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 --author flags to specify multiple project authors in poetry init.

Enhancements:

  • Refactor init.py and layout.py to 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_authors to verify generation of two authors in the pyproject output.

kaminskj added 17 commits May 13, 2025 08:20
…xample.com>' --author 'Authorname2 <[email protected]>'",

to test multiple author input,
 this is a temporary test for now will likely revert later and just add a second --author call to the original test
…out.py file to handle multiple author inputs still
…any other program still calls layouts, with a string
…but now the initial test isnt working for a seemingly unrealated formatting issue with the expected output
…y i can modify the layout code to handle this
…y i can modify the layout code to handle this
2 authors are getting added in the correct format, but I still have some format issues in the testing file expected output but almost there
     if author == author_str:
                author = ""
This handles if user simply hits enter no input

            if author is None:
                authors = author
This is if the user enter "n" as other tests error out for author not being set to the defaults instead otherwise this will be set to the vcs_config values

        authors = [author] if author else authors
This handles if a user enters 1 author, this will then be added
…and both still work, did not run entire test suite
…eleted an extra line in test_init.py that was flagged as a change from main poetry file.
@sourcery-ai
Copy link

sourcery-ai bot commented May 20, 2025

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
  • Set author option to multiple=True
  • Rename author variable to authors and handle default VCS user as list
  • Join authors for prompt display and adjust validator to accept lists
  • Implement skip and no-change logic for interactive inputs
  • Pass full authors list instead of single entry to layout
src/poetry/console/commands/init.py
Refactor layout to accept and process author lists
  • Change constructor signature to accept str or list[str]
  • Normalize author input to a list in init
  • Replace single-author regex parse with loop over authors
src/poetry/layouts/layout.py
Add test for multiple authors in project init
  • Introduce test_predefined_2_authors verifying two authors render correctly
  • Update expected TOML output block to list both authors
tests/console/commands/test_init.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on 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 issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on 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 dismiss on 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 review to 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

@kaminskj kaminskj changed the title poetry init --author doesn't seem to allow multiple authors on Windows #8864 poetry init --author multiple authors #8864 May 20, 2025
@kaminskj kaminskj changed the title poetry init --author multiple authors #8864 poetry init --author multiple authors fix #8864 May 20, 2025
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @kaminskj - I've reviewed your changes - here's some feedback:

  • The interactive prompt logic around distinguishing empty input, skip (n), and updating the authors list is quite complex—consider refactoring it so it clearly handles those three cases without string‐comparison hacks.
  • You only added a test for two --author flags; add a test for three (or more) authors to confirm unlimited multiple‐author support works as expected.
  • In init.py, the mix of variables named author and authors is confusing—consider a clearer naming scheme or separating singular vs. plural flows to reduce ambiguity.
Here's what I looked at during the review
  • 🟡 General issues: 3 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Documentation: all looks good

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.

self._dependencies = dependencies or {}
self._dev_dependencies = dev_dependencies or {}

if not author:
Copy link

Choose a reason for hiding this comment

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

suggestion (bug_risk): Prefer checking for None over falsy author

Use if author is None: so empty strings or lists aren’t treated as missing.

Suggested change
if not author:
if author is None:


authors = [author] if author else []
authors = [author] if author else authors # checks if author = None or ""
authors = authors if authors else []
Copy link

Choose a reason for hiding this comment

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

suggestion (code-quality): Replace if-expression with or (or-if-exp-identity)

Suggested change
authors = authors if authors else []
authors = authors or []


ExplanationHere we find ourselves setting a value if it evaluates to True, and otherwise
using a default.

The 'After' case is a bit easier to read and avoids the duplication of
input_currency.

It works because the left-hand side is evaluated first. If it evaluates to
true then currency will be set to this and the right-hand side will not be
evaluated. If it evaluates to false the right-hand side will be evaluated and
currency will be set to DEFAULT_CURRENCY.

version,
description=description,
author=authors[0] if authors else None,
author=authors if authors else None,
Copy link

Choose a reason for hiding this comment

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

suggestion (code-quality): Replace if-expression with or (or-if-exp-identity)

Suggested change
author=authors if authors else None,
author=authors or None,


ExplanationHere we find ourselves setting a value if it evaluates to True, and otherwise
using a default.

The 'After' case is a bit easier to read and avoids the duplication of
input_currency.

It works because the left-hand side is evaluated first. If it evaluates to
true then currency will be set to this and the right-hand side will not be
evaluated. If it evaluates to false the right-hand side will be evaluated and
currency will be set to DEFAULT_CURRENCY.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @kaminskj - I've reviewed your changes - here's some feedback:

  • In layout.py init, use if author is None instead of a falsy check so that an explicit empty list isn’t overridden by the default author.
  • The interactive prompt logic in init.py is a bit tangled—consider simplifying how you distinguish between empty input, ‘n’ (skip), and preserving the existing authors array to avoid assigning None or an empty string inadvertently.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Documentation: all looks good

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.


authors = [author] if author else []
authors = [author] if author else authors # checks if author = None or ""
authors = authors if authors else []
Copy link

Choose a reason for hiding this comment

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

suggestion (code-quality): Replace if-expression with or (or-if-exp-identity)

Suggested change
authors = authors if authors else []
authors = authors or []


ExplanationHere we find ourselves setting a value if it evaluates to True, and otherwise
using a default.

The 'After' case is a bit easier to read and avoids the duplication of
input_currency.

It works because the left-hand side is evaluated first. If it evaluates to
true then currency will be set to this and the right-hand side will not be
evaluated. If it evaluates to false the right-hand side will be evaluated and
currency will be set to DEFAULT_CURRENCY.

version,
description=description,
author=authors[0] if authors else None,
author=authors if authors else None,
Copy link

Choose a reason for hiding this comment

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

suggestion (code-quality): Replace if-expression with or (or-if-exp-identity)

Suggested change
author=authors if authors else None,
author=authors or None,


ExplanationHere we find ourselves setting a value if it evaluates to True, and otherwise
using a default.

The 'After' case is a bit easier to read and avoids the duplication of
input_currency.

It works because the left-hand side is evaluated first. If it evaluates to
true then currency will be set to this and the right-hand side will not be
evaluated. If it evaluates to false the right-hand side will be evaluated and
currency will be set to DEFAULT_CURRENCY.

kaminskj and others added 8 commits May 25, 2025 10:15
…pre-commit. mypy found no issues, pre-commit found issue fix-end-of-file but for files i didnt edit.
…rwritted

"N" means set author to the default strings
a author nae means set author to the user input
… is_interactive and vcs_config if statements.
ran code linter for new changes, and cleaned up conditional statements. Currenntly pytest ends OK
Copy link
Member

@radoering radoering left a comment

Choose a reason for hiding this comment

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

So we can set multiple authors via --author but we cannot set them interactively, can we? (Although this is a bit inconsistent, we can also define it as "out of scope" for this PR.)

question.set_validator(lambda v: self._validate_author(v, authors))
author = self.ask(question)
if author == author_str: # user entered nothing, dont change authors
author = ""
Copy link
Member

Choose a reason for hiding this comment

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

It looks like author is not used after this line. Why do we set it here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Why not introduce a new --authors flag for multiple authors?

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

3 participants