Skip to content

Commit

Permalink
python < 3.9 compat
Browse files Browse the repository at this point in the history
  • Loading branch information
simleo committed Mar 12, 2024
1 parent 3c9b9d4 commit 6fea6d6
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions rocrate/vocabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,28 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import sys
import json
import importlib.resources
if sys.version_info.minor < 9:
import pkg_resources
else:
import importlib.resources

# FIXME: Avoid eager loading?
RO_CRATE = json.loads(
importlib.resources.files(__package__).joinpath("data/ro-crate.jsonld").read_text()
)
SCHEMA = json.loads(
importlib.resources.files(__package__).joinpath("data/schema.jsonld").read_text()
)
if sys.version_info.minor < 9:
RO_CRATE = json.loads(pkg_resources.resource_string(
__name__, "data/ro-crate.jsonld"
))
SCHEMA = json.loads(pkg_resources.resource_string(
__name__, "data/schema.jsonld"
))
else:
RO_CRATE = json.loads(
importlib.resources.files(__package__).joinpath("data/ro-crate.jsonld").read_text()
)
SCHEMA = json.loads(
importlib.resources.files(__package__).joinpath("data/schema.jsonld").read_text()
)
SCHEMA_MAP = dict((e["@id"], e) for e in SCHEMA["@graph"])


Expand Down

0 comments on commit 6fea6d6

Please sign in to comment.