Skip to content

Commit 65cc612

Browse files
fix: Change the behavior of argumentify handling function descriptions.
It will now use the whole function description instead of the short one-line version.
1 parent e068033 commit 65cc612

5 files changed

Lines changed: 98 additions & 78 deletions

File tree

CHANGELOG.md

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

9+
### v3.0.2
10+
11+
Change `argumentify` to use the whole function description as the argument-parser
12+
description instead of the one-line short description.
13+
14+
- Example:
15+
16+
```python
17+
def main(verbose: bool = False) -> None:
18+
"""This is a very useful tool and I will describe it thoroughly. It is so good that
19+
we have a second line in the first part of the description.
20+
21+
And now we can talk more about the tool...
22+
23+
:param verbose: This flag will make the logs more verbose!
24+
"""
25+
26+
argumentify(main)
27+
```
28+
29+
The way old versions would look:
30+
31+
```help
32+
usage: test.py [-h] [--verbose]
33+
34+
This is a very useful tool and I will describe it thoroughly. It is so good that
35+
36+
options:
37+
-h, --help
38+
show this help message and exit
39+
--verbose, -v
40+
This flag will make the logs more verbose!
41+
42+
```
43+
44+
Now at v3.0.2:
45+
46+
```help
47+
usage: test.py [-h] [--verbose]
48+
49+
This is a very useful tool and I will describe it thoroughly. It is so good that we have a
50+
second line in the first part of the description. And now we can talk more about the tool...
51+
52+
options:
53+
-h, --help
54+
show this help message and exit
55+
--verbose, -v
56+
This flag will make the logs more verbose!
57+
58+
```
59+
960
### v3.0.1
1061

1162
Fix the issue with `argumentify` which would result in falsy default values to be
@@ -20,8 +71,8 @@ def main(offset: int = 0) -> None:
2071
argumentify(main)
2172
```
2273

23-
if no value is provided for `--offset`, the default will be `None` instead of `0` which
24-
is unexpected and can lead to issues.
74+
if no value was provided for `--offset`, the default would be `None` instead of `0`
75+
which was unexpected and can lead to issues.
2576

2677
### v3.0.0
2778

README.md

Lines changed: 41 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -69,85 +69,56 @@ pip install git+https://github.com/MPCodeWriter21/log21
6969
Changelog
7070
---------
7171

72-
### v3.0.1
72+
### v3.0.2
7373

74-
Fix the issue with `argumentify` which would result in falsy default values to be
75-
replaced with None.
74+
Change `argumentify` to use the whole function description as the argument-parser
75+
description instead of the one-line short description.
7676

7777
+ Example:
7878

7979
```python
80-
def main(offset: int = 0) -> None:
81-
...
80+
def main(verbose: bool = False) -> None:
81+
"""This is a very useful tool and I will describe it thoroughly. It is so good that
82+
we have a second line in the first part of the description.
83+
84+
And now we can talk more about the tool...
85+
86+
:param verbose: This flag will make the logs more verbose!
87+
"""
8288

