Skip to content

Conversation

@nothing-991
Copy link
Contributor

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

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:
- Add a section describing the recommended standard project layout, including package and tests placement and when explicit [tool.poetry.packages] configuration is required.

@sourcery-ai
Copy link

sourcery-ai bot commented Jan 2, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Documents Poetry’s expected “standard project structure” in the pyproject configuration docs, clarifying when packages can be auto-detected vs. when [tool.poetry.packages] must be explicitly configured.

Flow diagram for Poetry package auto-detection vs explicit configuration

flowchart TD
  A[Start_project_configuration] --> B[Project_matches_standard_structure]
  B -->|Yes| C[Poetry_auto_detects_main_package]
  B -->|No| D[Manually_configure_tool_poetry_packages]

  C --> E[No_need_to_list_packages_in_tool_poetry_packages]
  D --> F[Explicitly_list_all_packages_to_include]

  E --> G[Build_distribution]
  F --> G[Build_distribution]

  G --> H[Verify_included_packages]
Loading

File-Level Changes

Change Details Files
Add a new subsection describing the standard project layout and its implications for Poetry’s package auto-detection.
  • Introduce a ‘Standard Project Structure’ heading in the packages section of the pyproject documentation.
  • Add a tree-style example of the recommended directory layout including project root, package directory, and tests directory.
  • Explain that the main package directory should match the name field in pyproject.toml (or a snake_case variant).
  • Clarify that matching the standard layout allows Poetry to auto-detect the main package without listing it in [tool.poetry.packages].
  • Add a warning that non-standard layouts (e.g., packages under lib/ or mismatched package names) require explicit entries in [tool.poetry.packages] to be included in distributions.
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.

Comment on lines 584 to 595
```bash
project_name/
├── pyproject.toml
├── README.md
├── project_name/
│ └── __init__.py
└── tests/
└── __init__.py
This layout assumes:
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.
Copy link
Member

Choose a reason for hiding this comment

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

On the one side this is incomplete - this is not the only supported layout -, on the other side it contains dispensable information - it does not matter where tests are or if there is a readme).

Here is the code for automatically detecting packages: https://github.com/python-poetry/poetry-core/blob/2548a4c47e172d298c2c34d0e511e5c589397de5/src/poetry/core/masonry/utils/module.py#L38-L70

In words: There must be either a module or a package with the project name (canonicalized and dashes replaced by underscores). This module or package must either be on the level of the pyproject.toml (flat layout) or in a src directory (src layout). Both are "standard layouts" (cf https://packaging.python.org/en/latest/discussions/src-layout-vs-flat-layout/).

We should probably replace

If your project structure differs from the standard one

with

If packages are not automatically detected

and explain in which cases they are automatically detected.

@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!

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.

2 participants