Skip to content

Commit 0b1a273

Browse files
committed
fix: final corrections and clean-up before publication
final alignment with cookiecutter-template the-hatchlor-enhanced, fix/complete type annotations and docstrings, include test_dummy.py
1 parent f8509c7 commit 0b1a273

File tree

7 files changed

+87
-46
lines changed

7 files changed

+87
-46
lines changed
Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
{% if not incremental %}
22
# CHANGELOG
3-
4-
53
{% endif %}
6-
{# MACRO: Capitalize the first letter of a string only #}
7-
{% macro capitalize_first_letter_only(sentence) %}
4+
{# Macro: Capitalize the first letter of a string only #}
5+
{% macro capitalize_first_letter_only(sentence) %}
86
{{ (sentence[0] | upper) ~ sentence[1:] }}
9-
{% endmacro %}
7+
{% endmacro %}
108

119
{% for entry in tree %}
1210

13-
## [{{ entry.version }}](https://github.com/dornech/pytestdornech/releases/tag/{{ entry.version }}) {% if entry.date %}({{ entry.date }}){% endif %}
11+
12+
## [{{ entry.version }}](https://github.com/dornech/utils-COMobjects/releases/tag/{{ entry.version }}) {% if entry.date %} ({{ entry.date }}) {% endif %}
1413

1514
{% for change_type, changes in entry.changes.items() %}
1615

@@ -19,11 +18,10 @@
1918
{% endif %}
2019
{% for change in changes %}
2120
{% if change.scope %}
22-
- **{{ change.scope }}**: {{ capitalize_first_letter_only(change.message) }} (['{{ change.sha1[:7] }}'](https://github.com/dornech/pytestdornech/commit/{{ change.sha1 }}))
21+
- **{{ change.scope }}**: {{ capitalize_first_letter_only(change.message) }} (['{{ change.sha1[:7] }}'](https://github.com/dornech/utils-COMobjects/commit/{{ change.sha1 }}))
2322
{% elif change.message %}
24-
- {{ capitalize_first_letter_only(change.message) }}(['{{ change.sha1[:7] }}'](https://github.com/dornech/pytestdornech/commit/{{ change.sha1 }}))
23+
- {{ capitalize_first_letter_only(change.message) }}(['{{ change.sha1[:7] }}'](https://github.com/dornech/utils-COMobjects/commit/{{ change.sha1 }}))
2524
{% endif %}
26-
2725
{% endfor %}
2826
{% endfor %}
2927
{% endfor %}

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ if __name__ == "__main__":
227227
UtilsCOMobjects.UtilsCOMcheckreg.processCOMregistration(PyCOMtest_typelibClass2, gentypelib=True, testmode=True)
228228
UtilsCOMobjects.UtilsCOMcheckreg.processCOMregistration(PyCOMtest_typelibClass3, gentypelib=True, testmode=True)
229229
```
230+
230231
## Navigation
231232

232233
Documentation for specific `MAJOR.MINOR` versions can be chosen by using the dropdown on the top of every page.

src/utils_COMobjects/utils_COM_checkreg.py

Lines changed: 50 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,13 @@ class ErrorCOMregistration(Exception):
5656
# check COM registration readiness
5757

5858

59-
# get filename of module
60-
def getmodulefile():
59+
def getmodulefile() -> str:
60+
"""
61+
getmodulefile - get filename of module
62+
63+
Returns:
64+
str: filename of calling module
65+
"""
6166

6267
if sys.argv[0] != "-c":
6368
script = sys.argv[0]
@@ -67,18 +72,37 @@ def getmodulefile():
6772
return os.path.basename(script).split(".")[0]
6873
# return pathlib.Path(script).name.split(".")[0]
6974

70-
# check valid uuid
71-
# alternative: use is_uuid from validator-collection
7275
def is_valid_uuid(uuid_to_test: str, version=4) -> bool:
76+
"""
77+
is_valid_uuid - check uuid is valid
78+
79+
alternative: use is_uuid from validator-collection
80+
81+
Args:
82+
uuid_to_test (str): UUID to test.
83+
version (int): UUID-verison. Default is 4.
84+
85+
Returns:
86+
bool: uuid is valid or not
87+
"""
7388

7489
try:
7590
uuid_obj = UUID(uuid_to_test, version=version)
7691
except ValueError:
7792
return False
78-
return (str(uuid_obj).upper() == uuid_to_test.upper()) or (str(uuid_obj).upper() == uuid_to_test[1:-1].upper()) # type: ignore[no-any-return]
93+
return (str(uuid_obj).upper() == uuid_to_test.upper()) or (str(uuid_obj).upper() == uuid_to_test[1:-1].upper())
7994

80-
# check registry key
8195
def checkRegKey(regroot: int, regpath: str) -> bool:
96+
"""
97+
checkRegKey - check registry key
98+
99+
Args:
100+
regroot (int): registry root
101+
regpath (str): registry path to check
102+
103+
Returns:
104+
bool: chec k result if registry path exists under root (or not)
105+
"""
82106

83107
try:
84108
with winreg.OpenKey(regroot, regpath) as regkey:
@@ -87,13 +111,24 @@ def checkRegKey(regroot: int, regpath: str) -> bool:
87111
except OSError:
88112
return False
89113

90-
# check single COM registration attribute
91114
def checkCOMattrib(
92115
cls: type[COMclass.baseCOMclass],
93116
attrib: str,
94117
checkfunction: Union[Callable, None] = None,
95118
optional: bool = False
96119
) -> bool:
120+
"""
121+
checkCOMattrib - check single COM class registration attribute
122+
123+
Args:
124+
cls (COMclass.baseCOMclass): class to be checked
125+
attrib (str): attribute to be checked
126+
checkfunction (Callable): specific check function
127+
optional (bool): positive check result optional (i. e. if True only message is generated)
128+
129+
Returns:
130+
bool: check result
131+
"""
97132

98133
if hasattr(cls, attrib):
99134
attribvalue = getattr(cls, attrib)
@@ -114,7 +149,6 @@ def checkCOMattrib(
114149
return False or optional
115150

116151

117-
# check COM registration readiness - basic COM object attributes
118152
def checkAttribsCOM(cls: type[COMclass.baseCOMclass], checkpubattrib: bool = False) -> bool:
119153
"""
120154
checkAttribsCOM - check COM registration readiness, basic COM object attributes
@@ -213,8 +247,6 @@ def check_attribs_COM(cls: type[COMclass.baseCOMclass], checkpubattrib: bool = F
213247
return checkAttribsCOM(cls, checkpubattrib)
214248

215249

216-
217-
# check COM registration readiness - Typelib registration readiness;
218250
def checkAttribsTypeLib(
219251
cls: Union[type[COMclass.baseCOMclass], type[COMclass.typelibCOMclass]],
220252
clsmodule: Optional[types.ModuleType] = None
@@ -380,15 +412,14 @@ def check_attribs_typelib(
380412
return checkAttribsTypeLib(cls, clsmodule)
381413

382414

383-
384-
# COM registration caller
385-
# to register class add following call in object module
386-
# if __name__ == '__main__':
387-
# <import name of this module>.processCOMregistration(<classname>)
388-
def processCOMregistration(cls: type[COMclass.baseCOMclass], gentypelib: bool = False, testmode: bool = False):
415+
def processCOMregistration(cls: type[COMclass.baseCOMclass], gentypelib: bool = False, testmode: bool = False) -> None:
389416
"""
390417
processCOMregistration - check and register Python COM object class as COM object
391418
419+
To register class add following call in object module:
420+
if __name__ == '__main__':
421+
<import name of this module>.processCOMregistration(<classname>)
422+
392423
Args:
393424
cls (type[COMclass.baseCOMclass]): Python COM object class to be registered
394425
gentypelib (bool, optional): activate typelib generation. Defaults to False.
@@ -478,8 +509,7 @@ def checkRegistryTypelibID(tlbid):
478509
errorhandling(f"COM registration requested for instance not object class. Try registration for {cls.__class__.__name__}.", testmode)
479510
print()
480511

481-
482-
def process_COM_registration(cls: type[COMclass.baseCOMclass], gentypelib: bool = False, testmode: bool = False):
512+
def process_COM_registration(cls: type[COMclass.baseCOMclass], gentypelib: bool = False, testmode: bool = False) -> None:
483513
"""
484514
process_COM_registration - check and register Python COM object class as COM object
485515
@@ -491,9 +521,7 @@ def process_COM_registration(cls: type[COMclass.baseCOMclass], gentypelib: bool
491521
processCOMregistration(cls, gentypelib, testmode)
492522

493523

494-
495-
# COM object - list of public methods
496-
def printCOMpublicmethods(cls: Union[COMclass.baseCOMclass, COMclass.typelibCOMclass, Any]):
524+
def printCOMpublicmethods(cls: Union[COMclass.baseCOMclass, COMclass.typelibCOMclass, Any]) -> None:
497525
"""
498526
printCOMpublicmethods - print public methods of Python COM object class
499527
@@ -510,7 +538,7 @@ def printCOMpublicmethods(cls: Union[COMclass.baseCOMclass, COMclass.typelibCOMc
510538
print(f" Signature: {inspect.signature(member[1])}")
511539
print(f" {inspect.getfullargspec(member[1])}")
512540

513-
def print_COM_publicmethods(cls: Union[COMclass.baseCOMclass, COMclass.typelibCOMclass, object]):
541+
def print_COM_publicmethods(cls: Union[COMclass.baseCOMclass, COMclass.typelibCOMclass, object]) -> None:
514542
"""
515543
print_COM_publicmethods - print public methods of Python COM object class
516544

src/utils_COMobjects/utils_COM_classes.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,9 @@
5656

5757
import winreg
5858
import pythoncom
59-
# import win32com.server.register
60-
# from win32com.server.exception import COMException
6159

6260

6361

64-
# base class without typelib for DesignatedWrapPolicy or EventHandlerPolicy based hereupon
6562
class baseCOMclass(ABC):
6663
"""
6764
baseCOMclass - abstract base class for COM objects in Python
@@ -171,7 +168,6 @@ def _checkDebug(cls) -> bool:
171168
# https://pythonhosted.org/comtypes/server.html
172169

173170

174-
# base class with typelib
175171
class typelibCOMclass(baseCOMclass):
176172
"""
177173
typelibCOMclass - abstract base class for COM objects with typelib in Python

src/utils_COMobjects/utils_COM_logging.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050

5151

5252

53-
# mixin class for logging
5453
class mixinCOMclass_logger:
5554
"""
5655
mixin class for logging

src/utils_COMobjects/utils_COM_typelib.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,16 @@
7070

7171

7272

73-
# typelib generation - typelib per class or common typelib for all classes in py-file with same typelib assignment
74-
def generateIDL(cls, clsmodule: types.ModuleType) -> bool:
73+
# typelib generation - typelib per class or common typelib for all classes in py-file with same typelib assignment
74+
def generateIDL(cls, clsmodule: types.ModuleType) -> bool: # docsig: disable=SIG101
7575

76-
def setinterface(classname, cominterfaces: list[str]) -> str:
76+
def setinterface(classname, cominterfaces: list[str]) -> str: # docsig: disable=SIG101
7777
if len(cominterfaces) == 0:
7878
return "I" + str(classname)
7979
else:
8080
return cominterfaces[0]
8181

82-
def PythonTypeToIDLType(annotations, argname: str) -> str:
82+
def PythonTypeToIDLType(annotations, argname: str) -> str: # docsig: disable=SIG101
8383
argtypeIDL = None
8484
try:
8585
if argname in annotations:
@@ -245,7 +245,7 @@ def PythonTypeToIDLType(annotations, argname: str) -> str:
245245
return okIDL
246246

247247
# typelib compilation (i. e. call Microsoft IDL compiler midl.exe)
248-
def compileTypeLib(cls):
248+
def compileTypeLib(cls): # docsig: disable=SIG101
249249
idl = get_filename(cls)
250250
tlb = os.path.splitext(idl)[0] + '.tlb'
251251
# tlb = pathlib.Path(idl).stem + '.tlb'
@@ -269,7 +269,7 @@ def compileTypeLib(cls):
269269
# registration and unregistration (see Python code in win32com.server.register)
270270

271271
# register typelib
272-
def registerTypeLib(cls):
272+
def registerTypeLib(cls): # docsig: disable=SIG101
273273

274274
def registerTypeLibfile(tlbfile: str):
275275
tlbfile = os.path.abspath(tlbfile)
@@ -285,7 +285,7 @@ def registerTypeLibfile(tlbfile: str):
285285
registerTypeLibfile(tlbfile)
286286

287287
# unregister typelib - copy from win32com.server.register
288-
def unregister_typelib(cls):
288+
def unregister_typelib(cls): # docsig: disable=SIG101
289289
tlb_guid = getattr(cls, "_typelib_guid_")
290290
major, minor = getattr(cls, "_typelib_version_", (1, 0))
291291
lcid = getattr(cls, "_typelib_lcid_", 0)
@@ -300,15 +300,16 @@ def unregister_typelib(cls):
300300
# utilities for typelib generation
301301

302302
# get classes with same typelib assignment via _reg_typelib_filename_
303-
def get_typelib_classes(cls, clsmodule: types.ModuleType) -> list[Any]:
303+
def get_typelib_classes(cls, clsmodule: types.ModuleType) -> list[Any]: # docsig: disable=SIG101
304304
tlbfile = cls._reg_typelib_filename_
305305
if tlbfile == "":
306306
return [cls]
307307
else:
308308
return inspect.getmembers(clsmodule, lambda clsmember: getattr(clsmember, "_reg_typelib_filename_", "") == tlbfile and inspect.isclass)
309309

310310
# filename for typelib IDL belonging to class(es)
311-
def get_filename(cls, ext: str = ".idl"):
311+
# docsig: disable=SIG101
312+
def get_filename(cls, ext: str = ".idl") -> str: # docsig: disable=SIG101
312313
if cls._reg_typelib_filename_ == "" or cls._reg_typelib_filename_ == cls.__name__ + ".tlb" or cls._reg_typelib_filename_ == cls.__name__:
313314
return os.path.join(os.path.dirname(inspect.getfile(cls)), cls.__name__ + ext)
314315
# return pathlib.Path(inspect.getfile(cls)).parent.joinpath(cls.__name__ + ext)
@@ -317,5 +318,5 @@ def get_filename(cls, ext: str = ".idl"):
317318
# return pathlib.Path(inspect.getfile(cls)).parent.joinpath(pathlib.Path(cls._reg_typelib_filename_).stem + ext)
318319

319320
# get enum classes in module
320-
def get_enum_classes(clsmodule: types.ModuleType) -> list[Any]:
321+
def get_enum_classes(clsmodule: types.ModuleType) -> list[Any]: # docsig: disable=SIG101
321322
return inspect.getmembers(clsmodule, lambda clsmember: getattr(getattr(clsmember, "__base__", ""), "__name__", "") == "Enum" and inspect.isclass)

tests/test_dummy.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# dummy test
2+
3+
4+
# ruff and mypy per file settings
5+
#
6+
# empty lines
7+
# ruff: noqa: E302, E303
8+
# naming conventions
9+
# ruff: noqa: N801, N802, N803, N806, N812, N813, N815, N816, N818, N999
10+
# others
11+
# ruff: noqa: F401
12+
13+
14+
import pytest
15+
16+
17+
def test_dummy():
18+
pass

0 commit comments

Comments
 (0)