From b3c0c2a4c1224233d294fec81b1bce1f50897604 Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Mon, 27 Jun 2022 11:41:39 +0200 Subject: [PATCH] gh-93939: Create and install scripts in Makefile Scripts for 2to3, idle, and pydoc are now created and installed by make. --- Makefile.pre.in | 33 ++++++++++++++++--- ...2-06-27-11-57-15.gh-issue-93939.rv7s8W.rst | 2 ++ Tools/scripts/2to3 | 2 +- Tools/scripts/idle3 | 2 +- setup.py | 32 ------------------ 5 files changed, 33 insertions(+), 38 deletions(-) create mode 100644 Misc/NEWS.d/next/Build/2022-06-27-11-57-15.gh-issue-93939.rv7s8W.rst diff --git a/Makefile.pre.in b/Makefile.pre.in index 5af9efda6412ba..00131d2d9468dc 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -150,6 +150,8 @@ CONFINCLUDEDIR= $(exec_prefix)/include PLATLIBDIR= @PLATLIBDIR@ SCRIPTDIR= $(prefix)/$(PLATLIBDIR) ABIFLAGS= @ABIFLAGS@ +# executable name for shebangs +EXENAME= $(BINDIR)/python$(LDVERSION)$(EXE) # Variable used by ensurepip WHEEL_PKG_DIR= @WHEEL_PKG_DIR@ @@ -580,7 +582,7 @@ LIBEXPAT_HEADERS= \ # Default target all: @DEF_MAKE_ALL_RULE@ build_all: check-clean-src $(BUILDPYTHON) platform oldsharedmods sharedmods \ - gdbhooks Programs/_testembed python-config + gdbhooks Programs/_testembed scripts build_wasm: check-clean-src $(BUILDPYTHON) platform oldsharedmods python-config # Check that the source is clean when building out of source. @@ -2111,7 +2113,7 @@ libinstall: all $(srcdir)/Modules/xxmodule.c python-config: $(srcdir)/Misc/python-config.in Misc/python-config.sh @ # Substitution happens here, as the completely-expanded BINDIR @ # is not available in configure - sed -e "s,@EXENAME@,$(BINDIR)/python$(LDVERSION)$(EXE)," < $(srcdir)/Misc/python-config.in >python-config.py + sed -e "s,@EXENAME@,$(EXENAME)," < $(srcdir)/Misc/python-config.in >python-config.py @ # Replace makefile compat. variable references with shell script compat. ones; $(VAR) -> ${VAR} LC_ALL=C sed -e 's,\$$(\([A-Za-z0-9_]*\)),\$$\{\1\},g' < Misc/python-config.sh >python-config @ # On Darwin, always use the python version of the script, the shell @@ -2121,6 +2123,26 @@ python-config: $(srcdir)/Misc/python-config.in Misc/python-config.sh cp python-config.py python-config; \ fi +BUILD_SCRIPTS_DIR=build/scripts-$(VERSION) +$(BUILD_SCRIPTS_DIR): + $(MKDIR_P) $@ + +SCRIPT_2TO3=$(BUILD_SCRIPTS_DIR)/2to3-$(VERSION) +$(SCRIPT_2TO3): $(srcdir)/Tools/scripts/2to3 $(BUILD_SCRIPTS_DIR) + sed -e "s,/usr/bin/env python3,$(EXENAME)," < $(srcdir)/Tools/scripts/2to3 > $@ + chmod +x $@ + +SCRIPT_IDLE=$(BUILD_SCRIPTS_DIR)/idle$(VERSION) +$(SCRIPT_IDLE): $(srcdir)/Tools/scripts/idle3 $(BUILD_SCRIPTS_DIR) + sed -e "s,/usr/bin/env python3,$(EXENAME)," < $(srcdir)/Tools/scripts/idle3 > $@ + chmod +x $@ + +SCRIPT_PYDOC=$(BUILD_SCRIPTS_DIR)/pydoc$(VERSION) +$(SCRIPT_PYDOC): $(srcdir)/Tools/scripts/pydoc3 $(BUILD_SCRIPTS_DIR) + sed -e "s,/usr/bin/env python3,$(EXENAME)," < $(srcdir)/Tools/scripts/pydoc3 > $@ + chmod +x $@ + +scripts: $(SCRIPT_2TO3) $(SCRIPT_IDLE) $(SCRIPT_PYDOC) python-config # Install the include files INCLDIRSTOMAKE=$(INCLUDEDIR) $(CONFINCLUDEDIR) $(INCLUDEPY) $(CONFINCLUDEPY) @@ -2167,7 +2189,7 @@ LIBPL= @LIBPL@ # pkgconfig directory LIBPC= $(LIBDIR)/pkgconfig -libainstall: all python-config +libainstall: all scripts @for i in $(LIBDIR) $(LIBPL) $(LIBPC) $(BINDIR); \ do \ if test ! -d $(DESTDIR)$$i; then \ @@ -2203,6 +2225,9 @@ libainstall: all python-config $(INSTALL_SCRIPT) $(srcdir)/install-sh $(DESTDIR)$(LIBPL)/install-sh $(INSTALL_SCRIPT) python-config.py $(DESTDIR)$(LIBPL)/python-config.py $(INSTALL_SCRIPT) python-config $(DESTDIR)$(BINDIR)/python$(LDVERSION)-config + $(INSTALL_SCRIPT) $(SCRIPT_2TO3) $(DESTDIR)$(BINDIR)/2to3-$(VERSION) + $(INSTALL_SCRIPT) $(SCRIPT_IDLE) $(DESTDIR)$(BINDIR)/idle$(VERSION) + $(INSTALL_SCRIPT) $(SCRIPT_PYDOC) $(DESTDIR)$(BINDIR)/pydoc$(VERSION) @if [ -s Modules/python.exp -a \ "`echo $(MACHDEP) | sed 's/^\(...\).*/\1/'`" = "aix" ]; then \ echo; echo "Installing support files for building shared extension modules on AIX:"; \ @@ -2512,7 +2537,7 @@ Python/thread.o: @THREADHEADERS@ $(srcdir)/Python/condvar.h .PHONY: smelly funny patchcheck touch altmaninstall commoninstall .PHONY: clean-retain-profile profile-removal run_profile_task .PHONY: build_all_generate_profile build_all_merge_profile -.PHONY: gdbhooks +.PHONY: gdbhooks scripts ########################################################################## # Module dependencies and platform-specific files diff --git a/Misc/NEWS.d/next/Build/2022-06-27-11-57-15.gh-issue-93939.rv7s8W.rst b/Misc/NEWS.d/next/Build/2022-06-27-11-57-15.gh-issue-93939.rv7s8W.rst new file mode 100644 index 00000000000000..f9ecf5022e2489 --- /dev/null +++ b/Misc/NEWS.d/next/Build/2022-06-27-11-57-15.gh-issue-93939.rv7s8W.rst @@ -0,0 +1,2 @@ +The ``2to3``, ``idle``, and ``pydoc`` scripts are now generated and installed by +``Makefile`` instead of ``setup.py``. diff --git a/Tools/scripts/2to3 b/Tools/scripts/2to3 index fbd4aa6b838234..f27d18ecf67086 100755 --- a/Tools/scripts/2to3 +++ b/Tools/scripts/2to3 @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import sys from lib2to3.main import main diff --git a/Tools/scripts/idle3 b/Tools/scripts/idle3 index d7332bca48b8ae..2b4f1b5c957209 100755 --- a/Tools/scripts/idle3 +++ b/Tools/scripts/idle3 @@ -1,4 +1,4 @@ -#! /usr/bin/env python3 +#!/usr/bin/env python3 from idlelib.pyshell import main if __name__ == '__main__': diff --git a/setup.py b/setup.py index 210d0f49bae91f..843ec35effe109 100644 --- a/setup.py +++ b/setup.py @@ -47,7 +47,6 @@ ) from distutils.command.build_ext import build_ext - from distutils.command.build_scripts import build_scripts from distutils.command.install import install from distutils.command.install_lib import install_lib from distutils.core import Extension, setup @@ -408,10 +407,6 @@ def update_sources_depends(self): os.getcwd() ] - # Fix up the paths for scripts, too - self.distribution.scripts = [os.path.join(self.srcdir, filename) - for filename in self.distribution.scripts] - # Python header files include_dir = escape(sysconfig.get_path('include')) headers = [sysconfig.get_config_h_filename()] @@ -1463,26 +1458,6 @@ def set_dir_modes(self, dirname, mode): if not self.dry_run: os.chmod(dirpath, mode) -class PyBuildScripts(build_scripts): - def copy_scripts(self): - outfiles, updated_files = build_scripts.copy_scripts(self) - fullversion = '-{0[0]}.{0[1]}'.format(sys.version_info) - minoronly = '.{0[1]}'.format(sys.version_info) - newoutfiles = [] - newupdated_files = [] - for filename in outfiles: - if filename.endswith('2to3'): - newfilename = filename + fullversion - else: - newfilename = filename + minoronly - log.info(f'renaming {filename} to {newfilename}') - os.rename(filename, newfilename) - newoutfiles.append(newfilename) - if filename in updated_files: - newupdated_files.append(newfilename) - return newoutfiles, newupdated_files - - def main(): global LIST_MODULE_NAMES @@ -1517,18 +1492,11 @@ class DummyProcess: # Build info cmdclass = {'build_ext': PyBuildExt, - 'build_scripts': PyBuildScripts, 'install': PyBuildInstall, 'install_lib': PyBuildInstallLib}, # A dummy module is defined here, because build_ext won't be # called unless there's at least one extension module defined. ext_modules=[Extension('_dummy', ['_dummy.c'])], - - # If you change the scripts installed here, you also need to - # check the PyBuildScripts command above, and change the links - # created by the bininstall target in Makefile.pre.in - scripts = ["Tools/scripts/pydoc3", "Tools/scripts/idle3", - "Tools/scripts/2to3"] ) # --install-platlib