From de89e79390bfd883fc36b0a3db99c3fd70f48455 Mon Sep 17 00:00:00 2001 From: Grant Ramsay Date: Wed, 13 Nov 2024 11:15:43 +0000 Subject: [PATCH] remove Annotated from typer config as chokes in python 3.9 Signed-off-by: Grant Ramsay --- lice2/core.py | 218 +++++++++++++++++++++++--------------------------- 1 file changed, 98 insertions(+), 120 deletions(-) diff --git a/lice2/core.py b/lice2/core.py index 9485745..6e9ba3e 100644 --- a/lice2/core.py +++ b/lice2/core.py @@ -5,15 +5,15 @@ import sys from pathlib import Path from types import SimpleNamespace -from typing import Annotated, Any, Callable, Optional +from typing import Any, Callable, Optional import typer from rich import print as rprint -from rich.markup import escape # noqa: TCH002 +from rich.markup import escape from lice2 import __version__ from lice2.config import check_default_license, settings -from lice2.constants import LANGS, LICENSES # noqa: TCH001 +from lice2.constants import LANGS, LICENSES from lice2.helpers import ( copy_to_clipboard, format_license, @@ -45,126 +45,104 @@ context_settings={"help_option_names": ["-h", "--help"]}, ) def main( # noqa: PLR0913 - license_name: Annotated[ - str, - typer.Argument( - help=f"The license to generate, one of: {', '.join(LICENSES)}", - callback=validate_license, - metavar="[license]", - ), - ] = check_default_license(), - header: Annotated[ - bool, - typer.Option( - "--header", help="Generate source file header for specified license" - ), - ] = False, - organization: Annotated[ - str, - typer.Option( - "--org", - "-o", - help='Organization, defaults to .gitconfig or os.environ["USER"]', - ), - ] = guess_organization(), - project: Annotated[ - str, - typer.Option( - "--proj", - "-p", - help="Name of project, defaults to name of current directory", - ), - ] = Path.cwd().name, - template_path: Annotated[ - Optional[str], - typer.Option( - "--template", - "-t", - help="Path to license template file", - ), - ] = None, - year: Annotated[ - Optional[str], - typer.Option( - "--year", "-y", help="Copyright year", callback=validate_year - ), - ] = get_local_year(), - language: Annotated[ - Optional[str], - typer.Option( - "--language", - "-l", - help=( - "Format output for language source file, one of: " - f"{', '.join(LANGS.keys())} " - f"[dim]{escape('[default: txt]')}[/dim]" - ), - show_default=False, - ), - ] = None, - ofile: Annotated[ - Optional[str], - typer.Option( - "--file", - "-f", - help=( - "Name of the output source file (with -l, " - "extension can be omitted)" - ), - ), - ] = "stdout", - clipboard: Annotated[ - bool, - typer.Option( - "--clipboard", - "-c", - help="Copy the generated license to the clipboard", - ), - ] = False, - show_vars: Annotated[ - Optional[bool], - typer.Option( - "--vars", - help="List template variables for specified license", - ), - ] = None, - show_licenses: Annotated[ - bool, - typer.Option( - "--licenses", - help="List available license templates and their parameters", - ), - ] = False, - show_languages: Annotated[ - bool, - typer.Option( - "--languages", - help="List available source code formatting languages", - ), - ] = False, - legacy: Annotated[ - bool, - typer.Option( - "--legacy", - help="Use legacy method to generate license", + license_name: str = typer.Argument( + default=check_default_license(), + help=f"The license to generate, one of: {', '.join(LICENSES)}", + callback=validate_license, + metavar="[license]", + ), + organization: str = typer.Option( + guess_organization(), + "--org", + "-o", + help='Organization, defaults to .gitconfig or os.environ["USER"]', + ), + project: str = typer.Option( + Path.cwd().name, + "--proj", + "-p", + help="Name of project, defaults to name of current directory", + ), + template_path: Optional[str] = typer.Option( + None, + "--template", + "-t", + help="Path to license template file", + ), + year: Optional[str] = typer.Option( + get_local_year(), + "--year", + "-y", + help="Copyright year", + callback=validate_year, + ), + language: Optional[str] = typer.Option( + None, + "--language", + "-l", + help=( + "Format output for language source file, one of: " + f"{', '.join(LANGS.keys())} " + f"[dim]{escape('[default: txt]')}[/dim]" ), - ] = False, - version: Annotated[ - bool, - typer.Option( - "--version", "-v", is_eager=True, help="Show version info" + show_default=False, + ), + ofile: Optional[str] = typer.Option( + "stdout", + "--file", + "-f", + help=( + "Name of the output source file (with -l, " + "extension can be omitted)" ), - ] = False, - metadata: Annotated[ - bool, - typer.Option( - "--metadata", - help=( - "Output a JSON string listing all available licenses and " - "languages This allows easy integration into other tools." - ), + ), + *, + header: bool = typer.Option( + False, + "--header", + help="Generate source file header for specified license", + ), + clipboard: bool = typer.Option( + False, + "--clipboard", + "-c", + help="Copy the generated license to the clipboard", + ), + show_vars: Optional[bool] = typer.Option( + None, + "--vars", + help="List template variables for specified license", + ), + show_licenses: bool = typer.Option( + False, + "--licenses", + help="List available license templates and their parameters", + ), + show_languages: bool = typer.Option( + False, + "--languages", + help="List available source code formatting languages", + ), + legacy: bool = typer.Option( + False, + "--legacy", + help="Use legacy method to generate license", + ), + version: bool = typer.Option( + False, + "--version", + "-v", + is_eager=True, + help="Show version info", + ), + metadata: bool = typer.Option( + False, + "--metadata", + help=( + "Output a JSON string listing all available licenses and " + "languages This allows easy integration into other tools." ), - ] = False, + ), ) -> None: """Generate a license file.