Skip to content

Commit 2c4df3b

Browse files
authored
Replaced 'entry_points' instances with 'backports.entry_points_selectable' one (#400)
* Replaced 'entry_points' instances with those from 'backports.entry_points_selectable' * Removed 'importlib_resources' as Python 3.8 no longer supported * Highlighted when external entry points are being looked for
1 parent 7821855 commit 2c4df3b

File tree

4 files changed

+13
-22
lines changed

4 files changed

+13
-22
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ classifiers = [
3030
"Programming Language :: Python :: 3.12",
3131
]
3232
dependencies = [
33+
"backports.entry_points_selectable",
3334
"defusedxml", # For safely parsing XML files
3435
"pydantic<2", # Locked to <2 by zocalo
3536
"requests",
@@ -55,7 +56,6 @@ developer = [
5556
server = [
5657
# "matplotlib", # For visual statistical analysis of images
5758
"aiohttp",
58-
"backports.entry_points_selectable",
5959
"cryptography",
6060
"fastapi[standard]",
6161
"ispyb", # Responsible for setting requirements for SQLAlchemy and mysql-connector-python; v10.0.0: sqlalchemy <2, mysql-connector-python >=8.0.32

src/murfey/client/context.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from pathlib import Path
55
from typing import Any, Dict, List, NamedTuple
66

7-
import importlib_metadata
7+
from backports.entry_points_selectable import entry_points
88

99
from murfey.client.instance_environment import MurfeyInstanceEnvironment
1010

@@ -41,7 +41,8 @@ def __init__(self, name: str, acquisition_software: str):
4141
self.name = name
4242

4343
def post_transfer(self, transferred_file: Path, role: str = "", **kwargs):
44-
for h in importlib_metadata.entry_points(group="murfey.post_transfer_hooks"):
44+
# Search external packages for additional hooks to include in Murfey
45+
for h in entry_points(group="murfey.post_transfer_hooks"):
4546
if h.name == self.name:
4647
h.load()(transferred_file, role=role, **kwargs)
4748

src/murfey/server/__init__.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import time
99
from datetime import datetime
1010
from functools import partial, singledispatch
11+
from importlib.resources import files
1112
from pathlib import Path
1213
from threading import Thread
1314
from typing import Any, Dict, List, NamedTuple, Tuple
@@ -17,8 +18,10 @@
1718
import uvicorn
1819
import workflows
1920
import zocalo.configuration
21+
from backports.entry_points_selectable import entry_points
2022
from fastapi import Request
2123
from fastapi.templating import Jinja2Templates
24+
from importlib_metadata import EntryPoint # For type hinting only
2225
from ispyb.sqlalchemy._auto_db_schema import (
2326
AutoProcProgram,
2427
Base,
@@ -42,33 +45,25 @@
4245
import murfey
4346
import murfey.server.prometheus as prom
4447
import murfey.server.websocket
48+
import murfey.util.db as db
4549
from murfey.client.contexts.tomo import _midpoint
4650
from murfey.server.murfey_db import url # murfey_db
51+
from murfey.util import LogFilter
4752
from murfey.util.config import (
4853
MachineConfig,
4954
get_hostname,
5055
get_machine_config,
5156
get_microscope,
5257
get_security_config,
5358
)
59+
from murfey.util.spa_params import default_spa_parameters
60+
from murfey.util.state import global_state
5461

5562
try:
5663
from murfey.server.ispyb import TransportManager # Session
5764
except AttributeError:
5865
pass
59-
from backports.entry_points_selectable import entry_points
60-
from importlib_metadata import EntryPoint # For type hinting only
6166

62-
import murfey.util.db as db
63-
from murfey.util import LogFilter
64-
from murfey.util.spa_params import default_spa_parameters
65-
from murfey.util.state import global_state
66-
67-
try:
68-
from importlib.resources import files # type: ignore
69-
except ImportError:
70-
# Fallback for Python 3.8
71-
from importlib_resources import files # type: ignore
7267

7368
logger = logging.getLogger("murfey.server")
7469

src/murfey/server/main.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import logging
44
import os
5-
import sys
65

6+
from backports.entry_points_selectable import entry_points
77
from fastapi import FastAPI
88
from fastapi.middleware.cors import CORSMiddleware
99
from fastapi.staticfiles import StaticFiles
@@ -23,12 +23,6 @@
2323
from murfey.server import template_files
2424
from murfey.util.config import get_security_config
2525

26-
# Use importlib_metadata based on Python version
27-
if sys.version_info < (3, 10):
28-
from importlib_metadata import entry_points
29-
else:
30-
from importlib.metadata import entry_points
31-
3226
# Import Murfey server or demo server based on settings
3327
if os.getenv("MURFEY_DEMO"):
3428
from murfey.server.demo_api import router
@@ -82,5 +76,6 @@ class Settings(BaseSettings):
8276
app.include_router(murfey.server.api.hub.router)
8377
app.include_router(murfey.server.websocket.ws)
8478

79+
# Search external packages for additional routers to include in Murfey
8580
for r in entry_points(group="murfey.routers"):
8681
app.include_router(r.load())

0 commit comments

Comments
 (0)