Skip to content

Commit

Permalink
Restore python 3.8 functionality
Browse files Browse the repository at this point in the history
Use the importlib_resources backport.

This allows a fairly seamless python3.12 bump before the 1.29 upgrade
  • Loading branch information
willthames committed Dec 16, 2023
1 parent fd90198 commit 8291652
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tox.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
strategy:
matrix:
platform: [ubuntu-latest, windows-latest]
python-version: ["3.9", "3.10", "3.11", "3.12"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v1
Expand Down
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ license = {text = "Apache"}
dependencies = [
'PyYAML',
'jsonschema',
'typing-extensions'
'typing-extensions',
'importlib-resources',
'packaging'
]
dynamic = ["version", "readme"]

Expand Down
10 changes: 6 additions & 4 deletions src/kubernetes_validate/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
from packaging.version import Version

import jsonschema
import importlib.resources

import importlib_resources

import yaml

from kubernetes_validate.version import __version__
Expand Down Expand Up @@ -48,7 +50,7 @@ def __init__(self, message: str):


def all_versions() -> List[str]:
schemas = importlib.resources.files('kubernetes_validate').joinpath('kubernetes-json-schema')
schemas = importlib_resources.files('kubernetes_validate').joinpath('kubernetes-json-schema')
version_regex = re.compile(r'^v([^-]*).*')
return sorted([version_regex.sub(r"\1", schema.name)
for schema in schemas.iterdir()
Expand Down Expand Up @@ -85,10 +87,10 @@ def validate(data: Union[Dict[str, Any], SupportsToDict], desired_version: str,
schema_dir = 'v%s-local' % version
if strict:
schema_dir += '-strict'
ref = importlib.resources.files('kubernetes_validate').joinpath('kubernetes-json-schema/%s/%s-%s.json' %
ref = importlib_resources.files('kubernetes_validate').joinpath('kubernetes-json-schema/%s/%s-%s.json' %
(schema_dir, data['kind'].lower(),
api_version))
with importlib.resources.as_file(ref) as schema_file:
with importlib_resources.as_file(ref) as schema_file:
try:
f = open(schema_file)
except IOError:
Expand Down
7 changes: 4 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
[tox]
minversion = 1.6
envlist = py{39,310,311,312}-{pytest,flake8},mypy
envlist = py{38,39,310,311,312}-{pytest,flake8},mypy

[gh-actions]
python =
3.8: py38, mypy
3.9: py39, mypy
3.10: py310, mypy
3.11: py311, mypy
3.12: py312, mypy

[testenv]

[testenv:py{39,310,311,312}-pytest]
[testenv:py{38,39,310,311,312}-pytest]
deps =
-rtest-deps.txt
commands = pytest
passenv = HOME
recreate = False

[testenv:py{39,310,311,312}-flake8]
[testenv:py{38,39,310,311,312}-flake8]
platform = linux|darwin
deps = flake8
commands = python -m flake8 src
Expand Down

0 comments on commit 8291652

Please sign in to comment.