Skip to content

Commit cad8020

Browse files
authored
bpo-42955: Add Python/module_names.h (GH-24258)
Add a private list of all stdlib modules: _Py_module_names. * Add Tools/scripts/generate_module_names.py script. * Makefile: Add "make regen-module-names" command. * setup.py: Add --list-module-names option. * GitHub Action and Travis CI also runs "make regen-module-names", not ony "make regen-all", to ensure that the module names remains up to date.
1 parent e8e66ea commit cad8020

File tree

8 files changed

+592
-18
lines changed

8 files changed

+592
-18
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ jobs:
6363
# Build Python with the libpython dynamic library
6464
./configure --with-pydebug --enable-shared
6565
make -j4 regen-all
66+
make regen-module-names
6667
- name: Check for changes
6768
run: |
6869
changes=$(git status --porcelain)

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ before_script:
172172
- eval "$(pyenv init -)"
173173
- pyenv global 3.8
174174
- PYTHON_FOR_REGEN=python3.8 make -j4 regen-all
175+
- make regen-module-names
175176
- changes=`git status --porcelain`
176177
- |
177178
# Check for changes in regenerated files

Makefile.pre.in

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ PYTHON= python$(EXE)
252252
BUILDPYTHON= python$(BUILDEXE)
253253

254254
PYTHON_FOR_REGEN?=@PYTHON_FOR_REGEN@
255-
UPDATE_FILE=@PYTHON_FOR_REGEN@ $(srcdir)/Tools/scripts/update_file.py
255+
UPDATE_FILE=$(PYTHON_FOR_REGEN) $(srcdir)/Tools/scripts/update_file.py
256256
PYTHON_FOR_BUILD=@PYTHON_FOR_BUILD@
257257
_PYTHON_HOST_PLATFORM=@_PYTHON_HOST_PLATFORM@
258258
BUILD_GNU_TYPE= @build@
@@ -757,6 +757,8 @@ regen-limited-abi: all
757757
regen-all: regen-opcode regen-opcode-targets regen-typeslots \
758758
regen-token regen-ast regen-keyword regen-importlib clinic \
759759
regen-pegen-metaparser regen-pegen
760+
@echo
761+
@echo "Note: make regen-module-names and autoconf should be run manually"
760762

761763
############################################################################
762764
# Special rules for object files
@@ -896,6 +898,15 @@ regen-keyword:
896898
$(srcdir)/Lib/keyword.py.new
897899
$(UPDATE_FILE) $(srcdir)/Lib/keyword.py $(srcdir)/Lib/keyword.py.new
898900

901+
.PHONY: regen-module-names
902+
regen-module-names: build_all
903+
# Regenerate Python/module_names.h
904+
# using Tools/scripts/generate_module_names.py
905+
$(RUNSHARED) ./$(BUILDPYTHON) \
906+
$(srcdir)/Tools/scripts/generate_module_names.py \
907+
> $(srcdir)/Python/module_names.h.new
908+
$(UPDATE_FILE) $(srcdir)/Python/module_names.h $(srcdir)/Python/module_names.h.new
909+
899910
Python/compile.o Python/symtable.o Python/ast_unparse.o Python/ast.o Python/future.o: $(srcdir)/Include/Python-ast.h
900911

901912
Python/getplatform.o: $(srcdir)/Python/getplatform.c
@@ -1145,7 +1156,9 @@ PYTHON_HEADERS= \
11451156
$(srcdir)/Include/internal/pycore_ucnhash.h \
11461157
$(srcdir)/Include/internal/pycore_unionobject.h \
11471158
$(srcdir)/Include/internal/pycore_warnings.h \
1148-
$(DTRACE_HEADERS)
1159+
$(DTRACE_HEADERS) \
1160+
\
1161+
$(srcdir)/Python/module_names.h
11491162

11501163
$(LIBRARY_OBJS) $(MODOBJS) Programs/python.o: $(PYTHON_HEADERS)
11511164

PCbuild/pythoncore.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@
291291
<ClInclude Include="..\Python\ceval_gil.h" />
292292
<ClInclude Include="..\Python\condvar.h" />
293293
<ClInclude Include="..\Python\importdl.h" />
294+
<ClInclude Include="..\Python\module_names.h" />
294295
<ClInclude Include="..\Python\thread_nt.h" />
295296
<ClInclude Include="..\Python\wordcode_helpers.h" />
296297
</ItemGroup>

PCbuild/pythoncore.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,9 @@
360360
<ClInclude Include="..\Python\importdl.h">
361361
<Filter>Python</Filter>
362362
</ClInclude>
363+
<ClInclude Include="..\Python\module_names.h">
364+
<Filter>Python</Filter>
365+
</ClInclude>
363366
<ClInclude Include="..\Python\thread_nt.h">
364367
<Filter>Python</Filter>
365368
</ClInclude>

0 commit comments

Comments
 (0)