from pathlib import Path
from typing import Iterable
import click


def _requirements(
        path: Path,
        packages: Iterable[str],
        silent: bool = False
) -> Path:
    """
    Create a ``requirements.txt`` file.

    :param path: the output path
    :param packages: the packages
    :param silent: ``True`` to suppress normal output
    """
    # Figure out where we're going to write the files.
    _path = path.expanduser().resolve()
    # Write each package as a new line in the new requirements file.
    with open(str(_path), 'a') as fb:
        for package in packages:
            fb.write(f"{package}\n")
    # If we're not running silent...
    if not silent:
        # ...show 'em what we wrote.
        click.echo("requirements:")
        click.echo(_path.read_text())
    # Return the file path to the caller.
    return _path