Skip to content

Commit

Permalink
Use importlib resources instead of pkg_resources
Browse files Browse the repository at this point in the history
  • Loading branch information
ksunden committed Jun 20, 2023
1 parent bc8cdbf commit a9e6ff9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
16 changes: 8 additions & 8 deletions event_model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
from dataclasses import dataclass
from enum import Enum
from functools import partial
from importlib.metadata import metadata
from importlib.metadata import version as importlib_version
from typing import (
Any,
Callable,
Expand All @@ -34,7 +36,6 @@
import jsonschema
import numpy
from packaging import version
from pkg_resources import resource_filename as rs_fn
from typing_extensions import Literal

from .documents.datum import Datum
Expand All @@ -53,12 +54,10 @@
from .documents.stream_datum import StreamDatum
from .documents.stream_resource import StreamResource

if sys.version_info < (3, 8):
from importlib_metadata import metadata
from importlib_metadata import version as importlib_version
if sys.version_info < (3, 9):
import importlib_resources
else:
from importlib.metadata import metadata
from importlib.metadata import version as importlib_version
import importlib.resources as importlib_resources

__version__ = importlib_version("event-model")

Expand Down Expand Up @@ -1803,8 +1802,9 @@ class MismatchedDataKeys(InvalidData):
}
schemas = {}
for name, filename in SCHEMA_NAMES.items():
with open(rs_fn("event_model", filename)) as fin:
schemas[name] = json.load(fin)
ref = importlib_resources.files("event_model") / filename
with ref.open() as f:
schemas[name] = json.load(f)

# We pin jsonschema >=3.0.0 in requirements.txt but due to pip's dependency
# resolution it is easy to end up with an environment where that pin is not
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ classifiers = [
]
description = "Data model used by the bluesky ecosystem"
dependencies = [
"importlib-metadata",
"importlib-resources",
"jsonschema",
"numpy",
"packaging",
Expand Down

0 comments on commit a9e6ff9

Please sign in to comment.