Skip to content

Move from pkg_resources to importlib.metadata #222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions robotpy_build/pkgcfg_provider.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import importlib.util
from importlib.metadata import entry_points, EntryPoint
from os.path import join, dirname
from pkg_resources import iter_entry_points
import sys
from typing import Dict, List, Optional, Set
import warnings
Expand All @@ -27,12 +27,17 @@ class PkgCfg:
Contains information about an installed package that uses robotpy-build
"""

def __init__(self, entry_point):
def __init__(self, entry_point: EntryPoint):
try:
self.module = entry_point.load()
except Exception as e:
try:
self.module = _hacky_entrypoint_loader(entry_point.module_name)
mod = (
entry_point.module
if hasattr(entry_point, "module")
else entry_point.value
)
self.module = _hacky_entrypoint_loader(mod)
except Exception:
raise e

Expand Down Expand Up @@ -147,7 +152,13 @@ def detect_pkgs(self) -> None:
Only loads packages that are dependencies.
"""
deps_names = set().union(*[pkg.depends for pkg in self.pkgs.values()])
entry_points = list(iter_entry_points(group="robotpybuild", name=None))
ep_ret = entry_points()

# Python 3.8/3.9
if isinstance(ep_ret, dict):
all_entry_points = ep_ret.get("robotpybuild", [])
else:
all_entry_points = [e for e in entry_points() if e.group == "robotpybuild"]

# Only load the dependencies of the package we're building.
# If we load the [package being built], then the current build will fail.
Expand All @@ -156,7 +167,7 @@ def detect_pkgs(self) -> None:
run_loop = True
while run_loop:
run_loop = False
for ep in entry_points:
for ep in all_entry_points:
if ep.name in self.pkgs: # Prevents loading the package being built
continue
if ep.name not in deps_names and ep.name != "robotpy-build":
Expand Down