Imported Upstream version 58.5.3 upstream/58.5.3
authorJinWang An <jinwang.an@samsung.com>
Mon, 27 Mar 2023 08:02:38 +0000 (17:02 +0900)
committerJinWang An <jinwang.an@samsung.com>
Mon, 27 Mar 2023 08:02:38 +0000 (17:02 +0900)
.bumpversion.cfg
CHANGES.rst
setup.cfg
setuptools/command/egg_info.py
setuptools/tests/test_sdist.py

index ce559b120f474e55bb03b9dbe4422b57b532bab1..fe2b8e3e6d3c85bd712e90d5790e946d8f8bb70b 100644 (file)
@@ -1,5 +1,5 @@
 [bumpversion]
-current_version = 58.5.2
+current_version = 58.5.3
 commit = True
 tag = True
 
index 67d62ccb1709bc7aeeeb6e9c252828e0b1872d94..72856165bade29e9f9d2aa4792cd3d981ab9ae30 100644 (file)
@@ -1,3 +1,14 @@
+v58.5.3
+-------
+
+
+Misc
+^^^^
+* #2849: Add fallback for custom ``build_py`` commands inheriting directly from
+  :mod:`distutils`, while still handling ``include_package_data=True`` for
+  ``sdist``.
+
+
 v58.5.2
 -------
 
@@ -13,7 +24,7 @@ v58.5.1
 
 Misc
 ^^^^
-* #2486: Move PkgResourcesDeprecationWarning above implicitly-called function so that it's in the namespace when version warnings are generated in an environment that contains them.
+* #2846: Move PkgResourcesDeprecationWarning above implicitly-called function so that it's in the namespace when version warnings are generated in an environment that contains them.
 
 
 v58.5.0
index 631f097cc670d59b86544486a4c841a08b326d5e..fdaf6c04aeb759a9cfccaaffac85ecdec5ec84cb 100644 (file)
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,6 +1,6 @@
 [metadata]
 name = setuptools
-version = 58.5.2
+version = 58.5.3
 author = Python Packaging Authority
 author_email = distutils-sig@python.org
 description = Easily download, build, install, upgrade, and uninstall Python packages
index 4165c35e9f6553d6f456f0d91fcdb5154bf5778b..8ae27d87beb16c4fbc0b0233da4811c8dcad3312 100644 (file)
@@ -618,7 +618,15 @@ class manifest_maker(sdist):
         Therefore, avoid triggering any attempt of
         analyzing/building the manifest again.
         """
-        return build_py.get_data_files_without_manifest()
+        if hasattr(build_py, 'get_data_files_without_manifest'):
+            return build_py.get_data_files_without_manifest()
+
+        log.warn(
+            "Custom 'build_py' does not implement "
+            "'get_data_files_without_manifest'.\nPlease extend command classes"
+            " from setuptools instead of distutils."
+        )
+        return build_py.get_data_files()
 
 
 def write_file(filename, contents):
index 34c32bb010f7c85b9ec2bfcb708d34140cb702ee..e6d8e9081477bad2089c5ed73055811fd1dc9dfc 100644 (file)
@@ -6,6 +6,7 @@ import tempfile
 import unicodedata
 import contextlib
 import io
+from unittest import mock
 
 import pytest
 
@@ -106,6 +107,13 @@ class TestSdistTest:
         with tmpdir.as_cwd():
             yield
 
+    def assert_package_data_in_manifest(self, cmd):
+        manifest = cmd.filelist.files
+        assert os.path.join('sdist_test', 'a.txt') in manifest
+        assert os.path.join('sdist_test', 'b.txt') in manifest
+        assert os.path.join('sdist_test', 'c.rst') not in manifest
+        assert os.path.join('d', 'e.dat') in manifest
+
     def test_package_data_in_sdist(self):
         """Regression test for pull request #4: ensures that files listed in
         package_data are included in the manifest even if they're not added to
@@ -120,11 +128,7 @@ class TestSdistTest:
         with quiet():
             cmd.run()
 
-        manifest = cmd.filelist.files
-        assert os.path.join('sdist_test', 'a.txt') in manifest
-        assert os.path.join('sdist_test', 'b.txt') in manifest
-        assert os.path.join('sdist_test', 'c.rst') not in manifest
-        assert os.path.join('d', 'e.dat') in manifest
+        self.assert_package_data_in_manifest(cmd)
 
     def test_package_data_and_include_package_data_in_sdist(self):
         """
@@ -142,11 +146,58 @@ class TestSdistTest:
         with quiet():
             cmd.run()
 
-        manifest = cmd.filelist.files
-        assert os.path.join('sdist_test', 'a.txt') in manifest
-        assert os.path.join('sdist_test', 'b.txt') in manifest
-        assert os.path.join('sdist_test', 'c.rst') not in manifest
-        assert os.path.join('d', 'e.dat') in manifest
+        self.assert_package_data_in_manifest(cmd)
+
+    @mock.patch('setuptools.command.egg_info.log')
+    def test_custom_build_py(self, log_stub):
+        """
+        Ensure projects defining custom build_py don't break
+        when creating sdists (issue #2849)
+        """
+        from distutils.command.build_py import build_py as OrigBuildPy
+
+        using_custom_command_guard = mock.Mock()
+
+        class CustomBuildPy(OrigBuildPy):
+            """
+            Some projects have custom commands inheriting from `distutils`
+            """
+
+            def get_data_files(self):
+                using_custom_command_guard()
+                return super().get_data_files()
+
+        setup_attrs = {**SETUP_ATTRS, 'include_package_data': True}
+        assert setup_attrs['package_data']
+
+        dist = Distribution(setup_attrs)
+        dist.script_name = 'setup.py'
+        cmd = sdist(dist)
+        cmd.ensure_finalized()
+
+        # Make sure we use the custom command
+        cmd.cmdclass = {'build_py': CustomBuildPy}
+        cmd.distribution.cmdclass = {'build_py': CustomBuildPy}
+        assert cmd.distribution.get_command_class('build_py') == CustomBuildPy
+
+        with quiet():
+            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)