# Path: meta_package_manager/labels.py
# MANAGER_LABELS = {}
# 
# MANAGER_PREFIX = "📦 manager: "
# 
# PLATFORM_LABELS = {}
# 
# PLATFORM_PREFIX = "🖥 platform: "
# 
# Path: meta_package_manager/pool.py
# ALL_MANAGER_IDS = tuple(sorted(pool()))
# 
# @cached(LRI(max_size=1))
# def pool():
#     """Search for package manager definitions locally and store them into an
#     internal register.
# 
#     Is considered valid package manager, definitions classes which:
#         1 - are located in the `managers` subfolder, and
#         2 - are sub-classes of PackageManager, and
#         3 - are not virtual (i.e. have a non null `cli_names` property).
#     """
#     register = {}
# 
#     for py_file in Path(__file__).parent.joinpath(MANAGER_SUBFOLDER).glob("*.py"):
#         logger.debug(f"Search manager definitions in {py_file}")
#         module = import_module(
#             f".{MANAGER_SUBFOLDER}.{py_file.stem}", package=__package__
#         )
# 
#         for _, klass in inspect.getmembers(module, inspect.isclass):
#             if issubclass(klass, PackageManager) and not klass.virtual:
#                 logger.debug(f"Found {klass!r}")
#                 manager = klass()
#                 register[manager.id] = manager
#             else:
#                 logger.debug(f"{klass!r} is not a valid manager definition")
# 
#     return register


import json
import re
import tomli
from collections import Counter
from pathlib import Path
from boltons.iterutils import flatten
from click_extra.platform import OS_DEFINITIONS, os_label
from click_extra.tests.conftest import unless_linux
from yaml import Loader, load
from ..labels import MANAGER_LABELS, MANAGER_PREFIX, PLATFORM_LABELS, PLATFORM_PREFIX
from ..pool import ALL_MANAGER_IDS, pool
    # Each platforms has at least a rule.
    assert min(rules_platforms.values()) >= 1

    # Check that all canonical labels are referenced in rules.
    assert canonical_labels.issuperset(rules_platforms)

    # Check each rule definition.
    for rule in rules:

        # No duplicate labels.
        assert len(set(rule["labels"])) == len(rule["labels"])

        # Special checks for rules targetting manager labels.
        manager_label = canonical_managers.intersection(rule["labels"])
        if manager_label:

            # Extract manager label
            assert len(manager_label) == 1
            manager_label = manager_label.pop()

            # Only platforms are expected alongside manager labels.
            platforms = set(rule["labels"]) - canonical_managers
            assert platforms.issubset(canonical_platforms)

            # Check managers sharing the same label shares the same platforms.
            supported_platforms = [
                pool()[mid].platforms
                for mid, lbl in MANAGER_LABELS.items()
                # Relying on pool() restrict our checks, as the pool exclude
                # non-locally supported managers.

# Path: meta_package_manager/labels.py
# MANAGER_LABELS = {}
# 
# MANAGER_PREFIX = "📦 manager: "
# 
# PLATFORM_LABELS = {}
# 
# PLATFORM_PREFIX = "🖥 platform: "
# 
# Path: meta_package_manager/pool.py
# ALL_MANAGER_IDS = tuple(sorted(pool()))
# 
# @cached(LRI(max_size=1))
# def pool():
#     """Search for package manager definitions locally and store them into an
#     internal register.
# 
#     Is considered valid package manager, definitions classes which:
#         1 - are located in the `managers` subfolder, and
#         2 - are sub-classes of PackageManager, and
#         3 - are not virtual (i.e. have a non null `cli_names` property).
#     """
#     register = {}
# 
#     for py_file in Path(__file__).parent.joinpath(MANAGER_SUBFOLDER).glob("*.py"):
#         logger.debug(f"Search manager definitions in {py_file}")
#         module = import_module(
#             f".{MANAGER_SUBFOLDER}.{py_file.stem}", package=__package__
#         )
# 
#         for _, klass in inspect.getmembers(module, inspect.isclass):
#             if issubclass(klass, PackageManager) and not klass.virtual:
#                 logger.debug(f"Found {klass!r}")
#                 manager = klass()
#                 register[manager.id] = manager
#             else:
#                 logger.debug(f"{klass!r} is not a valid manager definition")
# 
#     return register


# Path: meta_package_manager/tests/test_docs.py
import json
import re
import tomli
from collections import Counter
from pathlib import Path
from boltons.iterutils import flatten
from click_extra.platform import OS_DEFINITIONS, os_label
from click_extra.tests.conftest import unless_linux
from yaml import Loader, load
from ..labels import MANAGER_LABELS, MANAGER_PREFIX, PLATFORM_LABELS, PLATFORM_PREFIX
from ..pool import ALL_MANAGER_IDS, pool

    # Each platforms has at least a rule.
    assert min(rules_platforms.values()) >= 1

    # Check that all canonical labels are referenced in rules.
    assert canonical_labels.issuperset(rules_platforms)

    # Check each rule definition.
    for rule in rules:

        # No duplicate labels.
        assert len(set(rule["labels"])) == len(rule["labels"])

        # Special checks for rules targetting manager labels.
        manager_label = canonical_managers.intersection(rule["labels"])
        if manager_label:

            # Extract manager label
            assert len(manager_label) == 1
            manager_label = manager_label.pop()

            # Only platforms are expected alongside manager labels.
            platforms = set(rule["labels"]) - canonical_managers
            assert platforms.issubset(canonical_platforms)

            # Check managers sharing the same label shares the same platforms.
            supported_platforms = [
                pool()[mid].platforms
                for mid, lbl in MANAGER_LABELS.items()
                # Relying on pool() restrict our checks, as the pool exclude
                # non-locally supported managers.

                if lbl == manager_label and mid in pool()