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

Replace click with tyro #141

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,8 @@ See also git tags: https://github.com/jedie/manageprojects/tags

[comment]: <> (✂✂✂ auto generated history start ✂✂✂)

* [**dev**](https://github.com/jedie/manageprojects/compare/v0.20.0...main)
* 2024-11-21 - Switch from click to tyro
* [v0.20.0](https://github.com/jedie/manageprojects/compare/v0.19.2...v0.20.0)
* 2024-11-11 - Bugfix publish: Add "build" dep.
* 2024-11-11 - Bugfix publish command: Add missing "setuptools" dep.
Expand All @@ -359,12 +361,12 @@ See also git tags: https://github.com/jedie/manageprojects/tags
* 2024-09-24 - Update requirements
* [v0.19.1](https://github.com/jedie/manageprojects/compare/v0.19.0...v0.19.1)
* 2024-09-15 - Bugfix and enhance "setup_python.py"
* [v0.19.0](https://github.com/jedie/manageprojects/compare/v0.18.0...v0.19.0)
* 2024-09-15 - NEW: setup_python.py
* 2024-09-15 - Update requirements

<details><summary>Expand older history entries ...</summary>

* [v0.19.0](https://github.com/jedie/manageprojects/compare/v0.18.0...v0.19.0)
* 2024-09-15 - NEW: setup_python.py
* 2024-09-15 - Update requirements
* [v0.18.0](https://github.com/jedie/manageprojects/compare/v0.17.1...v0.18.0)
* 2024-08-29 - Fix wrong "module" in publish call :(
* 2024-08-29 - Fix wrong "distribution_name" in publish command
Expand Down
44 changes: 15 additions & 29 deletions manageprojects/cli_app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,26 @@
import logging
import sys

import rich_click as click
from cli_base.autodiscover import import_all_files
from cli_base.cli_tools.rich_utils import rich_traceback_install
from cli_base.cli_tools.version_info import print_version
from rich import print # noqa
from rich.console import Console
from rich.traceback import install as rich_traceback_install
from rich_click import RichGroup
from tyro.extras import SubcommandApp

import manageprojects
from manageprojects import constants


logger = logging.getLogger(__name__)

app = SubcommandApp()

class ClickGroup(RichGroup): # FIXME: How to set the "info_name" easier?
def make_context(self, info_name, *args, **kwargs):
info_name = './cli.py'
return super().make_context(info_name, *args, **kwargs)


@click.group(
cls=ClickGroup,
epilog=constants.CLI_EPILOG,
)
def cli():
pass


# Register all click commands, just by import all files in this package:
# Register all CLI commands, just by import all files in this package:
import_all_files(package=__package__, init_file=__file__)


@cli.command()
@app.command
def version():
"""Print version and exit"""
# Pseudo command, because the version always printed on every CLI call ;)
Expand All @@ -48,14 +34,14 @@ def version():
def main():
print_version(manageprojects)

console = Console()
rich_traceback_install(
width=console.size.width, # full terminal width
show_locals=True,
suppress=[click],
max_frames=2,
)
rich_traceback_install()

# Work-a-round for: https://github.com/brentyi/tyro/issues/205
app._subcommands = {k.replace('_', '-'): v for k, v in app._subcommands.items()}

# Execute Click CLI:
cli.name = './cli.py'
cli()
app.cli(
prog='./cli.py',
description=constants.CLI_EPILOG,
use_underscores=False, # use hyphens instead of underscores
sort_subcommands=True,
)
Loading
Loading