Skip to content

Commit

Permalink
v2.7.0
Browse files Browse the repository at this point in the history
+ 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.
  • Loading branch information
MPCodeWriter21 committed Sep 23, 2023
1 parent 8fb9a3b commit 8c3e7e2
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 13 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ dependencies = [
"webcolors",
"docstring-parser"
]
version = "2.7.0rc1"
version = "2.7.0"

[tool.setuptools.packages.find]
where = ["src"]
Expand Down
22 changes: 14 additions & 8 deletions src/log21/Argumentify.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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]):
Expand Down Expand Up @@ -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]]):
Expand Down
2 changes: 1 addition & 1 deletion src/log21/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__ = [
Expand Down

0 comments on commit 8c3e7e2

Please sign in to comment.