8389
argumentify(main)
8490
```
8591

86-
if no value is provided for `--offset`, the default will be `None` instead of `0` which
87-
is unexpected and can lead to issues.
88-
89-
#### Breaking Changes
90-
91-
+ **Internal module renaming and normalization**
92-
+ All internal modules were renamed to lowercase and, in some cases, split or
93-
reorganized.
94-
+ Imports such as `log21.Colors`, `log21.Logger`, `log21.ProgressBar`, etc. are no
95-
longer valid.
96-
+ Users importing from internal modules must update their imports to the new module
97-
names.
98-
+ Public imports from `log21` remain supported.
99-
100-
+ **Argumentify exception renames**
101-
+ Several exceptions were renamed to follow a consistent `*Error` naming convention:
102-
+ `TooFewArguments``TooFewArgumentsError`
103-
+ `RequiredArgument``RequiredArgumentError`
104-
+ `IncompatibleArguments``IncompatibleArgumentsError`
105-
+ Code that explicitly raises or catches these exceptions must be updated.
106-
107-
#### Changes
108-
109-
+ **Crash reporter behavior improvement**
110-
+ Prevented the default file crash reporter from creating `.crash_report` files when it
111-
is not actually used.
112-
+ Implemented using an internal `FakeModule` helper.
113-
114-
+ **Argparse compatibility update**
115-
+ Bundled and used the Python 3.13 `argparse` implementation to ensure consistent
116-
behavior across supported Python versions.
117-
118-
+ **Progress bar module rename**
119-
+ Renamed the internal progress bar module to `progress_bar` for consistency with the
120-
new naming scheme.
121-
+ This will not break the usages of `log21.progress_bar(...)` since the call
122-
functionality was added to the module using the `FakeModule` helper.
123-
124-
+ **Examples added and updated**
125-
+ Added new example code files.
126-
+ Updated existing examples to match the v3 API and conventions.
127-
128-
#### Fixes
129-
130-
+ Resolved various linting and static-analysis issues across the codebase.
131-
+ Addressed minor compatibility issues uncovered by running linters and pre-commit hooks.
132-
+ Resolved errors occurring in environments with newer versions of argparse.
133-
134-
#### Internal and Maintenance Changes
135-
136-
+ Migrated the build system configuration to `uv`.
137-
+ Updated Python version classifiers and set the supported Python version to 3.9+.
138-
+ Added `vermin` to the pre-commit configuration.
139-
+ Updated `.gitignore`, license metadata, and tool configurations.
140-
+ Silenced and resolved a large number of linter warnings.
141-
+ General internal refactoring with no intended user-visible behavioral changes.
142-
143-
#### Notes
144-
145-
+ There are **no intentional behavioral changes** in logging output, argument parsing
146-
logic, or UI components.
147-
+ Most projects will require **minimal or no changes** unless they depend on internal
148-
modules or renamed exceptions.
149-
+ See [MIGRATION-V2-V3.md](https://github.com/MPCodeWriter21/log21/blob/master/MIGRATION-V2-V3.md)
150-
for detailed upgrade instructions.
92+
The way old versions would look:
93+
94+
```help
95+
usage: test.py [-h] [--verbose]
96+
97+
This is a very useful tool and I will describe it thoroughly. It is so good that
98+
99+
options:
100+
-h, --help
101+
show this help message and exit
102+
--verbose, -v
103+
This flag will make the logs more verbose!
104+
105+
```
106+
107+
Now at v3.0.2:
108+
109+
```help
110+
usage: test.py [-h] [--verbose]
111+
112+
This is a very useful tool and I will describe it thoroughly. It is so good that we have a
113+
second line in the first part of the description. And now we can talk more about the tool...
114+
115+
options:
116+
-h, --help
117+
show this help message and exit
118+
--verbose, -v
119+
This flag will make the logs more verbose!
120+
121+
```
151122

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

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ dependencies = [
2323
"webcolors",
2424
"docstring-parser"
2525
]
26-
version = "3.0.1"
26+
version = "3.0.2"
2727

2828
[build-system]
2929
requires = ["uv_build>=0.8.15,<0.9.0"]

src/log21/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
# yapf: enable
3232

3333
__author__ = 'CodeWriter21 (Mehrad Pooryoussof)'
34-
__version__ = '3.0.1'
34+
__version__ = '3.0.2'
3535
__github__ = 'https://GitHub.com/MPCodeWriter21/log21'
3636
__all__ = [
3737
'ColorizingStreamHandler', 'DecolorizingFileHandler', 'ColorizingFormatter',

src/log21/argumentify.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -384,9 +384,7 @@ def _argumentify_one(func: Callable) -> None:
384384
)
385385

386386
# Create the parser
387-
parser = _argparse.ColorizingArgumentParser(
388-
description=info.docstring.short_description
389-
)
387+
parser = _argparse.ColorizingArgumentParser(description=info.docstring.description)
390388
# Add the arguments
391389
_add_arguments(parser, info)
392390
cli_args = parser.parse_args()
@@ -432,7 +430,7 @@ def _argumentify(functions: _Dict[str, Callable]) -> None:
432430
parser = _argparse.ColorizingArgumentParser()
433431
subparsers = parser.add_subparsers(required=True)
434432
for name, (_, info) in functions_info.items():
435-
subparser = subparsers.add_parser(name, help=info.docstring.short_description)
433+
subparser = subparsers.add_parser(name, help=info.docstring.description)
436434
_add_arguments(subparser, info)
437435
subparser.set_defaults(func=info.function)
438436
cli_args = parser.parse_args()

0 commit comments

Comments
 (0)