# 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

    # Extract rules from json blurb serialized into YAML.
    content = PROJECT_ROOT.joinpath(
        ".github/workflows/labeller-content-based.yaml"
    ).read_text()
    assert "Naturalclar/issue-action" in content
    json_rules = load(content, Loader=Loader)["jobs"]["labeller"]["steps"][0]["with"][
        "parameters"
    ]
    rules = json.loads(json_rules)
    assert rules

    # Each keyword match one rule only.
    rules_keywords = Counter(flatten([r["keywords"] for r in rules]))
    assert rules_keywords
    assert max(rules_keywords.values()) == 1

    # Extract and categorize labels.
    rules_labels = Counter(flatten([r["labels"] for r in rules]))

    assert rules_labels
    # Check that all canonical labels are referenced in rules.
    assert (canonical_labels - {"🔌 BitBar plugin", "📦 manager: mpm"}).issubset(
        rules_labels
    )

    rules_managers = Counter(
        {
            label: count
            for label, count in rules_labels.items()

# 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


    # Extract rules from json blurb serialized into YAML.
    content = PROJECT_ROOT.joinpath(
        ".github/workflows/labeller-content-based.yaml"
    ).read_text()
    assert "Naturalclar/issue-action" in content
    json_rules = load(content, Loader=Loader)["jobs"]["labeller"]["steps"][0]["with"][
        "parameters"
    ]
    rules = json.loads(json_rules)
    assert rules

    # Each keyword match one rule only.
    rules_keywords = Counter(flatten([r["keywords"] for r in rules]))
    assert rules_keywords
    assert max(rules_keywords.values()) == 1

    # Extract and categorize labels.
    rules_labels = Counter(flatten([r["labels"] for r in rules]))

    assert rules_labels
    # Check that all canonical labels are referenced in rules.
    assert (canonical_labels - {"🔌 BitBar plugin", "📦 manager: mpm"}).issubset(
        rules_labels
    )

    rules_managers = Counter(
        {
            label: count
            for label, count in rules_labels.items()

            if label.startswith(MANAGER_PREFIX)