Skip to content

Commit 413ed1b

Browse files
committed
Fix pyfrc simulation entrypoint for python < 3.10
1 parent fea7602 commit 413ed1b

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

pyfrc/mains/cli_sim.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
11
import os
22
from os.path import abspath, dirname
33
import argparse
4+
import importlib.metadata
45
import inspect
56
import logging
67
import pathlib
8+
import sys
79

8-
from importlib.metadata import metadata, entry_points
910

1011
logger = logging.getLogger("pyfrc.sim")
1112

1213

14+
if sys.version_info < (3, 10):
15+
16+
def entry_points(group):
17+
eps = importlib.metadata.entry_points()
18+
return eps.get(group)
19+
20+
else:
21+
entry_points = importlib.metadata.entry_points
22+
23+
1324
class PyFrcSim:
1425
"""
1526
Runs the robot using WPILib's GUI HAL Simulator
@@ -26,8 +37,6 @@ def __init__(self, parser: argparse.ArgumentParser):
2637
self.simexts = {}
2738

2839
for entry_point in entry_points(group="robotpysimext"):
29-
if entry_point.module == "halsim_gui":
30-
continue
3140
try:
3241
sim_ext_module = entry_point.load()
3342
except ImportError:
@@ -36,11 +45,15 @@ def __init__(self, parser: argparse.ArgumentParser):
3645

3746
self.simexts[entry_point.name] = sim_ext_module
3847

48+
try:
49+
cmd_help = importlib.metadata.metadata(entry_point.dist.name)["summary"]
50+
except AttributeError:
51+
cmd_help = "Load specified simulation extension"
3952
parser.add_argument(
4053
f"--{entry_point.name}",
4154
default=False,
4255
action="store_true",
43-
help=metadata(entry_point.dist.name)["summary"],
56+
help=cmd_help,
4457
)
4558

4659
def run(self, options, robot_class, **static_options):

0 commit comments

Comments
 (0)