Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release: v0.2.0 #124

Merged
merged 3 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All notable changes to this project will be documented in this file.

## [v0.2.0](https://github.com/eonu/feud/releases/tag/v0.2.0) - 2023-12-27

### Features

- add `feud.build` + move `rich_click` styling to `feud.Config` ([#123](https://github.com/eonu/feud/issues/123))

## [v0.1.6](https://github.com/eonu/feud/releases/tag/v0.1.6) - 2023-12-26

### Bug Fixes
Expand Down
8 changes: 0 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -821,14 +821,6 @@ Without Rich-formatted output
</tr>
</table>

> [!TIP]
>
> [Settings for `rich-click`](https://github.com/ewels/rich-click/blob/main/src/rich_click/rich_click.py) can be provided to `feud.run`, e.g.:
>
> ```python
> feud.run(command, rich_settings={"SHOW_ARGUMENTS": False})
> ```

## Build status

| `master` | `dev` |
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
project = "feud"
copyright = "2023-2025, Feud Developers" # noqa: A001
author = "Edwin Onuonga (eonu)"
release = "0.1.6"
release = "0.2.0"

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
Expand Down
2 changes: 1 addition & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Feud

----

Designing a *good* CLI can spiral into chaos without the help of
Designing a *good* CLI can quickly spiral into chaos without the help of
an intuitive CLI builder.

**Feud builds on** `Click <https://click.palletsprojects.com/en/8.1.x/>`__ **for
Expand Down
1 change: 0 additions & 1 deletion docs/source/sections/core/group.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,4 @@ API reference
:members:
:exclude-members: from_dict, from_iter, from_module

.. autofunction:: feud.core.group.compile

11 changes: 8 additions & 3 deletions docs/source/sections/core/run.rst
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
Running commands/groups
=======================
Running and building CLIs
=========================

.. contents:: Table of Contents
:class: this-will-duplicate-information-and-it-is-still-useful-here
:local:
:backlinks: none
:depth: 3

- :py:func:`.run`: **Build and run** runnable objects as a :py:class:`click.Command` or :py:class:`click.Group`.
- :py:func:`.build`: **Build** runnable object(s) into a
:py:class:`click.Command`, :py:class:`click.Group` (or :py:class:`.Group`).

----

API reference
-------------

.. autofunction:: feud.core.run
.. automodule:: feud.core
:members: run, build
17 changes: 16 additions & 1 deletion feud/_internal/_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@

try:
import rich_click as click

RICH = True
except ImportError:
import click

RICH = False

from feud._internal import _decorators, _inflect, _types
from feud.config import Config

Expand Down Expand Up @@ -56,7 +60,10 @@ class CommandState:
options: dict[str, ParameterSpec] = dataclasses.field(default_factory=dict)
description: str | None = None

def decorate(self: CommandState, func: t.Callable) -> click.Command:
def decorate( # noqa: PLR0915
self: CommandState,
func: t.Callable,
) -> click.Command:
meta_vars: dict[str, str] = {}
sensitive_vars: dict[str, bool] = {}
positional: list[str] = []
Expand Down Expand Up @@ -146,6 +153,14 @@ def decorate(self: CommandState, func: t.Callable) -> click.Command:
if self.pass_context:
command = click.pass_context(command)

if RICH:
# apply rich-click styling
command = click.rich_config(
help_config=click.RichHelpConfiguration(
**self.config.rich_click_kwargs
)
)(command)

constructor = click.group if self.is_group else click.command
command = constructor(**self.click_kwargs)(command)

Expand Down
5 changes: 1 addition & 4 deletions feud/_internal/_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
import pydantic as pyd
import pydantic_core as pydc

try:
import rich_click as click
except ImportError:
import click
from feud import click


def validate_call(
Expand Down
6 changes: 1 addition & 5 deletions feud/_internal/_metaclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,11 @@
import abc
import typing as t

from feud import click
from feud._internal import _command
from feud.config import Config
from feud.core.command import command

try:
import rich_click as click
except ImportError:
import click


class GroupBase(abc.ABCMeta):
def __new__(
Expand Down
16 changes: 16 additions & 0 deletions feud/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ class Config(pyd.BaseModel):
#: :py:func:`pydantic.validate_call_decorator.validate_call`.
pydantic_kwargs: dict[str, Any] = {}

#: Styling settings for ``rich-click``.
#:
#: See all available options
#: `here <https://github.com/ewels/rich-click/blob/e6a3add46c591d49079d440917700dfe28cf0cfe/src/rich_click/rich_help_configuration.py#L50>`__
#: (as of ``rich-click`` v1.7.2).
rich_click_kwargs: dict[str, Any] = {"show_arguments": True}

def __init__(self: Config, **kwargs: Any) -> Config:
caller: str = inspect.currentframe().f_back.f_code.co_name
if caller != Config._create.__name__:
Expand Down Expand Up @@ -73,6 +80,7 @@ def config(
show_help_datetime_formats: bool | None = None,
show_help_envvars: bool | None = None,
pydantic_kwargs: dict[str, Any] | None = None,
rich_click_kwargs: dict[str, Any] | None = None,
) -> Config:
"""Create a reusable configuration for :py:func:`.command` or
:py:class:`.Group` objects.
Expand All @@ -97,6 +105,13 @@ def config(
Validation settings for
:py:func:`pydantic.validate_call_decorator.validate_call`.

rich_click_kwargs:
Styling settings for ``rich-click``.

See all available options
`here <https://github.com/ewels/rich-click/blob/e6a3add46c591d49079d440917700dfe28cf0cfe/src/rich_click/rich_help_configuration.py#L50>`__
(as of ``rich-click`` v1.7.2).

Returns
-------
The reusable :py:class:`.Config`.
Expand Down Expand Up @@ -132,4 +147,5 @@ def config(
show_help_datetime_formats=show_help_datetime_formats,
show_help_envvars=show_help_envvars,
pydantic_kwargs=pydantic_kwargs,
rich_click_kwargs=rich_click_kwargs,
)
Loading