Skip to content

Commit 44fa03d

Browse files
authoredJun 28, 2022
pythongh-93939: Create and install scripts in Makefile (pythonGH-94324)
Scripts for 2to3, idle, and pydoc are now created and installed by make.
1 parent 600c65c commit 44fa03d

File tree

5 files changed

+36
-38
lines changed

5 files changed

+36
-38
lines changed
 

‎Makefile.pre.in

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ CONFINCLUDEDIR= $(exec_prefix)/include
150150
PLATLIBDIR= @PLATLIBDIR@
151151
SCRIPTDIR= $(prefix)/$(PLATLIBDIR)
152152
ABIFLAGS= @ABIFLAGS@
153+
# executable name for shebangs
154+
EXENAME= $(BINDIR)/python$(LDVERSION)$(EXE)
153155
# Variable used by ensurepip
154156
WHEEL_PKG_DIR= @WHEEL_PKG_DIR@
155157

@@ -580,7 +582,7 @@ LIBEXPAT_HEADERS= \
580582
# Default target
581583
all: @DEF_MAKE_ALL_RULE@
582584
build_all: check-clean-src $(BUILDPYTHON) platform oldsharedmods sharedmods \
583-
gdbhooks Programs/_testembed python-config
585+
gdbhooks Programs/_testembed scripts
584586
build_wasm: check-clean-src $(BUILDPYTHON) platform oldsharedmods python-config
585587

586588
# Check that the source is clean when building out of source.
@@ -2111,7 +2113,7 @@ libinstall: all $(srcdir)/Modules/xxmodule.c
21112113
python-config: $(srcdir)/Misc/python-config.in Misc/python-config.sh
21122114
@ # Substitution happens here, as the completely-expanded BINDIR
21132115
@ # is not available in configure
2114-
sed -e "s,@EXENAME@,$(BINDIR)/python$(LDVERSION)$(EXE)," < $(srcdir)/Misc/python-config.in >python-config.py
2116+
sed -e "s,@EXENAME@,$(EXENAME)," < $(srcdir)/Misc/python-config.in >python-config.py
21152117
@ # Replace makefile compat. variable references with shell script compat. ones; $(VAR) -> ${VAR}
21162118
LC_ALL=C sed -e 's,\$$(\([A-Za-z0-9_]*\)),\$$\{\1\},g' < Misc/python-config.sh >python-config
21172119
@ # 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
21212123
cp python-config.py python-config; \
21222124
fi
21232125

2126+
# macOS' make seems to ignore a dependency on a
2127+
# "$(BUILD_SCRIPTS_DIR): $(MKDIR_P) $@" rule.
2128+
BUILD_SCRIPTS_DIR=build/scripts-$(VERSION)
2129+
SCRIPT_2TO3=$(BUILD_SCRIPTS_DIR)/2to3-$(VERSION)
2130+
SCRIPT_IDLE=$(BUILD_SCRIPTS_DIR)/idle$(VERSION)
2131+
SCRIPT_PYDOC=$(BUILD_SCRIPTS_DIR)/pydoc$(VERSION)
2132+
2133+
$(SCRIPT_2TO3): $(srcdir)/Tools/scripts/2to3
2134+
@$(MKDIR_P) $(BUILD_SCRIPTS_DIR)
2135+
sed -e "s,/usr/bin/env python3,$(EXENAME)," < $(srcdir)/Tools/scripts/2to3 > $@
2136+
@chmod +x $@
2137+
2138+
$(SCRIPT_IDLE): $(srcdir)/Tools/scripts/idle3
2139+
@$(MKDIR_P) $(BUILD_SCRIPTS_DIR)
2140+
sed -e "s,/usr/bin/env python3,$(EXENAME)," < $(srcdir)/Tools/scripts/idle3 > $@
2141+
@chmod +x $@
2142+
2143+
$(SCRIPT_PYDOC): $(srcdir)/Tools/scripts/pydoc3
2144+
@$(MKDIR_P) $(BUILD_SCRIPTS_DIR)
2145+
sed -e "s,/usr/bin/env python3,$(EXENAME)," < $(srcdir)/Tools/scripts/pydoc3 > $@
2146+
@chmod +x $@
2147+
2148+
scripts: $(SCRIPT_2TO3) $(SCRIPT_IDLE) $(SCRIPT_PYDOC) python-config
21242149

21252150
# Install the include files
21262151
INCLDIRSTOMAKE=$(INCLUDEDIR) $(CONFINCLUDEDIR) $(INCLUDEPY) $(CONFINCLUDEPY)
@@ -2167,7 +2192,7 @@ LIBPL= @LIBPL@
21672192
# pkgconfig directory
21682193
LIBPC= $(LIBDIR)/pkgconfig
21692194

