From 079a07a0065feeb2950c3584378daee01fac3274 Mon Sep 17 00:00:00 2001 From: Jun Komoda <45822440+junkmd@users.noreply.github.com> Date: Fri, 14 Jun 2024 22:53:17 +0000 Subject: [PATCH 1/5] add `_post_coinit` directory subpackage - move `unknwn` into `_post_coinit` - add `_post_coinit` to `setup.cfg` --- comtypes/__init__.py | 3 ++- comtypes/_post_coinit/__init__.py | 14 ++++++++++++++ comtypes/{ => _post_coinit}/unknwn.py | 0 setup.cfg | 1 + 4 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 comtypes/_post_coinit/__init__.py rename comtypes/{ => _post_coinit}/unknwn.py (100%) diff --git a/comtypes/__init__.py b/comtypes/__init__.py index a3497514..16e4f003 100644 --- a/comtypes/__init__.py +++ b/comtypes/__init__.py @@ -175,7 +175,8 @@ def CoUninitialize(): ################################################################ # IUnknown, the root of all evil... -from comtypes.unknwn import IUnknown, _shutdown # noqa +from comtypes._post_coinit import _shutdown +from comtypes._post_coinit.unknwn import IUnknown # noqa atexit.register(_shutdown) diff --git a/comtypes/_post_coinit/__init__.py b/comtypes/_post_coinit/__init__.py new file mode 100644 index 00000000..806fda91 --- /dev/null +++ b/comtypes/_post_coinit/__init__.py @@ -0,0 +1,14 @@ +"""comtypes._post_coinit + +This subpackage contains basic interfaces and functions that are defined or used +during the initialization of the `comtypes` package. + +These were previously defined in `comtypes/__init__.py`, but due to the codebase +of the file becoming bloated, reducing the ease of changes and increasing +cognitive load, they have been moved here. + +This subpackage is called simultaneously with the initialization of `comtypes`. +So it is necessary to maintain minimal settings to keep the lightweight action +when the package is initialized. +""" +from comtypes._post_coinit.unknwn import _shutdown # noqa diff --git a/comtypes/unknwn.py b/comtypes/_post_coinit/unknwn.py similarity index 100% rename from comtypes/unknwn.py rename to comtypes/_post_coinit/unknwn.py diff --git a/setup.cfg b/setup.cfg index 55811cea..29e49318 100644 --- a/setup.cfg +++ b/setup.cfg @@ -22,6 +22,7 @@ python_requires = >=3.7 packages = comtypes + comtypes._post_coinit comtypes.client comtypes.server comtypes.tools From 8cc46778717ba3695afc2d98e3377779679e22df Mon Sep 17 00:00:00 2001 From: Jun Komoda <45822440+junkmd@users.noreply.github.com> Date: Fri, 14 Jun 2024 22:53:17 +0000 Subject: [PATCH 2/5] update subpackage docstring --- comtypes/_post_coinit/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/comtypes/_post_coinit/__init__.py b/comtypes/_post_coinit/__init__.py index 806fda91..5f615735 100644 --- a/comtypes/_post_coinit/__init__.py +++ b/comtypes/_post_coinit/__init__.py @@ -1,7 +1,8 @@ """comtypes._post_coinit -This subpackage contains basic interfaces and functions that are defined or used -during the initialization of the `comtypes` package. +This subpackage contains symbols that should be imported into `comtypes/__init__.py` +after `CoInitializeEx` is defined and called, and symbols that can be defined in +any order during the initialization of the `comtypes` package. These were previously defined in `comtypes/__init__.py`, but due to the codebase of the file becoming bloated, reducing the ease of changes and increasing From 6dceedbf3c7a68b2694c4736272528adbd334067 Mon Sep 17 00:00:00 2001 From: Jun Komoda <45822440+junkmd@users.noreply.github.com> Date: Fri, 14 Jun 2024 22:53:17 +0000 Subject: [PATCH 3/5] move from `_bstr.py` to `comtypes/_post_coinit/bstr.py` --- comtypes/__init__.py | 5 ++++- comtypes/{_bstr.py => _post_coinit/bstr.py} | 0 2 files changed, 4 insertions(+), 1 deletion(-) rename comtypes/{_bstr.py => _post_coinit/bstr.py} (100%) diff --git a/comtypes/__init__.py b/comtypes/__init__.py index 16e4f003..f076fc33 100644 --- a/comtypes/__init__.py +++ b/comtypes/__init__.py @@ -39,7 +39,6 @@ from comtypes import patcher # noqa from comtypes._npsupport import interop as npsupport # noqa from comtypes._tlib_version_checker import _check_version # noqa -from comtypes._bstr import BSTR # noqa from comtypes._py_instance_method import instancemethod # noqa from comtypes._idl_stuff import defaultvalue, helpstring, dispid # noqa from comtypes._idl_stuff import STDMETHOD, DISPMETHOD, DISPPROPERTY, COMMETHOD # noqa @@ -180,6 +179,10 @@ def CoUninitialize(): atexit.register(_shutdown) +################################################################ + +from comtypes._post_coinit.bstr import BSTR # noqa + ################################################################ # IPersist is a trivial interface, which allows to ask an object about diff --git a/comtypes/_bstr.py b/comtypes/_post_coinit/bstr.py similarity index 100% rename from comtypes/_bstr.py rename to comtypes/_post_coinit/bstr.py From b54420491425474335baacbcc776c7264a0725a4 Mon Sep 17 00:00:00 2001 From: Jun Komoda <45822440+junkmd@users.noreply.github.com> Date: Fri, 14 Jun 2024 22:53:17 +0000 Subject: [PATCH 4/5] move from `_base.py` to `_post_coinit/misc.py` --- comtypes/__init__.py | 4 ++-- comtypes/{_base.py => _post_coinit/misc.py} | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename comtypes/{_base.py => _post_coinit/misc.py} (100%) diff --git a/comtypes/__init__.py b/comtypes/__init__.py index f076fc33..f5e8d773 100644 --- a/comtypes/__init__.py +++ b/comtypes/__init__.py @@ -187,13 +187,13 @@ def CoUninitialize(): ################################################################ # IPersist is a trivial interface, which allows to ask an object about # its clsid. -from comtypes._base import IPersist, IServiceProvider # noqa +from comtypes._post_coinit.misc import IPersist, IServiceProvider # noqa ################################################################ -from comtypes._base import ( # noqa +from comtypes._post_coinit.misc import ( # noqa _is_object, CoGetObject, CoCreateInstance, diff --git a/comtypes/_base.py b/comtypes/_post_coinit/misc.py similarity index 100% rename from comtypes/_base.py rename to comtypes/_post_coinit/misc.py From 0770a0715f3b8ea1036170d5c000e323ca79f7ca Mon Sep 17 00:00:00 2001 From: Jun Komoda <45822440+junkmd@users.noreply.github.com> Date: Fri, 14 Jun 2024 22:53:17 +0000 Subject: [PATCH 5/5] update import sources --- comtypes/_post_coinit/misc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/comtypes/_post_coinit/misc.py b/comtypes/_post_coinit/misc.py index 6db57221..3087414b 100644 --- a/comtypes/_post_coinit/misc.py +++ b/comtypes/_post_coinit/misc.py @@ -19,7 +19,7 @@ from comtypes._idl_stuff import COMMETHOD # noqa from comtypes import CLSCTX_SERVER, CLSCTX_LOCAL_SERVER, CLSCTX_REMOTE_SERVER from comtypes import _ole32, oledll, DWORD -from comtypes import IUnknown +from comtypes._post_coinit.unknwn import IUnknown def _is_object(obj):