summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnderson Bravalheri <andersonbravalheri@gmail.com>2022-03-25 17:21:24 +0000
committerAnderson Bravalheri <andersonbravalheri@gmail.com>2022-03-25 17:25:27 +0000
commit6b0a021cc772fb67d275407fffaf96895e8be04a (patch)
treed2fccf0c35023d45ab8f4f7e63d3142675f52b8b
parent1a3e1ccee8f740425081863109e26a04d2c10471 (diff)
downloadpython-setuptools-git-6b0a021cc772fb67d275407fffaf96895e8be04a.tar.gz
Disable auto-discovery when the 'configuration' attribute is passed
-rw-r--r--changelog.d/3211.change.rst12
-rw-r--r--setuptools/discovery.py2
-rw-r--r--setuptools/tests/test_config_discovery.py14
3 files changed, 28 insertions, 0 deletions
diff --git a/changelog.d/3211.change.rst b/changelog.d/3211.change.rst
new file mode 100644
index 00000000..a6a9ffb3
--- /dev/null
+++ b/changelog.d/3211.change.rst
@@ -0,0 +1,12 @@
+Disabled auto-discovery when distribution class has a ``configuration`` field
+(e.g. when the ``setup.py`` script contains ``setup(..., configuration=...)``).
+This is done to ensure extension-only packages created with
+``numpy.distutils.misc_util.Configuration`` are not broken by the safe guard
+behaviour to avoid accidental multiple top-level packages in a flat-layout.
+
+**Note** - Users that don't set ``packages``, ``py_modules``, or
+``configuration`` are still likely to observe the auto-discovery behavior,
+which may interrupt the build if the project contains multiple directories and/or
+multiple Python files directly under the project root.
+For projects that don't use the ``[project]`` table in their ``pyproject.toml``
+setting ``ext_modules`` will also disable auto-discovery.
diff --git a/setuptools/discovery.py b/setuptools/discovery.py
index 22f4fc4e..95c3c7f8 100644
--- a/setuptools/discovery.py
+++ b/setuptools/discovery.py
@@ -341,6 +341,8 @@ class ConfigDiscovery:
self.dist.packages is not None
or self.dist.py_modules is not None
or ext_modules
+ or hasattr(self.dist, "configuration") and self.dist.configuration
+ # ^ Some projects use numpy.distutils.misc_util.Configuration
)
def _analyse_package_layout(self, ignore_ext_modules: bool) -> bool:
diff --git a/setuptools/tests/test_config_discovery.py b/setuptools/tests/test_config_discovery.py
index fd5a3239..fac365f4 100644
--- a/setuptools/tests/test_config_discovery.py
+++ b/setuptools/tests/test_config_discovery.py
@@ -494,6 +494,20 @@ class TestWithPackageData:
assert wheel_files >= orig_files
+def test_compatible_with_numpy_configuration(tmp_path):
+ files = [
+ "dir1/__init__.py",
+ "dir2/__init__.py",
+ "file.py",
+ ]
+ _populate_project_dir(tmp_path, files, {})
+ dist = Distribution({})
+ dist.configuration = object()
+ dist.set_defaults()
+ assert dist.py_modules is None
+ assert dist.packages is None
+
+
def _populate_project_dir(root, files, options):
# NOTE: Currently pypa/build will refuse to build the project if no
# `pyproject.toml` or `setup.py` is found. So it is impossible to do