Skip to content

Commit

Permalink
Merge pull request #11 from jwodder/more-async
Browse files Browse the repository at this point in the history
Test against & document support for asyncclick
  • Loading branch information
jwodder authored Feb 11, 2025
2 parents 0b015e3 + 523b8b2 commit 5b5c9ab
Show file tree
Hide file tree
Showing 12 changed files with 367 additions and 57 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
v0.6.0 (in development)
-----------------------
- Add support for asyncclick (contributed by
[@kquinsland](https://github.com/kquinsland))

v0.5.1 (2024-12-01)
-------------------
- Migrated from setuptools to hatch
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2021-2024 John Thorvald Wodder II
Copyright (c) 2021-2025 John Thorvald Wodder II and contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
13 changes: 7 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,18 @@
| `Issues <https://github.com/jwodder/click-loglevel/issues>`_
| `Changelog <https://github.com/jwodder/click-loglevel/blob/master/CHANGELOG.md>`_
``click-loglevel`` provides a ``LogLevel`` parameter type for use in Click_
programs that wish to let the user set the logging level. It accepts all of
the ``logging`` log level names (``CRITICAL``, ``ERROR``, ``WARNING``,
``INFO``, ``DEBUG``, and ``NOTSET``, all case insensitive), and converts them
into their corresponding numeric values. It also accepts integer values and
leaves them as-is. Custom log levels are also supported.
``click-loglevel`` provides a ``LogLevel`` parameter type for use in Click_ and
asyncclick_ programs that wish to let the user set the logging level. It
accepts all of the ``logging`` log level names (``CRITICAL``, ``ERROR``,
``WARNING``, ``INFO``, ``DEBUG``, and ``NOTSET``, all case insensitive), and
converts them into their corresponding numeric values. It also accepts integer
values and leaves them as-is. Custom log levels are also supported.

Starting in version 0.4.0, shell completion of log level names (both built-in
and custom) is also supported.

.. _Click: https://palletsprojects.com/p/click/
.. _asyncclick: https://github.com/python-trio/asyncclick


Installation
Expand Down
2 changes: 1 addition & 1 deletion src/click_loglevel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import click
from click.shell_completion import CompletionItem

__version__ = "0.5.1"
__version__ = "0.6.0.dev1"
__author__ = "John Thorvald Wodder II"
__author_email__ = "click-loglevel@varonathe.org"
__license__ = "MIT"
Expand Down
17 changes: 17 additions & 0 deletions test/data/dict-extra-async.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import logging
import asyncclick as click
from click_loglevel import LogLevel


@click.command()
@click.option(
"-l",
"--log-level",
type=LogLevel(extra={"VERBOSE": 15, "NOTICE": 25}),
)
async def main(log_level: int) -> None:
click.echo(repr(log_level))


if __name__ == "__main__":
main()
17 changes: 17 additions & 0 deletions test/data/dict-extra-nonupper-async.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import logging
import asyncclick as click
from click_loglevel import LogLevel


@click.command()
@click.option(
"-l",
"--log-level",
type=LogLevel(extra={"Verbose": 15, "Notice": 25}),
)
async def main(log_level: int) -> None:
click.echo(repr(log_level))


if __name__ == "__main__":
main()
16 changes: 16 additions & 0 deletions test/data/list-extra-async.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import logging
import asyncclick as click
from click_loglevel import LogLevel

logging.addLevelName(15, "VERBOSE")
logging.addLevelName(25, "NOTICE")


@click.command()
@click.option("-l", "--log-level", type=LogLevel(extra=["VERBOSE", "NOTICE"]))
async def main(log_level: int) -> None:
click.echo(repr(log_level))


if __name__ == "__main__":
main()
16 changes: 16 additions & 0 deletions test/data/list-extra-nonupper-async.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import logging
import asyncclick as click
from click_loglevel import LogLevel

logging.addLevelName(15, "Verbose")
logging.addLevelName(25, "Notice")


@click.command()
@click.option("-l", "--log-level", type=LogLevel(extra=["Verbose", "Notice"]))
async def main(log_level: int) -> None:
click.echo(repr(log_level))


if __name__ == "__main__":
main()
52 changes: 52 additions & 0 deletions test/test_completions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from __future__ import annotations
import pytest
from click_loglevel import LogLevel


@pytest.mark.parametrize(
"incomplete,completions",
[
("IN", ["INFO"]),
("in", ["INFO"]),
("In", ["INFO"]),
("info", ["INFO"]),
("i", ["INFO"]),
("w", ["WARNING"]),
("n", ["NOTSET"]),
("D", ["DEBUG"]),
("E", ["ERROR"]),
("c", ["CRITICAL"]),
("Q", []),
("v", []),
("INFOS", []),
],
)
def test_get_completions(incomplete: str, completions: list[str]) -> None:
ll = LogLevel()
assert list(ll.get_completions(incomplete)) == completions


@pytest.mark.parametrize(
"incomplete,completions",
[
("IN", ["INFO"]),
("in", ["INFO"]),
("In", ["INFO"]),
("info", ["INFO"]),
("i", ["INFO"]),
("w", ["WARNING"]),
("n", ["NOTSET", "NOTICE"]),
("NOT", ["NOTSET", "NOTICE"]),
("NOTS", ["NOTSET"]),
("NOTI", ["NOTICE"]),
("D", ["DEBUG"]),
("E", ["ERROR"]),
("c", ["CRITICAL"]),
("Q", []),
("v", ["VERBOSE"]),
("INFOS", []),
],
)
def test_get_completions_extra(incomplete: str, completions: list[str]) -> None:
ll = LogLevel(extra={"Verbose": 5, "Notice": 25})
assert list(ll.get_completions(incomplete)) == completions
Loading

0 comments on commit 5b5c9ab

Please # to comment.