Skip to content

Reference

ChewPy This module serves as the main entry point for the ChewPy CLI application.

It initializes secret configuration, sets up logging based on environment variables, and launches the command-line interface using Typer. Logging is handled via Loguru, and secrets are managed through utility functions.

Typical usage

python -m chewpy uv run python -m chewpy

Functions:

Name Description
main

Initializes configuration and runs the CLI app.

main()

Main entry point for the CLI.

Source code in src/chewpy/__init__.py
def main() -> None:
    """Main entry point for the CLI."""
    global ENV_DEBUG  # pylint: disable=global-statement
    configure_secrets()
    try:
        ENV_DEBUG = get_secret("DEBUG", default=False, is_bool=True)
    except KeyError as e:
        logger.warning(e)
        ENV_DEBUG = False
    configure_logging(debug=ENV_DEBUG)

    logger.info("main from ChewPy!")
    app()

Translator

CLI Commands for Translator

Features:

  • Subtitle merging

subtitles_merge(source_01_path, source_02_path)

Merges two subtitle files.

Parameters:

Name Type Description Default
source_01_path Path

The path to the first subtitle file.

required
source_02_path Path

The path to the second subtitle file.

required
Source code in src/chewpy/translator/commands.py
@app.command()
def subtitles_merge(source_01_path: Path, source_02_path: Path) -> None:
    """Merges two subtitle files.

    Args:
        source_01_path (Path): The path to the first subtitle file.
        source_02_path (Path): The path to the second subtitle file.
    """
    output_path: Path = (
        source_01_path.parent
        / f"{source_01_path.stem}_merged_{source_02_path.stem}{source_02_path.suffix}"
    )
    logger.debug(f"Output Path: {output_path}")
    with (
        open(source_01_path, "r", encoding="utf-8") as file1,
        open(source_02_path, "r", encoding="utf-8") as file2,
        tempfile.NamedTemporaryFile(mode="w", encoding="utf-8") as tmp_file,
    ):
        logger.debug(f"Temporary file created: {tmp_file.name}")
        try:
            merge(file1, file2, tmp_file)
            tmp_file.flush()
            shutil.move(tmp_file.name, output_path)
        except ValueError as e:
            logger.error(f"Error merging subtitles: {e}")