Skip to content

Conversation

@nothing-991
Copy link
Contributor

@nothing-991 nothing-991 commented Jan 2, 2026

Resolves: #8713

Standard Project Structure

Poetry considers a "standard project structure" to be:

project_name/
├── pyproject.toml
├── README.md
├── project_name/
│   └── __init__.py
└── tests/
    └── __init__.py
The top-level directory contains pyproject.toml and README.md.
The main package directory matches the name field in pyproject.toml (or a snake_case variant).
Tests go in a separate tests/ directory.
{{% note %}} If your project matches this layout, Poetry will auto-detect your main package, and you do not need to list it in [tool.poetry.packages]. {{% /note %}}
{{% warning %}} If your project differs from this standard layout — for example, packages inside a lib/ directory, or the top-level package name doesn’t match name in pyproject.toml — you must explicitly list them in [tool.poetry.packages] to include them in your distribution. {{% /warning %}}

## Summary by Sourcery

Documentation:
- Document automatic package detection rules based on normalized project name and supported flat/src layouts in pyproject.md.

@sourcery-ai
Copy link

sourcery-ai bot commented Jan 2, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Updates the pyproject documentation to clarify how Poetry auto-detects packages/modules and when explicit [tool.poetry.packages] configuration is needed, including supported layouts and name normalization rules.

Flow diagram for Poetry package auto-detection rules

graph TD
    A[Start: Project setup] --> B[Read project name from pyproject.toml]
    B --> C[Normalize project name
replace - with _]

    C --> D{Is there a matching
module or package?}

    D -->|Yes| E{Location of matching
module or package}
    D -->|No| H[Packages are not auto-detected
User must configure tool.poetry.packages]

    E --> F{Is it at same level
as pyproject.toml?}
    E --> G{Is it inside src/ directory?}

    F -->|Yes| I[Auto-detect package/module
using flat layout]
    F -->|No| G

    G -->|Yes| J[Auto-detect package/module
using src layout]
    G -->|No| H

    I --> K[Poetry includes detected
package in distribution]
    J --> K
    H --> L[Poetry includes only packages
listed in tool.poetry.packages]

    K --> M[End]
    L --> M
Loading

File-Level Changes

Change Details Files
Clarify automatic package/module detection rules and supported layouts in pyproject documentation, and reword guidance about when to configure [tool.poetry.packages].
  • Reword the description of when to use [tool.poetry.packages] to refer to cases where packages are not automatically detected rather than vaguely "differing from the standard" structure.
  • Add a note explaining that Poetry auto-detects a single module or package whose name matches the normalized project name (with dashes replaced by underscores).
  • Document the allowed locations for the auto-detected module/package: at the same level as pyproject.toml (flat layout) or under src/ (src layout).
docs/pyproject.md

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

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 - I've left some high level feedback:

  • The bash code block for the directory tree isn’t closed before the explanatory sentences and Hugo note/warning shortcodes, so those lines will render as part of the code block instead of normal text and shortcodes—add a closing after the tree and then keep the prose and shortcodes outside.
  • Consider adding a blank line between the directory tree code block and the following explanatory sentences to match the surrounding markdown style and improve readability.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The ```bash code block for the directory tree isn’t closed before the explanatory sentences and Hugo note/warning shortcodes, so those lines will render as part of the code block instead of normal text and shortcodes—add a closing ``` after the tree and then keep the prose and shortcodes outside.
- Consider adding a blank line between the directory tree code block and the following explanatory sentences to match the surrounding markdown style and improve readability.

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.

@nothing-991
Copy link
Contributor Author

Added the snippet detailing the Standard Project Structure in the [tool.poetry.packages] section.
This clarifies when Poetry can auto-detect packages vs. when explicit entries are required.
Updated the PR for review.

@nothing-991
Copy link
Contributor Author

