Skip to content

Commit

Permalink
Fix pyfrc simulation entrypoint for python < 3.10
Browse files Browse the repository at this point in the history
  • Loading branch information
virtuald committed Dec 30, 2023
1 parent fea7602 commit 413ed1b
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions pyfrc/mains/cli_sim.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
Expand All @@ -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):
Expand Down

0 comments on commit 413ed1b

Please sign in to comment.