Skip to content

Commit 9b81749

Browse files
radoeringSecrus
authored andcommitted
docs: improve explanation of exclude and include (python-poetry#9734)
1 parent 5065482 commit 9b81749

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

docs/pyproject.md

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -622,43 +622,53 @@ Poetry is clever enough to detect Python subpackages.
622622
Thus, you only have to specify the directory where your root package resides.
623623
{{% /note %}}
624624

625-
### include and exclude
625+
### exclude and include
626626

627-
A list of patterns that will be included in the final package.
627+
{{% note %}}
628+
If you just want to include a package or module, which is not picked up automatically,
629+
use [packages]({{< relref "#packages" >}}) instead of `include`.
630+
{{% /note %}}
631+
632+
A list of patterns that will be excluded or included in the final package.
633+
634+
```toml
635+
[tool.poetry]
636+
# ...
637+
exclude = ["my_package/excluded.py"]
638+
include = ["CHANGELOG.md"]
639+
```
628640

629641
You can explicitly specify to Poetry that a set of globs should be ignored or included for the purposes of packaging.
630642
The globs specified in the exclude field identify a set of files that are not included when a package is built.
643+
`include` has priority over `exclude`.
631644

632645
If a VCS is being used for a package, the exclude field will be seeded with the VCS’ ignore settings (`.gitignore` for git for example).
633646

634647
{{% note %}}
635648
Explicitly declaring entries in `include` will negate VCS' ignore settings.
636649
{{% /note %}}
637650

638-
```toml
639-
[tool.poetry]
640-
# ...
641-
include = ["CHANGELOG.md"]
642-
```
643-
644651
You can also specify the formats for which these patterns have to be included, as shown here:
645652

646653
```toml
647654
[tool.poetry]
648655
# ...
649656
include = [
650657
{ path = "tests", format = "sdist" },
651-
{ path = "for_wheel.txt", format = ["sdist", "wheel"] }
658+
{ path = "my_package/for_sdist_and_wheel.txt", format = ["sdist", "wheel"] }
652659
]
653660
```
654661

655662
If no format is specified, `include` defaults to only `sdist`.
656663

657664
In contrast, `exclude` defaults to both `sdist` and `wheel`.
658665

659-
```toml
660-
exclude = ["my_package/excluded.py"]
661-
```
666+
{{% warning %}}
667+
When a wheel is installed, its includes are unpacked straight into the `site-packages` directory.
668+
Pay attention to include top level files and directories with common names like
669+
`CHANGELOG.md`, `LICENSE`, `tests` or `docs` only in sdists and **not** in wheels.
670+
{{% /warning %}}
671+
662672

663673
### dependencies and dependency groups
664674

poetry.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)