Skip to content

Commit 2527119

Browse files
committed
docs: clarify automatic package detection
1 parent 5e1fd5e commit 2527119

1 file changed

Lines changed: 10 additions & 62 deletions

File tree

docs/pyproject.md

Lines changed: 10 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -574,74 +574,22 @@ based on the `python` requirement, use `project.classifiers` instead of this set
574574

575575
A list of packages and modules to include in the final distribution.
576576

577-
If your project structure differs from the standard one supported by `poetry`,
578-
you can specify the packages you want to include in the final distribution.
577+
Poetry can automatically detect your package without requiring `[tool.poetry.packages]` in common cases.
579578

580-
```toml
581-
[tool.poetry]
582-
# ...
583-
packages = [
584-
{ include = "my_package" },
585-
{ include = "extra_package/**/*.py" },
586-
]
587-
```
588-
589-
If your package is stored inside a "lib" directory, you must specify it:
590-
591-
```toml
592-
[tool.poetry]
593-
# ...
594-
packages = [
595-
{ include = "my_package", from = "lib" },
596-
]
597-
```
598-
599-
The `to` parameter is designed to specify the relative destination path
600-
where the package will be located upon installation. This allows for
601-
greater control over the organization of packages within your project's structure.
602-
603-
```toml
604-
[tool.poetry]
605-
# ...
606-
packages = [
607-
{ include = "my_package", from = "lib", to = "target_package" },
608-
]
609-
```
579+
### Automatic package detection
610580

611-
If you want to restrict a package to a specific build format, you can specify
612-
it by using `format`:
581+
Poetry can automatically detect packages if there exists either a **module** or a **package**
582+
whose name matches the project name (canonicalized: lowercase, with `-` replaced by `_`).
613583

614-
```toml
615-
[tool.poetry]
616-
# ...
617-
packages = [
618-
{ include = "my_package" },
619-
{ include = "my_other_package", format = "sdist" },
620-
]
621-
```
584+
The detected module or package must be located in one of the following places:
622585

623-
From now on, only the `sdist` build archive will include the `my_other_package` package.
624-
625-
{{% note %}}
626-
Using `packages` disables the package auto-detection feature meaning you have to
627-
**explicitly** specify the "default" package.
586+
- **Flat layout:** at the same level as `pyproject.toml`
587+
- **Src layout:** inside a `src/` directory
628588

629-
For instance, if you have a package named `my_package` and you want to also include
630-
another package named `extra_package`, you will need to specify `my_package` explicitly:
589+
These two layouts are considered the standard layouts.
631590

632-
```toml
633-
packages = [
634-
{ include = "my_package" },
635-
{ include = "extra_package" },
636-
]
637-
```
638-
{{% /note %}}
639-
640-
{{% note %}}
641-
Poetry is clever enough to detect Python subpackages.
642-
643-
Thus, you only have to specify the directory where your root package resides.
644-
{{% /note %}}
591+
If packages are not automatically detected, you must explicitly define them using
592+
[`tool.poetry.packages`](#packages).
645593

646594
### exclude and include
647595

0 commit comments

Comments
 (0)