def get_package_versions(lines, ignore_external=False):
    """Return a dictionary of package versions."""
    versions = {}
    for line in lines:
        line = line.strip()
        if len(line) == 0 or line.startswith('#') or line.startswith('-r '):
            continue
        if line.startswith('https://'):
            continue
        if ignore_external and line.startswith('-e'):
            continue
        full_name, version_and_extras = line.split('==', 1)
        name = full_name.split('[', 1)[0].lower()
        version = version_and_extras.split(' ', 1)[0]
        versions[name] = version
    return versions
