From b53c692e402ddc6f6f4bedd5758f5cb7b996f085 Mon Sep 17 00:00:00 2001 From: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Date: Fri, 3 Dec 2021 16:39:39 +0530 Subject: [PATCH 1/4] bpo-45654: freeze runpy module --- Makefile.pre.in | 36 ++++++++++++++++++++++++++ PCbuild/_freeze_module.vcxproj | 28 ++++++++++++++++++++ PCbuild/_freeze_module.vcxproj.filters | 12 +++++++++ PCbuild/pythoncore.vcxproj | 4 +++ Python/frozen.c | 20 +++++++++++--- Tools/scripts/freeze_modules.py | 6 +++++ 6 files changed, 103 insertions(+), 3 deletions(-) diff --git a/Makefile.pre.in b/Makefile.pre.in index 3dc131b6c9651b..1dc49a50dcc510 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -483,6 +483,10 @@ DEEPFREEZE_OBJS = \ Python/deepfreeze/os.o \ Python/deepfreeze/site.o \ Python/deepfreeze/stat.o \ + Python/deepfreeze/types.o \ + Python/deepfreeze/importlib.util.o \ + Python/deepfreeze/importlib.machinery.o \ + Python/deepfreeze/runpy.o \ Python/deepfreeze/__hello__.o \ Python/deepfreeze/__phello__.o \ Python/deepfreeze/__phello__.ham.o \ @@ -990,6 +994,18 @@ Python/deepfreeze/site.c: Python/frozen_modules/site.h $(DEEPFREEZE_DEPS) Python/deepfreeze/stat.c: Python/frozen_modules/stat.h $(DEEPFREEZE_DEPS) $(PYTHON_FOR_REGEN) $(srcdir)/Tools/scripts/deepfreeze.py Python/frozen_modules/stat.h -m stat -o Python/deepfreeze/stat.c +Python/deepfreeze/types.c: Python/frozen_modules/types.h $(DEEPFREEZE_DEPS) + $(PYTHON_FOR_REGEN) $(srcdir)/Tools/scripts/deepfreeze.py Python/frozen_modules/types.h -m types -o Python/deepfreeze/types.c + +Python/deepfreeze/importlib.util.c: Python/frozen_modules/importlib.util.h $(DEEPFREEZE_DEPS) + $(PYTHON_FOR_REGEN) $(srcdir)/Tools/scripts/deepfreeze.py Python/frozen_modules/importlib.util.h -m importlib.util -o Python/deepfreeze/importlib.util.c + +Python/deepfreeze/importlib.machinery.c: Python/frozen_modules/importlib.machinery.h $(DEEPFREEZE_DEPS) + $(PYTHON_FOR_REGEN) $(srcdir)/Tools/scripts/deepfreeze.py Python/frozen_modules/importlib.machinery.h -m importlib.machinery -o Python/deepfreeze/importlib.machinery.c + +Python/deepfreeze/runpy.c: Python/frozen_modules/runpy.h $(DEEPFREEZE_DEPS) + $(PYTHON_FOR_REGEN) $(srcdir)/Tools/scripts/deepfreeze.py Python/frozen_modules/runpy.h -m runpy -o Python/deepfreeze/runpy.c + Python/deepfreeze/__hello__.c: Python/frozen_modules/__hello__.h $(DEEPFREEZE_DEPS) $(PYTHON_FOR_REGEN) $(srcdir)/Tools/scripts/deepfreeze.py Python/frozen_modules/__hello__.h -m __hello__ -o Python/deepfreeze/__hello__.c @@ -1029,6 +1045,10 @@ FROZEN_FILES_IN = \ Lib/os.py \ Lib/site.py \ Lib/stat.py \ + Lib/types.py \ + Lib/importlib/util.py \ + Lib/importlib/machinery.py \ + Lib/runpy.py \ Lib/__hello__.py \ Lib/__phello__/__init__.py \ Lib/__phello__/ham/__init__.py \ @@ -1051,6 +1071,10 @@ FROZEN_FILES_OUT = \ Python/frozen_modules/os.h \ Python/frozen_modules/site.h \ Python/frozen_modules/stat.h \ + Python/frozen_modules/types.h \ + Python/frozen_modules/importlib.util.h \ + Python/frozen_modules/importlib.machinery.h \ + Python/frozen_modules/runpy.h \ Python/frozen_modules/__hello__.h \ Python/frozen_modules/__phello__.h \ Python/frozen_modules/__phello__.ham.h \ @@ -1111,6 +1135,18 @@ Python/frozen_modules/site.h: $(FREEZE_MODULE) Lib/site.py Python/frozen_modules/stat.h: $(FREEZE_MODULE) Lib/stat.py $(FREEZE_MODULE) stat $(srcdir)/Lib/stat.py Python/frozen_modules/stat.h +Python/frozen_modules/types.h: $(FREEZE_MODULE) Lib/types.py + $(FREEZE_MODULE) types $(srcdir)/Lib/types.py Python/frozen_modules/types.h + +Python/frozen_modules/importlib.util.h: $(FREEZE_MODULE) Lib/importlib/util.py + $(FREEZE_MODULE) importlib.util $(srcdir)/Lib/importlib/util.py Python/frozen_modules/importlib.util.h + +Python/frozen_modules/importlib.machinery.h: $(FREEZE_MODULE) Lib/importlib/machinery.py + $(FREEZE_MODULE) importlib.machinery $(srcdir)/Lib/importlib/machinery.py Python/frozen_modules/importlib.machinery.h + +Python/frozen_modules/runpy.h: $(FREEZE_MODULE) Lib/runpy.py + $(FREEZE_MODULE) runpy $(srcdir)/Lib/runpy.py Python/frozen_modules/runpy.h + Python/frozen_modules/__hello__.h: $(FREEZE_MODULE) Lib/__hello__.py $(FREEZE_MODULE) __hello__ $(srcdir)/Lib/__hello__.py Python/frozen_modules/__hello__.h diff --git a/PCbuild/_freeze_module.vcxproj b/PCbuild/_freeze_module.vcxproj index 7b2df4b8afcc2c..49f5aa04d57063 100644 --- a/PCbuild/_freeze_module.vcxproj +++ b/PCbuild/_freeze_module.vcxproj @@ -330,6 +330,34 @@ $(IntDir)stat.g.c $(PySourcePath)Python\deepfreeze\df.stat.c + + types + $(IntDir)types.g.h + $(PySourcePath)Python\frozen_modules\types.h + $(IntDir)types.g.c + $(PySourcePath)Python\deepfreeze\df.types.c + + + importlib.util + $(IntDir)importlib.util.g.h + $(PySourcePath)Python\frozen_modules\importlib.util.h + $(IntDir)importlib.util.g.c + $(PySourcePath)Python\deepfreeze\df.importlib.util.c + + + importlib.machinery + $(IntDir)importlib.machinery.g.h + $(PySourcePath)Python\frozen_modules\importlib.machinery.h + $(IntDir)importlib.machinery.g.c + $(PySourcePath)Python\deepfreeze\df.importlib.machinery.c + + + runpy + $(IntDir)runpy.g.h + $(PySourcePath)Python\frozen_modules\runpy.h + $(IntDir)runpy.g.c + $(PySourcePath)Python\deepfreeze\df.runpy.c + __hello__ $(IntDir)__hello__.g.h diff --git a/PCbuild/_freeze_module.vcxproj.filters b/PCbuild/_freeze_module.vcxproj.filters index 1c8f1b0dcf4499..7690e5ee58890a 100644 --- a/PCbuild/_freeze_module.vcxproj.filters +++ b/PCbuild/_freeze_module.vcxproj.filters @@ -447,6 +447,18 @@ Python Files + + Python Files + + + Python Files + + + Python Files + + + Python Files + Python Files diff --git a/PCbuild/pythoncore.vcxproj b/PCbuild/pythoncore.vcxproj index b446e0995565e0..e607208bd70449 100644 --- a/PCbuild/pythoncore.vcxproj +++ b/PCbuild/pythoncore.vcxproj @@ -532,6 +532,10 @@ + + + + diff --git a/Python/frozen.c b/Python/frozen.c index 9f43db70886f79..73fefcd2a6e5b6 100644 --- a/Python/frozen.c +++ b/Python/frozen.c @@ -53,6 +53,10 @@ #include "frozen_modules/os.h" #include "frozen_modules/site.h" #include "frozen_modules/stat.h" +#include "frozen_modules/types.h" +#include "frozen_modules/importlib.util.h" +#include "frozen_modules/importlib.machinery.h" +#include "frozen_modules/runpy.h" #include "frozen_modules/__hello__.h" #include "frozen_modules/__phello__.h" #include "frozen_modules/__phello__.ham.h" @@ -75,10 +79,14 @@ extern PyObject *_Py_get__sitebuiltins_toplevel(void); extern PyObject *_Py_get_genericpath_toplevel(void); extern PyObject *_Py_get_ntpath_toplevel(void); extern PyObject *_Py_get_posixpath_toplevel(void); -extern PyObject *_Py_get_posixpath_toplevel(void); +extern PyObject *_Py_get_ntpath_toplevel(void); extern PyObject *_Py_get_os_toplevel(void); extern PyObject *_Py_get_site_toplevel(void); extern PyObject *_Py_get_stat_toplevel(void); +extern PyObject *_Py_get_types_toplevel(void); +extern PyObject *_Py_get_importlib_util_toplevel(void); +extern PyObject *_Py_get_importlib_machinery_toplevel(void); +extern PyObject *_Py_get_runpy_toplevel(void); extern PyObject *_Py_get___hello___toplevel(void); extern PyObject *_Py_get___hello___toplevel(void); extern PyObject *_Py_get___hello___toplevel(void); @@ -112,10 +120,16 @@ static const struct _frozen stdlib_modules[] = { {"genericpath", _Py_M__genericpath, (int)sizeof(_Py_M__genericpath), GET_CODE(genericpath)}, {"ntpath", _Py_M__ntpath, (int)sizeof(_Py_M__ntpath), GET_CODE(ntpath)}, {"posixpath", _Py_M__posixpath, (int)sizeof(_Py_M__posixpath), GET_CODE(posixpath)}, - {"os.path", _Py_M__posixpath, (int)sizeof(_Py_M__posixpath), GET_CODE(posixpath)}, + {"os.path", _Py_M__ntpath, (int)sizeof(_Py_M__ntpath), GET_CODE(ntpath)}, {"os", _Py_M__os, (int)sizeof(_Py_M__os), GET_CODE(os)}, {"site", _Py_M__site, (int)sizeof(_Py_M__site), GET_CODE(site)}, {"stat", _Py_M__stat, (int)sizeof(_Py_M__stat), GET_CODE(stat)}, + + /* runpy - run module with -m */ + {"types", _Py_M__types, (int)sizeof(_Py_M__types), GET_CODE(types)}, + {"importlib.util", _Py_M__importlib_util, (int)sizeof(_Py_M__importlib_util), GET_CODE(importlib_util)}, + {"importlib.machinery", _Py_M__importlib_machinery, (int)sizeof(_Py_M__importlib_machinery), GET_CODE(importlib_machinery)}, + {"runpy", _Py_M__runpy, (int)sizeof(_Py_M__runpy), GET_CODE(runpy)}, {0, 0, 0} /* stdlib sentinel */ }; static const struct _frozen test_modules[] = { @@ -139,7 +153,7 @@ const struct _frozen *_PyImport_FrozenTest = test_modules; static const struct _module_alias aliases[] = { {"_frozen_importlib", "importlib._bootstrap"}, {"_frozen_importlib_external", "importlib._bootstrap_external"}, - {"os.path", "posixpath"}, + {"os.path", "ntpath"}, {"__hello_alias__", "__hello__"}, {"__phello_alias__", "__hello__"}, {"__phello_alias__.spam", "__hello__"}, diff --git a/Tools/scripts/freeze_modules.py b/Tools/scripts/freeze_modules.py index 7496b6c868407e..44d071e6e7633c 100644 --- a/Tools/scripts/freeze_modules.py +++ b/Tools/scripts/freeze_modules.py @@ -68,6 +68,12 @@ 'site', 'stat', ]), + ('runpy - run module with -m', [ + "types", + "importlib.util", + "importlib.machinery", + "runpy" + ]), (TESTS_SECTION, [ '__hello__', '__hello__ : __hello_alias__', From dd7a0f6e7f1181aa50ba70c015d0336beaafa102 Mon Sep 17 00:00:00 2001 From: Kumar Aditya Date: Fri, 3 Dec 2021 11:16:52 +0000 Subject: [PATCH 2/4] fix posixpath --- Python/frozen.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Python/frozen.c b/Python/frozen.c index 73fefcd2a6e5b6..377c32249a83e5 100644 --- a/Python/frozen.c +++ b/Python/frozen.c @@ -79,7 +79,7 @@ extern PyObject *_Py_get__sitebuiltins_toplevel(void); extern PyObject *_Py_get_genericpath_toplevel(void); extern PyObject *_Py_get_ntpath_toplevel(void); extern PyObject *_Py_get_posixpath_toplevel(void); -extern PyObject *_Py_get_ntpath_toplevel(void); +extern PyObject *_Py_get_posixpath_toplevel(void); extern PyObject *_Py_get_os_toplevel(void); extern PyObject *_Py_get_site_toplevel(void); extern PyObject *_Py_get_stat_toplevel(void); @@ -120,7 +120,7 @@ static const struct _frozen stdlib_modules[] = { {"genericpath", _Py_M__genericpath, (int)sizeof(_Py_M__genericpath), GET_CODE(genericpath)}, {"ntpath", _Py_M__ntpath, (int)sizeof(_Py_M__ntpath), GET_CODE(ntpath)}, {"posixpath", _Py_M__posixpath, (int)sizeof(_Py_M__posixpath), GET_CODE(posixpath)}, - {"os.path", _Py_M__ntpath, (int)sizeof(_Py_M__ntpath), GET_CODE(ntpath)}, + {"os.path", _Py_M__posixpath, (int)sizeof(_Py_M__posixpath), GET_CODE(posixpath)}, {"os", _Py_M__os, (int)sizeof(_Py_M__os), GET_CODE(os)}, {"site", _Py_M__site, (int)sizeof(_Py_M__site), GET_CODE(site)}, {"stat", _Py_M__stat, (int)sizeof(_Py_M__stat), GET_CODE(stat)}, @@ -153,7 +153,7 @@ const struct _frozen *_PyImport_FrozenTest = test_modules; static const struct _module_alias aliases[] = { {"_frozen_importlib", "importlib._bootstrap"}, {"_frozen_importlib_external", "importlib._bootstrap_external"}, - {"os.path", "ntpath"}, + {"os.path", "posixpath"}, {"__hello_alias__", "__hello__"}, {"__phello_alias__", "__hello__"}, {"__phello_alias__.spam", "__hello__"}, From 8b2a791c731f5e4b3239162d332b6e91dc205c04 Mon Sep 17 00:00:00 2001 From: Kumar Aditya Date: Sat, 4 Dec 2021 16:10:53 +0000 Subject: [PATCH 3/4] regen all --- Makefile.pre.in | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile.pre.in b/Makefile.pre.in index 47fdb563f46cdd..f6801353cfeb46 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -1015,16 +1015,16 @@ Python/deepfreeze/stat.c: Python/frozen_modules/stat.h $(DEEPFREEZE_DEPS) $(PYTHON_FOR_FREEZE) $(srcdir)/Tools/scripts/deepfreeze.py Python/frozen_modules/stat.h -m stat -o Python/deepfreeze/stat.c Python/deepfreeze/types.c: Python/frozen_modules/types.h $(DEEPFREEZE_DEPS) - $(PYTHON_FOR_REGEN) $(srcdir)/Tools/scripts/deepfreeze.py Python/frozen_modules/types.h -m types -o Python/deepfreeze/types.c + $(PYTHON_FOR_FREEZE) $(srcdir)/Tools/scripts/deepfreeze.py Python/frozen_modules/types.h -m types -o Python/deepfreeze/types.c Python/deepfreeze/importlib.util.c: Python/frozen_modules/importlib.util.h $(DEEPFREEZE_DEPS) - $(PYTHON_FOR_REGEN) $(srcdir)/Tools/scripts/deepfreeze.py Python/frozen_modules/importlib.util.h -m importlib.util -o Python/deepfreeze/importlib.util.c + $(PYTHON_FOR_FREEZE) $(srcdir)/Tools/scripts/deepfreeze.py Python/frozen_modules/importlib.util.h -m importlib.util -o Python/deepfreeze/importlib.util.c Python/deepfreeze/importlib.machinery.c: Python/frozen_modules/importlib.machinery.h $(DEEPFREEZE_DEPS) - $(PYTHON_FOR_REGEN) $(srcdir)/Tools/scripts/deepfreeze.py Python/frozen_modules/importlib.machinery.h -m importlib.machinery -o Python/deepfreeze/importlib.machinery.c + $(PYTHON_FOR_FREEZE) $(srcdir)/Tools/scripts/deepfreeze.py Python/frozen_modules/importlib.machinery.h -m importlib.machinery -o Python/deepfreeze/importlib.machinery.c Python/deepfreeze/runpy.c: Python/frozen_modules/runpy.h $(DEEPFREEZE_DEPS) - $(PYTHON_FOR_REGEN) $(srcdir)/Tools/scripts/deepfreeze.py Python/frozen_modules/runpy.h -m runpy -o Python/deepfreeze/runpy.c + $(PYTHON_FOR_FREEZE) $(srcdir)/Tools/scripts/deepfreeze.py Python/frozen_modules/runpy.h -m runpy -o Python/deepfreeze/runpy.c Python/deepfreeze/__hello__.c: Python/frozen_modules/__hello__.h $(DEEPFREEZE_DEPS) $(PYTHON_FOR_FREEZE) $(srcdir)/Tools/scripts/deepfreeze.py Python/frozen_modules/__hello__.h -m __hello__ -o Python/deepfreeze/__hello__.c From cfd4301b5dbdd42a951661d11a87c2c761c216c6 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Thu, 9 Dec 2021 11:57:44 +0000 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Core and Builtins/2021-12-09-11-57-43.bpo-45654.MZc7ei.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2021-12-09-11-57-43.bpo-45654.MZc7ei.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2021-12-09-11-57-43.bpo-45654.MZc7ei.rst b/Misc/NEWS.d/next/Core and Builtins/2021-12-09-11-57-43.bpo-45654.MZc7ei.rst new file mode 100644 index 00000000000000..9072558a30e9ad --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2021-12-09-11-57-43.bpo-45654.MZc7ei.rst @@ -0,0 +1 @@ +Deepfreeze :mod:`runpy`, patch by Kumar Aditya. \ No newline at end of file