Hi @radoering, I’ve updated the packages section as suggested:
Replaced “If your project structure differs from the standard one” with “If packages are not automatically detected”.
Added clarification about when Poetry can auto-detect packages.
Kept examples for packages, exclude/include, and extras updated for clarity.
All changes are now committed and pushed. Thanks for reviewing!

@nothing-991 nothing-991 force-pushed the docs-standard-project-structure branch from 79434ab to a74ceed Compare January 4, 2026 05:49
@nothing-991
Copy link
Contributor Author

Hi @radoering,
I just wanted to clarify that this PR (docs-standard-project-structure) only contains changes related to the standard project structure documentation.
All commits have been reviewed and cleaned up.
There are no unrelated changes from the contributor guide or other PRs in this branch.
The branch has been force-pushed to remove any accidental commits that were previously present.
Everything in this PR is fully aligned with the intended scope: standard project layout, package auto-detection, and related notes.
Please let me know if you notice anything else that needs adjustment — everything else should be ready for review.
Thanks! 🙏

@radoering
Copy link
Member

Everything in this PR is fully aligned with the intended scope: standard project layout, package auto-detection, and related notes.

It looks like something went wrong. https://github.com/python-poetry/poetry/pull/10680/changes only shows a Contributing to an Existing Poetry Project section in basic-usage.md, which clearly belongs to another PR.

@nothing-991 nothing-991 force-pushed the docs-standard-project-structure branch from b229569 to 2527119 Compare January 8, 2026 06:09
@nothing-991
Copy link
Contributor Author

Hey
I just force-pushed the branch so it now only includes docs/pyproject.md. All other unrelated stuff has been removed—this PR now matches the intended scope. Thanks for taking a look!

@radoering
Copy link
Member

Please always double-check the diff view. Now, almost all explanation about tool.poetry.packages got deleted.

@nothing-991
Copy link
Contributor Author

I’ve reworked the packages section to clearly describe when Poetry automatically detects packages (module/package name matching the project name, flat or src/ layout) and when explicit configuration is required.
The previous wording around “standard project structure” has been removed to avoid over-constraining supported layouts, and the existing configuration examples and notes were kept intact.
Please let me know if you’d like the detection criteria or wording refined further.

@radoering radoering force-pushed the docs-standard-project-structure branch from 351e745 to 8071422 Compare January 16, 2026 15:59
@radoering
Copy link
Member

@sourcery-ai review

@radoering radoering added the impact/docs Contains or requires documentation changes label Jan 16, 2026
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 - I've left some high level feedback:

  • The new note describes auto-detection rules but doesn’t mention how this interacts with the earlier “standard project structure” guidance (e.g., package dir matching the project name, tests/ placement); consider aligning or cross-referencing these sections so users don’t get conflicting mental models.
  • It may help to explicitly call out common non-standard layouts that won’t be auto-detected (e.g., multiple top-level packages, namespace packages, or packages under lib/), so readers know when they must fall back to [tool.poetry.packages].
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new note describes auto-detection rules but doesn’t mention how this interacts with the earlier “standard project structure” guidance (e.g., package dir matching the project name, tests/ placement); consider aligning or cross-referencing these sections so users don’t get conflicting mental models.
- It may help to explicitly call out common non-standard layouts that won’t be auto-detected (e.g., multiple top-level packages, namespace packages, or packages under lib/), so readers know when they must fall back to [tool.poetry.packages].

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.

@github-actions
Copy link

Deploy preview for website ready!

✅ Preview
https://website-ip427xbm0-python-poetry.vercel.app

Built with commit 8071422.
This pull request is being automatically deployed with vercel-action

@radoering radoering changed the title Add explanation of standard project structure (#8713) Explain in which cases packages are automatically detected Jan 16, 2026
@radoering radoering merged commit 91fb81b into python-poetry:main Jan 16, 2026
57 checks passed
@nothing-991 nothing-991 deleted the docs-standard-project-structure branch January 16, 2026 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

impact/docs Contains or requires documentation changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add an explanation of the standard project structure

2 participants