from typing import Set
from typing import List


def _parse_requirements_txt(input_: str) -> Set[str]:
    """Parses Python dependencies in the requirements.txt format.

    :param input_: The text in the requirements.txt
    :return: A list of dependencies in PEP440 format
    """
    specifications: List[str] = []
    dependency = ""

    for line in input_.split("\n"):
        # Whitespace around definitions is never semantically significant
        line = line.strip()

        if line.startswith("#"):
            # Just a comment, ignore it
            continue
        elif len(line) == 0:
            continue

        dependency += line
        if line.endswith("\\"):
            # Line continuation! The dependency definition continues
            dependency += line[:-1]
        else:
            # The dependency definition is complete. Remove any environment
            # markers, leaving only the specification.
            spec = dependency.split(";")[0]
            specifications.append(spec)

    return set(specifications)