Skip to content

Commit

Permalink
pythongh-93939: Create and install scripts in Makefile (pythonGH-94324)
Browse files Browse the repository at this point in the history
Scripts for 2to3, idle, and pydoc are now created and installed by make.
  • Loading branch information
tiran authored and gvanrossum committed Jun 30, 2022
1 parent 8e1bce0 commit 3daebfe
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 38 deletions.
36 changes: 32 additions & 4 deletions Makefile.pre.in
Original file line number Diff line number Diff line change
Expand Up @@ -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@

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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 \
Expand Down Expand Up @@ -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:"; \
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The ``2to3``, ``idle``, and ``pydoc`` scripts are now generated and installed by
``Makefile`` instead of ``setup.py``.
2 changes: 1 addition & 1 deletion Tools/scripts/2to3
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import sys
from lib2to3.main import main

Expand Down
2 changes: 1 addition & 1 deletion Tools/scripts/idle3
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/env python3
#!/usr/bin/env python3

from idlelib.pyshell import main
if __name__ == '__main__':
Expand Down
32 changes: 0 additions & 32 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()]
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3daebfe

Please sign in to comment.