[Python-checkins] gh-93939: Create and install scripts in Makefile (GH-94324)
tiran
webhook-mailer at python.org
Tue Jun 28 08:56:17 EDT 2022
https://github.com/python/cpython/commit/44fa03d748eb2b9a13a77c6143b18968521a1980
commit: 44fa03d748eb2b9a13a77c6143b18968521a1980
branch: main
author: Christian Heimes <christian at python.org>
committer: tiran <christian at python.org>
date: 2022-06-28T14:56:06+02:00
summary:
gh-93939: Create and install scripts in Makefile (GH-94324)
Scripts for 2to3, idle, and pydoc are now created and installed by make.
files:
A Misc/NEWS.d/next/Build/2022-06-27-11-57-15.gh-issue-93939.rv7s8W.rst
M Makefile.pre.in
M Tools/scripts/2to3
M Tools/scripts/idle3
M setup.py
diff --git a/Makefile.pre.in b/Makefile.pre.in
index 5af9efda6412b..3601d8a8775c6 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, at EXENAME@,$(BINDIR)/python$(LDVERSION)$(EXE)," < $(srcdir)/Misc/python-config.in >python-config.py
+ sed -e "s, at 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,29 @@ python-config: $(srcdir)/Misc/python-config.in Misc/python-config.sh
cp python-config.py python-config; \
fi
+# macOS' make seems to ignore a dependency on a
+# "$(BUILD_SCRIPTS_DIR): $(MKDIR_P) $@" rule.
+BUILD_SCRIPTS_DIR=build/scripts-$(VERSION)
+SCRIPT_2TO3=$(BUILD_SCRIPTS_DIR)/2to3-$(VERSION)
+SCRIPT_IDLE=$(BUILD_SCRIPTS_DIR)/idle$(VERSION)
+SCRIPT_PYDOC=$(BUILD_SCRIPTS_DIR)/pydoc$(VERSION)
+
+$(SCRIPT_2TO3): $(srcdir)/Tools/scripts/2to3
+ @$(MKDIR_P) $(BUILD_SCRIPTS_DIR)
+ sed -e "s,/usr/bin/env python3,$(EXENAME)," < $(srcdir)/Tools/scripts/2to3 > $@
+ @chmod +x $@
+
+$(SCRIPT_IDLE): $(srcdir)/Tools/scripts/idle3
+ @$(MKDIR_P) $(BUILD_SCRIPTS_DIR)
+ sed -e "s,/usr/bin/env python3,$(EXENAME)," < $(srcdir)/Tools/scripts/idle3 > $@
+ @chmod +x $@
+
+$(SCRIPT_PYDOC): $(srcdir)/Tools/scripts/pydoc3
+ @$(MKDIR_P) $(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 +2192,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 +2228,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 +2540,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 0000000000000..f9ecf5022e248
--- /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 fbd4aa6b83823..f27d18ecf6708 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 d7332bca48b8a..2b4f1b5c95720 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 210d0f49bae91..843ec35effe10 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
More information about the Python-checkins
mailing list