diff --git a/setuptools/discovery.py b/setuptools/discovery.py index 95c3c7f83ed..45f75acafcd 100644 --- a/setuptools/discovery.py +++ b/setuptools/discovery.py @@ -44,12 +44,15 @@ from pathlib import Path from typing import TYPE_CHECKING from typing import Callable, Dict, Iterator, Iterable, List, Optional, Tuple, Union +import warnings import _distutils_hack.override # noqa: F401 from distutils import log from distutils.util import convert_path +import setuptools + _Path = Union[str, os.PathLike] _Filter = Callable[[str], bool] StrIter = Iterator[str] @@ -148,6 +151,13 @@ def _find_iter(cls, where: _Path, exclude: _Filter, include: _Filter) -> StrIter # Should this package be included? if include(package) and not exclude(package): + top_package = package.split(".")[0] + if top_package in FlatLayoutPackageFinder._EXCLUDE: + warnings.warn( + f"{top_package!r} is a reserved package name. " + "Please add it to find_package(exclude=...)", + setuptools.SetuptoolsDeprecationWarning, + ) yield package # Keep searching subdirectories, as there may be more packages