Repository: scikit-learn/scikit-learn
File: sklearn/tests/test_min_dependencies_readme.py (Python)

Code before:
    return (
        min_depencies_tag_to_packages_without_version,
        pyproject_section_to_min_dependencies_tag,
    )


def check_pyproject_sections(pyproject_toml, min_dependencies):
    packages, pyproject_tags = extract_packages_and_pyproject_tags(min_dependencies)

    for pyproject_section, min_dependencies_tag in pyproject_tags.items():
        # NumPy is more complex because build-time (>=1.25) and run-time (>=1.19.5)
        # requirement currently don't match
        skip_version_check_for = ["numpy"] if min_dependencies_tag == "build" else []

        expected_packages = packages[min_dependencies_tag]

        pyproject_section_keys = pyproject_section.split(".")
        info = pyproject_toml
        # iterate through nested keys to get packages and version
        for key in pyproject_section_keys:
            info = info[key]

        pyproject_build_min_versions = {}
        # Assuming pyproject.toml build section has something like "my-package>=2.3.0"
        # Warning: if you try to modify this regex, bear in mind that there can be upper
        # bounds in release branches so "my-package>=2.3.0,<2.5.0"
        pattern = r"([\w-]+)\s*[>=]=\s*([\d\w.]+)"
        for requirement in info:
            match = re.search(pattern, requirement)
            if match is None:
                raise NotImplementedError(
                    f"{requirement} does not match expected regex {pattern!r}. "
                    "Only >= and == are supported for version requirements"
                )

            package, version = match.group(1), match.group(2)

            pyproject_build_min_versions[package] = version

        msg = f"Packages in {pyproject_section} differ from _min_depencies.py"

        assert sorted(pyproject_build_min_versions) == sorted(expected_packages), msg

        for package, version in pyproject_build_min_versions.items():
            version = parse_version(version)
            expected_min_version = parse_version(min_dependencies[package][0])
            if package in skip_version_check_for:
                continue

            message = (
                f"{package} has inconsistent minimum versions in pyproject.toml and"

Review comment (bug):
I guess you can remove those 2 lines since there is a test checking this now? Basically I added this comment because there was not test before and to remind people of this edge case.
```suggestion
```

Code after:
        "build-system.requires": "build",
        "project.dependencies": "install",
    }
    for tag in min_depencies_tag_to_packages_without_version:
        section = f"project.optional-dependencies.{tag}"
        pyproject_section_to_min_dependencies_tag[section] = tag

    return (
        min_depencies_tag_to_packages_without_version,
        pyproject_section_to_min_dependencies_tag,
    )


def check_pyproject_sections(pyproject_toml, min_dependencies):
    packages, pyproject_tags = extract_packages_and_pyproject_tags(min_dependencies)

    for pyproject_section, min_dependencies_tag in pyproject_tags.items():
        # Special situation for numpy: we have numpy>=2 in
        # build-system.requires to make sure we build wheels against numpy>=2.
        # TODO remove this when our minimum supported numpy version is >=2.
        skip_version_check_for = (
            ["numpy"] if pyproject_section == "build-system.requires" else []
        )

        expected_packages = packages[min_dependencies_tag]

        pyproject_section_keys = pyproject_section.split(".")
        info = pyproject_toml
        # iterate through nested keys to get packages and version
        for key in pyproject_section_keys:
            info = info[key]

        pyproject_build_min_versions = {}
        # Assuming pyproject.toml build section has something like "my-package>=2.3.0"
        pattern = r"([\w-]+)\s*[>=]=\s*([\d\w.]+)"
        for requirement in info:
            match = re.search(pattern, requirement)
            if match is None:
                raise NotImplementedError(
                    f"{requirement} does not match expected regex {pattern!r}. "
                    "Only >= and == are supported for version requirements"
                )

            package, version = match.group(1), match.group(2)

            pyproject_build_min_versions[package] = version

        msg = f"Packages in {pyproject_section} differ from _min_depencies.py"

        assert sorted(pyproject_build_min_versions) == sorted(expected_packages), msg