2170-
libainstall: all python-config
2195+
libainstall: all scripts
21712196
@for i in $(LIBDIR) $(LIBPL) $(LIBPC) $(BINDIR); \
21722197
do \
21732198
if test ! -d $(DESTDIR)$$i; then \
@@ -2203,6 +2228,9 @@ libainstall: all python-config
22032228
$(INSTALL_SCRIPT) $(srcdir)/install-sh $(DESTDIR)$(LIBPL)/install-sh
22042229
$(INSTALL_SCRIPT) python-config.py $(DESTDIR)$(LIBPL)/python-config.py
22052230
$(INSTALL_SCRIPT) python-config $(DESTDIR)$(BINDIR)/python$(LDVERSION)-config
2231+
$(INSTALL_SCRIPT) $(SCRIPT_2TO3) $(DESTDIR)$(BINDIR)/2to3-$(VERSION)
2232+
$(INSTALL_SCRIPT) $(SCRIPT_IDLE) $(DESTDIR)$(BINDIR)/idle$(VERSION)
2233+
$(INSTALL_SCRIPT) $(SCRIPT_PYDOC) $(DESTDIR)$(BINDIR)/pydoc$(VERSION)
22062234
@if [ -s Modules/python.exp -a \
22072235
"`echo $(MACHDEP) | sed 's/^\(...\).*/\1/'`" = "aix" ]; then \
22082236
echo; echo "Installing support files for building shared extension modules on AIX:"; \
@@ -2512,7 +2540,7 @@ Python/thread.o: @THREADHEADERS@ $(srcdir)/Python/condvar.h
25122540
.PHONY: smelly funny patchcheck touch altmaninstall commoninstall
25132541
.PHONY: clean-retain-profile profile-removal run_profile_task
25142542
.PHONY: build_all_generate_profile build_all_merge_profile
2515-
.PHONY: gdbhooks
2543+
.PHONY: gdbhooks scripts
25162544

25172545
##########################################################################
25182546
# Module dependencies and platform-specific files
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The ``2to3``, ``idle``, and ``pydoc`` scripts are now generated and installed by
2+
``Makefile`` instead of ``setup.py``.

‎Tools/scripts/2to3

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22
import sys
33
from lib2to3.main import main
44

‎Tools/scripts/idle3

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#! /usr/bin/env python3
1+
#!/usr/bin/env python3
22

33
from idlelib.pyshell import main
44
if __name__ == '__main__':

‎setup.py

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
)
4848

4949
from distutils.command.build_ext import build_ext
50-
from distutils.command.build_scripts import build_scripts
5150
from distutils.command.install import install
5251
from distutils.command.install_lib import install_lib
5352
from distutils.core import Extension, setup
@@ -408,10 +407,6 @@ def update_sources_depends(self):
408407
os.getcwd()
409408
]
410409

411-
# Fix up the paths for scripts, too
412-
self.distribution.scripts = [os.path.join(self.srcdir, filename)
413-
for filename in self.distribution.scripts]
414-
415410
# Python header files
416411
include_dir = escape(sysconfig.get_path('include'))
417412
headers = [sysconfig.get_config_h_filename()]
@@ -1463,26 +1458,6 @@ def set_dir_modes(self, dirname, mode):
14631458
if not self.dry_run: os.chmod(dirpath, mode)
14641459

14651460

1466-
class PyBuildScripts(build_scripts):
1467-
def copy_scripts(self):
1468-
outfiles, updated_files = build_scripts.copy_scripts(self)
1469-
fullversion = '-{0[0]}.{0[1]}'.format(sys.version_info)
1470-
minoronly = '.{0[1]}'.format(sys.version_info)
1471-
newoutfiles = []
1472-
newupdated_files = []
1473-
for filename in outfiles:
1474-
if filename.endswith('2to3'):
1475-
newfilename = filename + fullversion
1476-
else:
1477-
newfilename = filename + minoronly
1478-
log.info(f'renaming {filename} to {newfilename}')
1479-
os.rename(filename, newfilename)
1480-
newoutfiles.append(newfilename)
1481-
if filename in updated_files:
1482-
newupdated_files.append(newfilename)
1483-
return newoutfiles, newupdated_files
1484-
1485-
14861461
def main():
14871462
global LIST_MODULE_NAMES
14881463

@@ -1517,18 +1492,11 @@ class DummyProcess:
15171492

15181493
# Build info
15191494
cmdclass = {'build_ext': PyBuildExt,
1520-
'build_scripts': PyBuildScripts,
15211495
'install': PyBuildInstall,
15221496
'install_lib': PyBuildInstallLib},
15231497
# A dummy module is defined here, because build_ext won't be
15241498
# called unless there's at least one extension module defined.
15251499
ext_modules=[Extension('_dummy', ['_dummy.c'])],
1526-
1527-
# If you change the scripts installed here, you also need to
1528-
# check the PyBuildScripts command above, and change the links
1529-
# created by the bininstall target in Makefile.pre.in
1530-
scripts = ["Tools/scripts/pydoc3", "Tools/scripts/idle3",
1531-
"Tools/scripts/2to3"]
15321500
)
15331501

15341502
# --install-platlib

0 commit comments

Comments
 (0)
Please sign in to comment.