From 2dd10915bc6ba12f30a9ce44cd1e678c63a0891e Mon Sep 17 00:00:00 2001 From: ManiacDC Date: Tue, 18 Mar 2025 10:19:38 -0400 Subject: [PATCH 1/7] Restores _default_compilers to ccompilers.py for backwards compatibility --- distutils/ccompiler.py | 18 ++++++++++-------- newsfragments/4877.bugfix.rst | 1 + 2 files changed, 11 insertions(+), 8 deletions(-) create mode 100644 newsfragments/4877.bugfix.rst diff --git a/distutils/ccompiler.py b/distutils/ccompiler.py index e39cd8aa..9cf0f4ce 100644 --- a/distutils/ccompiler.py +++ b/distutils/ccompiler.py @@ -6,18 +6,20 @@ get_default_compiler, new_compiler, show_compilers, + _default_compilers, ) from .compilers.C.errors import CompileError, LinkError __all__ = [ - 'CompileError', - 'LinkError', - 'compiler_class', - 'gen_lib_options', - 'gen_preprocess_options', - 'get_default_compiler', - 'new_compiler', - 'show_compilers', + "CompileError", + "LinkError", + "compiler_class", + "gen_lib_options", + "gen_preprocess_options", + "get_default_compiler", + "new_compiler", + "show_compilers", + _default_compilers, ] diff --git a/newsfragments/4877.bugfix.rst b/newsfragments/4877.bugfix.rst new file mode 100644 index 00000000..8350c5a7 --- /dev/null +++ b/newsfragments/4877.bugfix.rst @@ -0,0 +1 @@ +Restore `distutils.ccompiler._default_compilers` -- by :user:`ManiacDC` From bc319747b1d77c771b52124ab44cbdc04aac8078 Mon Sep 17 00:00:00 2001 From: ManiacDC Date: Tue, 18 Mar 2025 10:37:06 -0400 Subject: [PATCH 2/7] fix newsfragments --- newsfragments/{4877.bugfix.rst => 4876.bugfix-2.rst} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename newsfragments/{4877.bugfix.rst => 4876.bugfix-2.rst} (100%) diff --git a/newsfragments/4877.bugfix.rst b/newsfragments/4876.bugfix-2.rst similarity index 100% rename from newsfragments/4877.bugfix.rst rename to newsfragments/4876.bugfix-2.rst From 742f566b53f0ed48027defc0e42ef569b9824679 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 19 Mar 2025 18:57:02 -0400 Subject: [PATCH 3/7] Fixed __all__. --- distutils/ccompiler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/distutils/ccompiler.py b/distutils/ccompiler.py index 9cf0f4ce..33efc251 100644 --- a/distutils/ccompiler.py +++ b/distutils/ccompiler.py @@ -19,7 +19,7 @@ "get_default_compiler", "new_compiler", "show_compilers", - _default_compilers, + "_default_compilers", ] From 205a3ecc960f709d0811aa08f097b9537d36c107 Mon Sep 17 00:00:00 2001 From: maniacdc Date: Wed, 19 Mar 2025 19:54:41 -0400 Subject: [PATCH 4/7] * fixed import order * added documentation to imports as to why they are there, and when they can be removed. --- distutils/ccompiler.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/distutils/ccompiler.py b/distutils/ccompiler.py index 33efc251..6f5bbde6 100644 --- a/distutils/ccompiler.py +++ b/distutils/ccompiler.py @@ -1,25 +1,28 @@ from .compilers.C import base from .compilers.C.base import ( + # `_default_compilers` is needed by numpy.distutils, which is supported until + # Python 3.11 is deprecated. This import & export can be removed when + # Python 3.11 is no longer supported by distutils. + _default_compilers, compiler_class, gen_lib_options, gen_preprocess_options, get_default_compiler, new_compiler, show_compilers, - _default_compilers, ) from .compilers.C.errors import CompileError, LinkError __all__ = [ "CompileError", "LinkError", + "_default_compilers", "compiler_class", "gen_lib_options", "gen_preprocess_options", "get_default_compiler", "new_compiler", "show_compilers", - "_default_compilers", ] From e2a30b5f0576483ef51dcb40d6a6f67bafec4572 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 19 Mar 2025 21:37:12 -0400 Subject: [PATCH 5/7] Restore quotes. --- distutils/ccompiler.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/distutils/ccompiler.py b/distutils/ccompiler.py index 6f5bbde6..3aeacdb9 100644 --- a/distutils/ccompiler.py +++ b/distutils/ccompiler.py @@ -14,15 +14,15 @@ from .compilers.C.errors import CompileError, LinkError __all__ = [ - "CompileError", - "LinkError", - "_default_compilers", - "compiler_class", - "gen_lib_options", - "gen_preprocess_options", - "get_default_compiler", - "new_compiler", - "show_compilers", + 'CompileError', + 'LinkError', + '_default_compilers', + 'compiler_class', + 'gen_lib_options', + 'gen_preprocess_options', + 'get_default_compiler', + 'new_compiler', + 'show_compilers', ] From 731a65edc6f053cfb8cc3a25402f41dff7e4a624 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 19 Mar 2025 21:37:45 -0400 Subject: [PATCH 6/7] Rename newsfragment. --- newsfragments/{4876.bugfix-2.rst => 4876.bugfix.2.rst} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename newsfragments/{4876.bugfix-2.rst => 4876.bugfix.2.rst} (100%) diff --git a/newsfragments/4876.bugfix-2.rst b/newsfragments/4876.bugfix.2.rst similarity index 100% rename from newsfragments/4876.bugfix-2.rst rename to newsfragments/4876.bugfix.2.rst From b48a3b8bda04a392603362e1beb7c0b08f935fbd Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 19 Mar 2025 21:45:24 -0400 Subject: [PATCH 7/7] Move numpy compatibility imports to the compat package. Remove them from __all__, as that's not needed for compatibility. --- distutils/ccompiler.py | 11 ++++------- distutils/compat/numpy.py | 2 ++ 2 files changed, 6 insertions(+), 7 deletions(-) create mode 100644 distutils/compat/numpy.py diff --git a/distutils/ccompiler.py b/distutils/ccompiler.py index 3aeacdb9..58bc6a55 100644 --- a/distutils/ccompiler.py +++ b/distutils/ccompiler.py @@ -1,10 +1,9 @@ -from .compilers.C import base -from .compilers.C.base import ( - # `_default_compilers` is needed by numpy.distutils, which is supported until - # Python 3.11 is deprecated. This import & export can be removed when - # Python 3.11 is no longer supported by distutils. +from .compat.numpy import ( # noqa: F401 _default_compilers, compiler_class, +) +from .compilers.C import base +from .compilers.C.base import ( gen_lib_options, gen_preprocess_options, get_default_compiler, @@ -16,8 +15,6 @@ __all__ = [ 'CompileError', 'LinkError', - '_default_compilers', - 'compiler_class', 'gen_lib_options', 'gen_preprocess_options', 'get_default_compiler', diff --git a/distutils/compat/numpy.py b/distutils/compat/numpy.py new file mode 100644 index 00000000..73eca7ac --- /dev/null +++ b/distutils/compat/numpy.py @@ -0,0 +1,2 @@ +# required for older numpy versions on Pythons prior to 3.12; see pypa/setuptools#4876 +from ..compilers.C.base import _default_compilers, compiler_class # noqa: F401