def METHOD_NAME(
    directory: Path,
    *,
    output: Optional[str],
    compression: Optional[str] = None,
    name: Optional[str] = None,
    version: Optional[str] = None,
    target_arch: Optional[str] = None,
) -> str:
    """Pack snap contents with `snap pack`.
    `output` may either be a directory, a file path, or just a file name.
      - directory: write snap to directory with default snap name
      - file path: write snap to specified directory with specified snap name
      - file name: write snap to cwd with specified snap name
    If name, version, and target architecture are not specified, then snap
    will use its default naming convention.
    :param directory: Directory to pack.
    :param output: Snap file name or directory.
    :param compression: Compression type to use, None for defaults.
    :param name: Name of snap project.
    :param version: Version of snap project.
    :param target_arch: Target architecture the snap project is built to.
    """
    emit.debug(f"pack_snap: output={output!r}, compression={compression!r}")
    # TODO remove workaround once LP: #1950465 is fixed
    _verify_snap(directory)
    # create command formatted as `snap pack <options> <snap-dir> <output-dir>`
    command: List[Union[str, Path]] = ["snap", "pack"]
    output_file = _get_filename(output, name, version, target_arch)
    if output_file is not None:
        command.extend(["--filename", output_file])
    if compression is not None:
        command.extend(["--compression", compression])
    command.append(directory)
    command.append(_get_directory(output))
    emit.progress("Creating snap package...")
    emit.debug(f"Pack command: {command}")
    try:
        proc = subprocess.run(
            command, capture_output=True, check=True, universal_newlines=True
        )
    except subprocess.CalledProcessError as err:
        msg = f"Cannot pack snap file: {err!s}"
        if err.stderr:
            msg += f" ({err.stderr.strip()!s})"
        raise errors.SnapcraftError(msg)
    snap_filename = Path(str(proc.stdout).partition(":")[2].strip()).name
    return snap_filename