Repository: pypa/setuptools

Issue:
[FR] Deprecate support for custom commands inheriting from distutils
### What's the problem this feature will solve?

From #2849, it is clear that many projects still inherit directly from distutils when creating customised commands.

As per [PEP 632](https://www.python.org/dev/peps/pep-0632/) this practice is deprecated for Python >= 3.10. But even in previous versions, it has been discouraged for a while.

We should encourage people to move away from it, by officially issuing deprecation.

### Describe the solution you'd like

In #2855, a warning message is already being printed, however as discussed in https://github.com/pypa/setuptools/pull/2855#discussion_r743251028, there is a clear advantage in using warnings:

> I'm unsure whether to invoke log.warn here or issue a DeprecationWarning. The latter can be controlled by warnings filters. In any case, I quite like the approach taken here to direct the users away from using distutils, which _is_ deprecated.

_Originally posted by @jaraco

### Alternative Solutions

_No response_

### Additional context

_No response_

### Code of Conduct

- [X] I agree to follow the PSF Code of Conduct


Discussion:

Resolving patch:
diff --git a/setuptools/command/egg_info.py b/setuptools/command/egg_info.py
--- a/setuptools/command/egg_info.py
+++ b/setuptools/command/egg_info.py
@@ -621,10 +621,11 @@ def _safe_data_files(self, build_py):
         if hasattr(build_py, 'get_data_files_without_manifest'):
             return build_py.get_data_files_without_manifest()
 
-        log.warn(
+        warnings.warn(
             "Custom 'build_py' does not implement "
             "'get_data_files_without_manifest'.\nPlease extend command classes"
-            " from setuptools instead of distutils."
+            " from setuptools instead of distutils.",
+            SetuptoolsDeprecationWarning
         )
         return build_py.get_data_files()
 


Test patch:
diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py
--- a/setuptools/tests/test_sdist.py
+++ b/setuptools/tests/test_sdist.py
@@ -11,6 +11,7 @@
 import pytest
 
 import pkg_resources
+from setuptools import SetuptoolsDeprecationWarning
 from setuptools.command.sdist import sdist
 from setuptools.command.egg_info import manifest_maker
 from setuptools.dist import Distribution
@@ -148,8 +149,7 @@ def test_package_data_and_include_package_data_in_sdist(self):
 
         self.assert_package_data_in_manifest(cmd)
 
-    @mock.patch('setuptools.command.egg_info.log')
-    def test_custom_build_py(self, log_stub):
+    def test_custom_build_py(self):
         """
         Ensure projects defining custom build_py don't break
         when creating sdists (issue #2849)
@@ -180,25 +180,13 @@ def get_data_files(self):
         cmd.distribution.cmdclass = {'build_py': CustomBuildPy}
         assert cmd.distribution.get_command_class('build_py') == CustomBuildPy
 
-        with quiet():
+        msg = "setuptools instead of distutils"
+        with quiet(), pytest.warns(SetuptoolsDeprecationWarning, match=msg):
             cmd.run()
 
         using_custom_command_guard.assert_called()
         self.assert_package_data_in_manifest(cmd)
 
-        warn_stub = log_stub.warn
-        warn_stub.assert_called()
-        for call in warn_stub.call_args_list:
-            args, _kw = call
-            if "setuptools instead of distutils" in args[0]:
-                return
-        else:
-            raise AssertionError(
-                "The user should have been warned to extend setuptools command"
-                " classes instead of distutils",
-                warn_stub.call_args_list
-            )
-
     def test_setup_py_exists(self):
         dist = Distribution(SETUP_ATTRS)
         dist.script_name = 'foo.py'