From 413ed1bafe25f13bc0368c68febe5ba8b5db0e47 Mon Sep 17 00:00:00 2001 From: Dustin Spicuzza Date: Sat, 30 Dec 2023 03:49:41 -0500 Subject: [PATCH] Fix pyfrc simulation entrypoint for python < 3.10 --- pyfrc/mains/cli_sim.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/pyfrc/mains/cli_sim.py b/pyfrc/mains/cli_sim.py index d5200d9..904bfb6 100644 --- a/pyfrc/mains/cli_sim.py +++ b/pyfrc/mains/cli_sim.py @@ -1,15 +1,26 @@ import os from os.path import abspath, dirname import argparse +import importlib.metadata import inspect import logging import pathlib +import sys -from importlib.metadata import metadata, entry_points logger = logging.getLogger("pyfrc.sim") +if sys.version_info < (3, 10): + + def entry_points(group): + eps = importlib.metadata.entry_points() + return eps.get(group) + +else: + entry_points = importlib.metadata.entry_points + + class PyFrcSim: """ Runs the robot using WPILib's GUI HAL Simulator @@ -26,8 +37,6 @@ def __init__(self, parser: argparse.ArgumentParser): self.simexts = {} for entry_point in entry_points(group="robotpysimext"): - if entry_point.module == "halsim_gui": - continue try: sim_ext_module = entry_point.load() except ImportError: @@ -36,11 +45,15 @@ def __init__(self, parser: argparse.ArgumentParser): self.simexts[entry_point.name] = sim_ext_module + try: + cmd_help = importlib.metadata.metadata(entry_point.dist.name)["summary"] + except AttributeError: + cmd_help = "Load specified simulation extension" parser.add_argument( f"--{entry_point.name}", default=False, action="store_true", - help=metadata(entry_point.dist.name)["summary"], + help=cmd_help, ) def run(self, options, robot_class, **static_options):