From cfc724c86ff5a5cd77e0e5a638061acb56f7a2c8 Mon Sep 17 00:00:00 2001 From: jhpyke Date: Mon, 16 Dec 2024 11:01:39 +0000 Subject: [PATCH] Update to fix pkg_resources deprecation while maintaining back compat --- iam_builder/iam_schema.py | 21 +++++++++++++++++---- poetry.lock | 14 ++++++++++++-- pyproject.toml | 1 + 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/iam_builder/iam_schema.py b/iam_builder/iam_schema.py index 719a32d..bf516cf 100644 --- a/iam_builder/iam_schema.py +++ b/iam_builder/iam_schema.py @@ -1,11 +1,24 @@ import jsonschema import json -import pkg_resources +import importlib from iam_builder.exceptions import IAMValidationError -IAM_SCHEMA = json.load( - pkg_resources.resource_stream(__name__, "schemas/iam_schema.json") -) +try: + import pkg_resources +except ImportError: + import importlib + + +try: + IAM_SCHEMA = json.load( + pkg_resources.resource_stream(__name__, "schemas/iam_schema.json") + ) +except ImportError: + ref = importlib_resources.files(__name__).joinpath("schemas/iam_schema.json") + with ref.open('rb') as fp: + IAM_SCHEMA = json.load( + fp.read() + ) def validate_iam(config: dict): diff --git a/poetry.lock b/poetry.lock index 747f382..e388852 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.8.4 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.8.5 and should not be changed by hand. [[package]] name = "attrs" @@ -22,6 +22,16 @@ docs = ["cogapp", "furo", "myst-parser", "sphinx", "sphinx-notfound-page", "sphi tests = ["cloudpickle", "hypothesis", "mypy (>=1.11.1)", "pympler", "pytest (>=4.3.0)", "pytest-mypy-plugins", "pytest-xdist[psutil]"] tests-mypy = ["mypy (>=1.11.1)", "pytest-mypy-plugins"] +[[package]] +name = "importlib" +version = "1.0.4" +description = "Backport of importlib.import_module() from Python 2.7" +optional = false +python-versions = "*" +files = [ + {file = "importlib-1.0.4.zip", hash = "sha256:b6ee7066fea66e35f8d0acee24d98006de1a0a8a94a8ce6efe73a9a23c8d9826"}, +] + [[package]] name = "importlib-metadata" version = "6.7.0" @@ -233,4 +243,4 @@ testing = ["big-O", "flake8 (<5)", "jaraco.functools", "jaraco.itertools", "more [metadata] lock-version = "2.0" python-versions = "^3.7" -content-hash = "c219fc7057748ca636f0b399d2a185f4fd032082c52cd2edfd115f681659fa0f" +content-hash = "31b7dfa41c123da6d641f88c7162b15be0886ccceaa1a2a859e271d2e0ef868e" diff --git a/pyproject.toml b/pyproject.toml index 1cadfe7..b4788a1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,6 +11,7 @@ python = "^3.7" PyYAML = "^6.0" parameterized = "0.7.*" jsonschema = "^4.10.0" +importlib = "^1.0.4" [tool.poetry.scripts] iam_builder = "iam_builder.command_line:main"