Skip to content

Commit

Permalink
Add new line at end of yaml file
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorricks committed Mar 11, 2022
1 parent 1f534c8 commit b56f9ca
Show file tree
Hide file tree
Showing 14 changed files with 92 additions and 101 deletions.
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[flake8]
# Default ignores that we can extend
ignore=D100
ignore=D100,D102,D205,E203,E231,E731,W504,I001,W503
max-line-length=120
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,6 @@ dmypy.json

# Pyre type checker
.pyre/

# Ideas
.idea/
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ Please create a new [issue](https://github.com/ewels/rich-click/issues)
or better still, dive right in with a pull-request.

### Local setup

1. Create a new venv with a python3.6+ interpreter using `python3 -m venv venv`
2. Activate the venv with `source venv/bin/activate`
3. Install our the package as an editable including all dev dependencies with `pip3 install -e ."[dev]"`
Expand Down
10 changes: 5 additions & 5 deletions examples/01_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ def cli(debug):
)
@click.option("--all", is_flag=True, help="Sync all the things?")
def sync(type, all):
"""Synchronise all your files between two places"""
"""Synchronise all your files between two places."""
print("Syncing")


@cli.command(short_help="Optionally use short-help for the group help text")
@click.option("--all", is_flag=True, help="Get everything")
def download(all):
"""
Pretend to download some files from
somewhere. Multi-line help strings are unwrapped
until you use a double newline.
r"""
Pretend to download some files from somewhere.
Multi-line help strings are unwrapped until you use a double newline.
Only the first paragraph is used in group help texts.
Don't forget you can opt-in to rich and markdown formatting!
Expand Down
5 changes: 3 additions & 2 deletions examples/02_declarative.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import click
from rich_click import RichGroup, RichCommand

from rich_click import RichCommand, RichGroup


@click.group(cls=RichGroup)
Expand All @@ -19,7 +20,7 @@ def cli(debug):

@cli.command(cls=RichCommand)
def sync():
"""Synchronise all your files between two places"""
"""Synchronise all your files between two places."""
click.echo("Syncing")


Expand Down
8 changes: 4 additions & 4 deletions examples/03_groups_sorting.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,26 +71,26 @@ def cli(type, debug):
@click.option("--all", is_flag=True, help="Sync all the things?")
@click.option("--overwrite", is_flag=True, help="Overwrite local files")
def sync(input, output, all, overwrite):
"""Synchronise all your files between two places"""
"""Synchronise all your files between two places."""
print("Syncing")


@cli.command()
@click.option("--all", is_flag=True, help="Get everything")
def download(all):
"""Pretend to download some files from somewhere"""
"""Pretend to download some files from somewhere."""
print("Downloading")


@cli.command()
def auth():
"""Authenticate the app"""
"""Authenticate the app."""
print("Downloading")


@cli.command()
def config():
"""Set up the configuration"""
"""Set up the configuration."""
print("Downloading")


