Skip to content

Commit 740fc20

Browse files
committed
Fix entry point loading in >3.9 python for pfb and users
Update test_cli to assert SystemExit 0
1 parent 253be88 commit 740fc20

File tree

7 files changed

+41
-14
lines changed

7 files changed

+41
-14
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ jobs:
1919
strategy:
2020
matrix:
2121
# the versions for which we require the CI to pass on PRs can
22+
2223
# be updated in the repo settings (branch rules)
2324
version: ['3.9', '3.10', '3.11', '3.12', '3.13']
2425
fail-fast: false # run for all versions even if one of them fails
2526
with:
2627
python-version: ${{ matrix.version }}
28+
poetry-version: '2.2.1' # Max version supported by python 3.9

gen3/cli/pfb.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import click
2+
import sys
23
from pfb import cli as pfb_cli
34

5+
from gen3.utils import load_entry_points
6+
47
try:
58
from importlib.metadata import entry_points
69
except ImportError:
@@ -22,6 +25,4 @@ def pfb():
2225
for command in pfb_cli.main.commands:
2326
pfb.add_command(pfb_cli.main.get_command(ctx=None, cmd_name=command))
2427

25-
# load plug-ins from entry_points
26-
for ep in entry_points().get("gen3.plugins", []):
27-
ep.load()
28+
load_entry_points()

gen3/cli/users.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import click
22

33
from gen3users import main as users_cli
4+
import sys
45

6+
from gen3.utils import load_entry_points
57

68
try:
79
from importlib.metadata import entry_points
@@ -24,6 +26,4 @@ def users():
2426
for command in users_cli.main.commands:
2527
users.add_command(users_cli.main.get_command(ctx=None, cmd_name=command))
2628

27-
# load plug-ins from entry_points
28-
for ep in entry_points().get("gen3.plugins", []):
29-
ep.load()
29+
load_entry_points()

gen3/utils.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,23 @@ def deep_dict_update(a, b):
341341
return a
342342

343343

344+
def load_entry_points():
345+
try:
346+
from importlib.metadata import entry_points
347+
except ImportError:
348+
from importlib_metadata import entry_points
349+
350+
# Load plug-ins from entry_points (syntax changes for python 3.12+)
351+
major = sys.version_info[0]
352+
minor = sys.version_info[1]
353+
if major == 3 and minor >= 12:
354+
for ep in entry_points(group="pfb.plugins"):
355+
ep.load()
356+
else:
357+
for ep in entry_points().get("pfb.plugins", []):
358+
ep.load()
359+
360+
344361
# Default settings to control usage of backoff library.
345362
DEFAULT_BACKOFF_SETTINGS = {
346363
# Disable backoff lib default logger, only show custom logs

poetry.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ importlib_metadata = ">=8,<9"
3030
jsonschema = "*"
3131
# FIXME updating to >=0.6.0 breaks a few tests
3232
dataclasses-json = "<=0.5.9"
33-
pypfb = ">=0.5.33"
33+
pypfb = ">=0.6.2"
3434
tqdm = "^4.61.2"
3535
humanfriendly ="*"
3636
python-dateutil = "*"

tests/test_cli.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
1-
def test_import_cli():
2-
import gen3.cli.__main__
1+
import pytest
2+
3+
4+
def test_import_cli(monkeypatch):
5+
monkeypatch.setattr("sys.argv", ["gen3", "--help"])
6+
with pytest.raises(SystemExit) as e:
7+
import gen3.cli.__main__
8+
9+
assert e.value.code == 0

0 commit comments

Comments
 (0)