poetry icon indicating copy to clipboard operation
poetry copied to clipboard

feat: add an option to generate a project with package mode = false

Open danielepintore opened this issue 6 months ago • 2 comments

Pull Request Check List

Resolves: #9447

  • [x] Added tests for changed code.
  • [ ] Updated documentation for changed code.

This small pull request adds an option to disable package mode: -N and ----disable-package-mode. When this options are enabled optional field in the pyproject.toml are skipped if the user leaves the default value

Summary by Sourcery

Add a disable-package-mode option to poetry init that marks package-mode as false and skips default optional metadata fields in the generated pyproject.toml

New Features:

  • Add --disable-package-mode (-N) flag to the init command to toggle package mode

Enhancements:

  • Omit default optional fields (version, description, authors) when package mode is disabled

Tests:

  • Cover disable-package-mode behavior in init, including flag recognition and pyproject.toml content adjustments

danielepintore avatar Jul 18 '25 10:07 danielepintore

Reviewer's Guide

Adds a new CLI flag to disable package mode during project initialization, propagates the flag through the init command into the layout generator, and updates the layout to skip optional fields and include package-mode metadata, accompanied by new tests.

Sequence diagram for project initialization with package mode option

sequenceDiagram
    actor User
    participant CLI as Poetry CLI
    participant InitCommand
    participant Layout
    User->>CLI: poetry init -N
    CLI->>InitCommand: parse options (disable-package-mode)
    InitCommand->>Layout: __init__(..., package_mode=False)
    InitCommand->>Layout: generate_project_content()
    Layout-->>InitCommand: project content (skipping optional fields)
    InitCommand-->>CLI: write pyproject.toml

Class diagram for InitCommand and Layout changes

classDiagram
    class InitCommand {
        +_init_pyproject(...)
        +option("disable-package-mode", "-N", ...)
    }
    class Layout {
        +__init__(..., package_mode: bool = True)
        +generate_project_content() TOMLDocument
        -_package_mode: bool
    }
    InitCommand --> Layout : uses

File-Level Changes

Change Details Files
Introduce disable-package-mode option in the init command
  • Add --disable-package-mode (-N) flag to init command options
  • Adjust interactive prompts and default values to clear version when flag is active
  • Pass package_mode boolean from CLI into project layout generation
src/poetry/console/commands/init.py
Extend layout generator to honor package_mode flag
  • Add package_mode parameter to Layout constructor and store in instance
  • Define POETRY_DEFAULT_AUTHOR constant and use it for default author value
  • Remove authors, version, and description entries when package_mode is false
  • Inject package-mode = false into the generated [tool.poetry] section
src/poetry/layouts/layout.py
Add tests for disabling package mode
  • Test long and short flags produce package-mode=false in pyproject.toml
  • Verify optional fields (version, description, authors) are omitted when disabling package mode
  • Ensure author entry with email is preserved correctly even when optional fields are removed
tests/console/commands/test_init.py

Possibly linked issues

  • #9447: The PR implements the --disable-package-mode flag for poetry init to generate the [tool.poetry] layout, directly addressing the issue's request for a classic layout option.
  • #9447: The PR adds a --disable-package-mode option to init, explicitly setting package-mode = false in pyproject.toml, addressing the issue's goal of explicit package declaration.

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

  • 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.

sourcery-ai[bot] avatar Jul 18 '25 10:07 sourcery-ai[bot]

It has not moved forward for a month. If @danielepintore can't finish it, I volunter to take it over.

deronnax avatar Sep 26 '25 11:09 deronnax