Skip to content

Commit

Permalink
Get the documentation from the main function (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
kmagusiak authored Oct 13, 2022
1 parent a5738a1 commit dafc3b9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/lint-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ name: Lint and test
on:
push:
branches:
- "*"
tags-ignore: ["*"]
- "**"
tags-ignore: ["**"]

jobs:
lint:
Expand Down Expand Up @@ -45,3 +45,8 @@ jobs:
- name: Run mypy
run: |
mypy --install-types --non-interactive .
- name: Run examples
run: |
./example-simple.py
python example-inv.py -h
11 changes: 11 additions & 0 deletions alphaconf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,17 @@ def run(main: Callable, arguments=True, *, should_exit=True, app: Application =
for k in ['name', 'version', 'description', 'short_description']
if k in config
}
# if we don't have a description, get it from the function's docs
if 'description' not in properties and main.__doc__:
description = main.__doc__.strip().split('\n', maxsplit=1)
if 'short_description' not in properties:
properties['short_description'] = description[0]
if len(description) > 1:
import textwrap

properties['description'] = description[0] + '\n' + textwrap.dedent(description[1])
else:
properties['description'] = properties['short_description']
app = Application(**properties)
try:
app.setup_configuration(arguments, **config)
Expand Down
3 changes: 1 addition & 2 deletions example-simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@


def main():
"""Demo application"""
"""Simple demo of alphaconf"""
# you can log extra values with formatters such as json, try:
# ./example-simple.py logging.handlers.console.formatter=json
logging.info('The app is running...', extra={'other': 'othervalue'})
Expand All @@ -50,5 +50,4 @@ def main():
main,
name='example',
version='0.1',
description="Simple demo of alphaconf",
)

0 comments on commit dafc3b9

Please sign in to comment.