]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
GH-129064: deprecate sysconfig.expand_makefile_vars (#129082)
authorFilipe Laíns 🇵🇸 <lains@riseup.net>
Mon, 20 Jan 2025 17:03:44 +0000 (17:03 +0000)
committerGitHub <noreply@github.com>
Mon, 20 Jan 2025 17:03:44 +0000 (17:03 +0000)
Doc/deprecations/pending-removal-in-3.16.rst
Lib/sysconfig/__init__.py
Lib/test/test_sysconfig.py
Misc/NEWS.d/next/Library/2025-01-20-16-02-38.gh-issue-129064.JXasgJ.rst [new file with mode: 0644]

index 41b30defdba0bcf6153dd71a3014aeb2282eeecd..58f7c01bf394690a494426c5c61f2a7ea4d0d838 100644 (file)
@@ -80,6 +80,12 @@ Pending removal in Python 3.16
     has been deprecated since Python 3.13.
     Use the :envvar:`PYTHONLEGACYWINDOWSFSENCODING` environment variable instead.
 
+* :mod:`sysconfig`:
+
+  * The ``~sysconfig.expand_makefile_vars`` function
+    has been deprecated since Python 3.14.
+    Use the ``vars`` argument of :func:`sysconfig.get_paths` instead.
+
 * :mod:`tarfile`:
 
   * The undocumented and unused :attr:`!TarFile.tarfile` attribute
index ec9bb705925cdbc7f976a92b1b6a2f1a60a1edd1..86dd391aa173b5ec3c3b1a829250ecdfbc3a586c 100644 (file)
@@ -716,6 +716,15 @@ def expand_makefile_vars(s, vars):
     variable expansions; if 'vars' is the output of 'parse_makefile()',
     you're fine.  Returns a variable-expanded version of 's'.
     """
+
+    import warnings
+    warnings.warn(
+        'sysconfig.expand_makefile_vars is deprecated and will be removed in '
+        'Python 3.16. Use sysconfig.get_paths(vars=...) instead.',
+        DeprecationWarning,
+        stacklevel=2,
+    )
+
     import re
 
     _findvar1_rx = r"\$\(([A-Za-z][A-Za-z0-9_]*)\)"
index ce504dc21af85fba1902cf7d835084cc2024c166..a5676027eb7438ced53afe1274bed7db302fd422 100644 (file)
@@ -711,5 +711,24 @@ class MakefileTests(unittest.TestCase):
         })
 
 
+class DeprecationTests(unittest.TestCase):
+    def deprecated(self, removal_version, deprecation_msg=None, attribute_msg=None):
+        if sys.version_info >= removal_version:
+            return self.assertRaises(AttributeError, msg=attribute_msg)
+        else:
+            return self.assertWarns(DeprecationWarning, msg=deprecation_msg)
+
+    def test_expand_makefile_vars(self):
+        with self.deprecated(
+            removal_version=(3, 16),
+            deprecation_msg=(
+                'sysconfig.expand_makefile_vars is deprecated and will be removed in '
+                'Python 3.16. Use sysconfig.get_paths(vars=...) instead.',
+            ),
+            attribute_msg="module 'sysconfig' has no attribute 'expand_makefile_vars'",
+        ):
+            sysconfig.expand_makefile_vars('', {})
+
+
 if __name__ == "__main__":
     unittest.main()
diff --git a/Misc/NEWS.d/next/Library/2025-01-20-16-02-38.gh-issue-129064.JXasgJ.rst b/Misc/NEWS.d/next/Library/2025-01-20-16-02-38.gh-issue-129064.JXasgJ.rst
new file mode 100644 (file)
index 0000000..5939fdc
--- /dev/null
@@ -0,0 +1,2 @@
+Deprecate ``sysconfig.expand_makefile_vars``, in favor of using
+:func:`sysconfig.get_paths` with the ``vars`` argument.