Skip to content

Commit

Permalink
fix: migrate to modern entry_points api
Browse files Browse the repository at this point in the history
  • Loading branch information
vberlier committed Jan 29, 2023
1 parent 3a92a85 commit 473e6e5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 27 deletions.
7 changes: 3 additions & 4 deletions beet/toolchain/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import logging
from contextlib import contextmanager
from importlib.metadata import entry_points
from typing import Any, Callable, Iterator, List, Optional

import click
Expand All @@ -24,7 +25,6 @@
from beet.core.utils import format_exc

from .project import Project
from .utils import select_entry_points


def format_error(
Expand Down Expand Up @@ -211,9 +211,8 @@ def load_entry_points(self):

self.entry_points_loaded = True

for ep in select_entry_points("beet"):
if ep.name == "commands":
ep.load()
for ep in entry_points(group="beet", name="commands"):
ep.load()

def get_command(self, ctx: click.Context, cmd_name: str) -> Optional[click.Command]:
self.load_entry_points()
Expand Down
4 changes: 2 additions & 2 deletions beet/toolchain/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from contextlib import ExitStack, contextmanager
from copy import deepcopy
from dataclasses import dataclass
from importlib.metadata import entry_points
from pathlib import Path
from tempfile import TemporaryDirectory
from typing import Any, ClassVar, Iterable, Iterator, List, Optional, Sequence
Expand All @@ -33,7 +34,6 @@
from .config import PackConfig, ProjectConfig, load_config, locate_config
from .context import Context, PluginSpec, ProjectCache
from .template import TemplateManager
from .utils import select_entry_points
from .worker import WorkerPool


Expand Down Expand Up @@ -228,7 +228,7 @@ def __init__(

if ProjectBuilder.autoload is None:
ProjectBuilder.autoload = [
ep.value for ep in select_entry_points("beet") if ep.name == "autoload"
ep.value for ep in entry_points(group="beet", name="autoload")
]

@contextmanager
Expand Down
22 changes: 1 addition & 21 deletions beet/toolchain/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,8 @@

import json
import re
import sys
from copy import copy
from importlib.metadata import EntryPoint, entry_points
from typing import (
Any,
Callable,
Iterable,
List,
Literal,
Mapping,
Sequence,
Tuple,
cast,
)
from typing import Any, Callable, Iterable, List, Literal, Mapping, Sequence, cast

FNV_32_INIT = 0x811C9DC5
FNV_64_INIT = 0xCBF29CE484222325
Expand Down Expand Up @@ -85,14 +73,6 @@ def ensure_builtins(value: Any) -> Any:
raise TypeError(value) from None


def select_entry_points(group: str) -> Tuple[EntryPoint, ...]:
eps: Any = entry_points()
if sys.version_info >= (3, 10):
return eps.select(group=group)
else:
return eps.get(group, ())


def iter_options(options: Any) -> Iterable[str]:
if isinstance(options, str):
yield from options.splitlines()
Expand Down

0 comments on commit 473e6e5

Please sign in to comment.