From 2c9dbd6d49744aa8da8ebf8d0187d6b06f93c2b5 Mon Sep 17 00:00:00 2001
From: Maxime Ripard <maxime.ripard@free-electrons.com>
Date: Wed, 22 Feb 2017 17:45:14 -0800
Subject: [PATCH] Add an option to disable IDLE

IDLE is an IDE embedded into python, written using Tk, so it doesn't make
much sense to have it into our build.

Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
[ Andrey Smirnov: ported to Python 3.6 ]
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
[ Adam Duskett: ported to Python 3.10.0 ]
Signed-off-by: Adam Duskett <aduskett@gmail.com>
---
 Makefile.pre.in | 7 ++++++-
 configure.ac    | 6 ++++++
 setup.py        | 5 ++++-
 3 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/Makefile.pre.in b/Makefile.pre.in
index 80d617cf7f..8d1ba1356c 100644
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -1862,7 +1862,9 @@ bininstall: altbininstall
 	-rm -f $(DESTDIR)$(LIBPC)/python3-embed.pc
 	(cd $(DESTDIR)$(LIBPC); $(LN) -s python-$(VERSION)-embed.pc python3-embed.pc)
 	-rm -f $(DESTDIR)$(BINDIR)/idle3
+ifeq (@IDLE@,yes)
 	(cd $(DESTDIR)$(BINDIR); $(LN) -s idle$(VERSION) idle3)
+endif
 	-rm -f $(DESTDIR)$(BINDIR)/pydoc3
 ifeq (@PYDOC@,yes)
 	(cd $(DESTDIR)$(BINDIR); $(LN) -s pydoc$(VERSION) pydoc3)
@@ -1912,7 +1914,6 @@ LIBSUBDIRS=	asyncio \
 		ensurepip ensurepip/_bundled \
 		html \
 		http \
-		idlelib idlelib/Icons \
 		importlib importlib/resources importlib/metadata \
 		json \
 		logging \
@@ -2030,6 +2031,10 @@ ifeq (@EXPAT@,yes)
 LIBSUBDIRS += $(XMLLIBSUBDIRS)
 endif
 
+ifeq (@IDLE@,yes)
+LIBSUBDIRS += idlelib idlelib/Icons
+endif
+
 TEST_MODULES=@TEST_MODULES@
 libinstall:	all $(srcdir)/Modules/xxmodule.c
 	@for i in $(SCRIPTDIR) $(LIBDEST); \
diff --git a/configure.ac b/configure.ac
index ba4b0e0c1c..5e6d72f7db 100644
--- a/configure.ac
+++ b/configure.ac
@@ -7137,6 +7137,12 @@ AC_ARG_ENABLE(lib2to3,
 	AS_HELP_STRING([--disable-lib2to3], [disable lib2to3]),
 	[ LIB2TO3="${enableval}" ], [ LIB2TO3=yes ])
 
+AC_SUBST(IDLE)
+
+AC_ARG_ENABLE(idle3,
+	AS_HELP_STRING([--disable-idle3], [disable idle3 IDE]),
+	[ IDLE="${enableval}" ], [ IDLE=yes ])
+
 # generate output files
 AC_CONFIG_FILES(Makefile.pre Misc/python.pc Misc/python-embed.pc Misc/python-config.sh)
 AC_CONFIG_FILES([Modules/Setup.bootstrap Modules/Setup.stdlib])
diff --git a/setup.py b/setup.py
index c490b0b08f..4d49a792f7 100644
--- a/setup.py
+++ b/setup.py
@@ -1594,11 +1594,14 @@ class DummyProcess:
     import warnings
     warnings.filterwarnings("ignore",category=DeprecationWarning)
 
-    scripts = ['Tools/scripts/idle3', 'Lib/smtpd.py']
+    scripts = [ 'Lib/smtpd.py']
     if not '--disable-pydoc' in sysconfig.get_config_var("CONFIG_ARGS"):
         scripts += [ 'Tools/scripts/pydoc3' ]
     if not '--disable-lib2to3' in sysconfig.get_config_var("CONFIG_ARGS"):
         scripts += [ 'Tools/scripts/2to3' ]
+    if not '--disable-idle3' in sysconfig.get_config_var("CONFIG_ARGS"):
+        scripts += [ 'Tools/scripts/idle3' ]
+
     setup(# PyPI Metadata (PEP 301)
           name = "Python",
           version = sys.version.split()[0],
-- 
2.34.1