Expand Down
2 changes: 1 addition & 1 deletion examples/04_rich_markup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@click.option(
"--input",
type=click.Path(),
help="Input [magenta bold]file[/]. [dim]\[default: a custom default][/]",
help=r"Input [magenta bold]file[/]. [dim]\[default: a custom default][/]",
)
@click.option(
"--type",
Expand Down
4 changes: 1 addition & 3 deletions examples/07_custom_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

# Show custom error messages
click.rich_click.STYLE_ERRORS_SUGGESTION = "blue italic"
click.rich_click.ERRORS_SUGGESTION = (
"Try running the '--help' flag for more information."
)
click.rich_click.ERRORS_SUGGESTION = "Try running the '--help' flag for more information."
click.rich_click.ERRORS_EPILOGUE = "To find out more, visit https://mytool.com"


Expand Down
30 changes: 19 additions & 11 deletions src/rich_click/__init__.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,39 @@
"""
rich-click is a minimal Python module to combine the efforts
of the excellent packages 'rich' and 'click'.
rich-click is a minimal Python module to combine the efforts of the excellent packages 'rich' and 'click'.
The intention is to provide attractive help output from
click, formatted with rich, with minimal customisation required.
The intention is to provide attractive help output from click, formatted with rich, with minimal
customisation required.
"""

__version__ = "1.2.2.dev0"

from click import *
from click import group as click_group
from typing import TYPE_CHECKING

from click import * # noqa: F401, F403
from click import command as click_command
from rich_click.rich_group import RichGroup
from click import group as click_group

from rich_click.rich_command import RichCommand
from rich_click.rich_group import RichGroup

# MyPy does not like star imports. Therefore when we are type checking we import them here as well.
if TYPE_CHECKING:
from click import argument, Choice, option, Path, version_option # noqa: F401


def group(*args, cls=RichGroup, **kwargs):
"""group decorator function.
"""
Group decorator function.
Defines the group() function so that it uses the RichGroup class by default
Defines the group() function so that it uses the RichGroup class by default.
"""
return click_group(*args, cls=cls, **kwargs)


def command(*args, cls=RichCommand, **kwargs):
"""command decorator function.
"""
Command decorator function.
Defines the command() function so that it uses the RichCommand class by default
Defines the command() function so that it uses the RichCommand class by default.
"""
return click_command(*args, cls=cls, **kwargs)
4 changes: 1 addition & 3 deletions src/rich_click/__main__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
"""
Entry-point module for the command line prefixer,
called in case you use `python -m rich_click`.
Entry-point module for the command line prefixer, called in case you use `python -m rich_click`.
Why does this file exist, and why `__main__`? For more info, read:
- https://www.python.org/dev/peps/pep-0338/
- https://docs.python.org/3/using/cmdline.html#cmdoption-m
"""
Expand Down
32 changes: 16 additions & 16 deletions src/rich_click/cli.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""The command line interface."""

import sys
from textwrap import dedent
from importlib import import_module
from typing import Optional, List, Any
from textwrap import dedent
from typing import Any, List, Optional

try:
from importlib.metadata import entry_points
Expand All @@ -16,15 +16,17 @@
from rich.padding import Padding
from rich.panel import Panel
from rich.text import Text
from rich_click import group as rich_group, command as rich_command

from rich_click import command as rich_command
from rich_click import group as rich_group
from rich_click.rich_click import (
STYLE_HELPTEXT_FIRST_LINE,
ALIGN_ERRORS_PANEL,
ERRORS_PANEL_TITLE,
STYLE_ERRORS_PANEL_BORDER,
STYLE_HELPTEXT,
STYLE_USAGE_COMMAND,
STYLE_HELPTEXT_FIRST_LINE,
STYLE_USAGE,
STYLE_ERRORS_PANEL_BORDER,
ERRORS_PANEL_TITLE,
ALIGN_ERRORS_PANEL,
STYLE_USAGE_COMMAND,
)

console = Console()
Expand All @@ -33,17 +35,15 @@
def _print_usage() -> None:
console.print(
Padding(
Text.from_markup(
f"[{STYLE_USAGE}]Usage[/]: rich-click [SCRIPT | MODULE:FUNCTION] [-- SCRIPT_ARGS...]"
),
Text.from_markup(f"[{STYLE_USAGE}]Usage[/]: rich-click [SCRIPT | MODULE:FUNCTION] [-- SCRIPT_ARGS...]"),
1,
),
style=STYLE_USAGE_COMMAND,
)


def _print_help() -> None:
help_paragraphs = dedent(main.__doc__).split("\n\n")
help_paragraphs = dedent(main.__doc__ or "").split("\n\n")
help_paragraphs = [x.replace("\n", " ").strip() for x in help_paragraphs]
console.print(
Padding(
Expand All @@ -63,9 +63,9 @@ def _print_help() -> None:

def main(args: Optional[List[str]] = None) -> Any:
"""
The [link=https://github.com/ewels/rich-click]rich-click[/] CLI
provides attractive help output from any tool using [link=https://click.palletsprojects.com/]click[/],
formatted with [link=https://github.com/Textualize/rich]rich[/].
The [link=https://github.com/ewels/rich-click]rich-click[/] CLI provides attractive help output from any
tool using [link=https://click.palletsprojects.com/]click[/], formatted with
[link=https://github.com/Textualize/rich]rich[/].
The rich-click command line tool can be prepended before any Python package
using native click to provide attractive richified click help output.
Expand All @@ -79,7 +79,7 @@ def main(args: Optional[List[str]] = None) -> Any:
or [cyan]command()[/] classes.
If in doubt, please suggest to the authors that they use rich_click within their
tool natively - this will always give a better experience.
"""
""" # noqa: D400, D401
args = args or sys.argv[1:]
if not args or args == ["--help"]:
# Print usage if we got no args, or only --help
Expand Down
Loading

0 comments on commit b56f9ca

Please sign in to comment.