diff --git a/CHANGELOG.md b/CHANGELOG.md index 22c5440..71967c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,19 @@ Help this project by [Donation](DONATE.md) Changes ----------- +### 2.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. + ### 2.6.2 Change in README.md. diff --git a/README.md b/README.md index 16e481c..1ca9497 100644 --- a/README.md +++ b/README.md @@ -61,9 +61,18 @@ pip install git+https://github.com/MPCodeWriter21/log21 Changes ------- -### 2.6.2 - -Change in README.md. +### 2.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. [Full CHANGELOG](https://github.com/MPCodeWriter21/log21/blob/master/CHANGELOG.md) diff --git a/pyproject.toml b/pyproject.toml index 90df2a8..4e816fc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,7 +26,7 @@ dependencies = [ "webcolors", "docstring-parser" ] -version = "2.7.0rc1" +version = "2.7.0" [tool.setuptools.packages.find] where = ["src"] diff --git a/src/log21/Argumentify.py b/src/log21/Argumentify.py index 1d25bf3..a16d7e2 100644 --- a/src/log21/Argumentify.py +++ b/src/log21/Argumentify.py @@ -3,12 +3,12 @@ import re as _re import string as _string +import asyncio as _asyncio import inspect as _inspect -from typing import ( - Any as _Any, Set as _Set, Dict as _Dict, List as _List, Tuple as _Tuple, Union as - _Union, Callable as _Callable, Optional as _Optional, Coroutine as _Coroutine, - OrderedDict as _OrderedDict -) +from typing import (Any as _Any, Set as _Set, Dict as _Dict, List as _List, + Tuple as _Tuple, Union as _Union, Callable as _Callable, + Optional as _Optional, Awaitable as _Awaitable, + Coroutine as _Coroutine, OrderedDict as _OrderedDict) from dataclasses import field as _field, dataclass as _dataclass from docstring_parser import Docstring as _Docstring, parse as _parse @@ -151,7 +151,7 @@ class FunctionInfo: """Represents a function.""" function: Callable name: str = _field(init=False) - arguments: _Dict[str, Argument] = _field(init=False) + arguments: _OrderedDict[str, Argument] = _field(init=False) docstring: _Docstring = _field(init=False) parser: _Argparse.ColorizingArgumentParser = _field(init=False) @@ -313,7 +313,10 @@ def _argumentify_one(func: Callable): args.extend(getattr(cli_args, argument.name) or []) else: kwargs[argument.name] = getattr(cli_args, argument.name) - func(*args, **kwargs) + result = func(*args, **kwargs) + # Check if the result is a coroutine + if isinstance(result, (_Coroutine, _Awaitable)): + _asyncio.run(result) def _argumentify(functions: _Dict[str, Callable]): @@ -359,7 +362,10 @@ def _argumentify(functions: _Dict[str, Callable]): args.extend(getattr(cli_args, argument.name) or []) else: kwargs[argument.name] = getattr(cli_args, argument.name) - function(*args, **kwargs) + result = function(*args, **kwargs) + # Check if the result is a coroutine + if isinstance(result, (_Coroutine, _Awaitable)): + _asyncio.run(result) def argumentify(entry_point: _Union[Callable, _List[Callable], _Dict[str, Callable]]): diff --git a/src/log21/__init__.py b/src/log21/__init__.py index d3828c9..d42d0a9 100644 --- a/src/log21/__init__.py +++ b/src/log21/__init__.py @@ -24,7 +24,7 @@ from log21.LoggingWindow import LoggingWindow, LoggingWindowHandler from log21.StreamHandler import StreamHandler, ColorizingStreamHandler -__version__ = "2.7.0rc1" +__version__ = "2.7.0" __author__ = "CodeWriter21 (Mehrad Pooryoussof)" __github__ = "Https://GitHub.com/MPCodeWriter21/log21" __all__ = [