Skip to content

Commit 8c3e7e2

Browse files
v2.7.0
+ Modified `automatic-release.yml` and `pypi.yml` workflows to check the version. + Added the support for more `type`s to pass to `ColorizingArgumentParser().add_argument(...)`: `typing.Union`, `typing.Optional`, `typing.Literal`, `enum.Enum`, `tuple` and `typing.Required`. + Modified the way `Enum`s are handled in the Argument Parser. + Handled some `typing._SpecialForm`s. + A normal ArgumentGroup can now be required! (Unlike MutuallyExclusiveGroup it can have more than 1 option used at the same time) + `argumentify` now supports async functions as the entry point.
1 parent 8fb9a3b commit 8c3e7e2

5 files changed

Lines changed: 41 additions & 13 deletions

File tree

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@ Help this project by [Donation](DONATE.md)
66
Changes
77
-----------
88

9+
### 2.7.0
10+
11+
+ Modified `automatic-release.yml` and `pypi.yml` workflows to check the
12+
version
13+
+ Added the support for more `type`s to pass to
14+
`ColorizingArgumentParser().add_argument(...)`: `typing.Union`, `typing.Optional`,
15+
`typing.Literal`, `enum.Enum`, `tuple` and `typing.Required`.
16+
+ Modified the way `Enum`s are handled in the Argument Parser.
17+
+ Handled some `typing._SpecialForm`s.
18+
+ A normal ArgumentGroup can now be required! (Unlike MutuallyExclusiveGroup it can
19+
have more than 1 option used at the same time)
20+
+ `argumentify` now supports async functions as the entry point.
21+
922
### 2.6.2
1023

1124
Change in README.md.

README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,18 @@ pip install git+https://github.com/MPCodeWriter21/log21
6161
Changes
6262
-------
6363

64-
### 2.6.2
65-
66-
Change in README.md.
64+
### 2.7.0
65+
66+
+ Modified `automatic-release.yml` and `pypi.yml` workflows to check the
67+
version.
68+
+ Added the support for more `type`s to pass to
69+
`ColorizingArgumentParser().add_argument(...)`: `typing.Union`, `typing.Optional`,
70+
`typing.Literal`, `enum.Enum`, `tuple` and `typing.Required`.
71+
+ Modified the way `Enum`s are handled in the Argument Parser.
72+
+ Handled some `typing._SpecialForm`s.
73+
+ A normal ArgumentGroup can now be required! (Unlike MutuallyExclusiveGroup it can
74+
have more than 1 option used at the same time)
75+
+ `argumentify` now supports async functions as the entry point.
6776

6877
[Full CHANGELOG](https://github.com/MPCodeWriter21/log21/blob/master/CHANGELOG.md)
6978

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ dependencies = [
2626
"webcolors",
2727
"docstring-parser"
2828
]
29-
version = "2.7.0rc1"
29+
version = "2.7.0"
3030

3131
[tool.setuptools.packages.find]
3232
where = ["src"]

src/log21/Argumentify.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33

44
import re as _re
55
import string as _string
6+
import asyncio as _asyncio
67
import inspect as _inspect
7-
from typing import (
8-
Any as _Any, Set as _Set, Dict as _Dict, List as _List, Tuple as _Tuple, Union as
9-
_Union, Callable as _Callable, Optional as _Optional, Coroutine as _Coroutine,
10-
OrderedDict as _OrderedDict
11-
)
8+
from typing import (Any as _Any, Set as _Set, Dict as _Dict, List as _List,
9+
Tuple as _Tuple, Union as _Union, Callable as _Callable,
10+
Optional as _Optional, Awaitable as _Awaitable,
11+
Coroutine as _Coroutine, OrderedDict as _OrderedDict)
1212
from dataclasses import field as _field, dataclass as _dataclass
1313

1414
from docstring_parser import Docstring as _Docstring, parse as _parse
@@ -151,7 +151,7 @@ class FunctionInfo:
151151
"""Represents a function."""
152152
function: Callable
153153
name: str = _field(init=False)
154-
arguments: _Dict[str, Argument] = _field(init=False)
154+
arguments: _OrderedDict[str, Argument] = _field(init=False)
155155
docstring: _Docstring = _field(init=False)
156156
parser: _Argparse.ColorizingArgumentParser = _field(init=False)
157157

@@ -313,7 +313,10 @@ def _argumentify_one(func: Callable):
313313
args.extend(getattr(cli_args, argument.name) or [])
314314
else:
315315
kwargs[argument.name] = getattr(cli_args, argument.name)
316-
func(*args, **kwargs)
316+
result = func(*args, **kwargs)
317+
# Check if the result is a coroutine
318+
if isinstance(result, (_Coroutine, _Awaitable)):
319+
_asyncio.run(result)
317320

318321

319322
def _argumentify(functions: _Dict[str, Callable]):
@@ -359,7 +362,10 @@ def _argumentify(functions: _Dict[str, Callable]):
359362
args.extend(getattr(cli_args, argument.name) or [])
360363
else:
361364
kwargs[argument.name] = getattr(cli_args, argument.name)
362-
function(*args, **kwargs)
365+
result = function(*args, **kwargs)
366+
# Check if the result is a coroutine
367+
if isinstance(result, (_Coroutine, _Awaitable)):
368+
_asyncio.run(result)
363369

364370

365371
def argumentify(entry_point: _Union[Callable, _List[Callable], _Dict[str, Callable]]):

src/log21/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from log21.LoggingWindow import LoggingWindow, LoggingWindowHandler
2525
from log21.StreamHandler import StreamHandler, ColorizingStreamHandler
2626

27-
__version__ = "2.7.0rc1"
27+
__version__ = "2.7.0"
2828
__author__ = "CodeWriter21 (Mehrad Pooryoussof)"
2929
__github__ = "Https://GitHub.com/MPCodeWriter21/log21"
3030
__all__ = [

0 commit comments

Comments
 (0)