feat: add an option to generate a project with package mode = false
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
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 |
|
src/poetry/console/commands/init.py |
| Extend layout generator to honor package_mode flag |
|
src/poetry/layouts/layout.py |
| Add tests for disabling package mode |
|
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 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.
It has not moved forward for a month. If @danielepintore can't finish it, I volunter to take it over.