Skip to content

Commit

Permalink
Revert "Migrate from deprecated importlib.resources function"
Browse files Browse the repository at this point in the history
This reverts commit 9ace677.
  • Loading branch information
eigenbeam committed Jan 14, 2025
1 parent 9ace677 commit 41f515a
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/nsidc/metgen/metgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import os.path
import sys
import uuid
from importlib.resources import files
from importlib.resources import open_text
from pathlib import Path
from string import Template
from typing import Callable
Expand Down Expand Up @@ -668,14 +668,13 @@ def cnms_body_template():
def cnms_files_template():
return initialize_template(constants.CNM_FILES_TEMPLATE)

def _open_text(anchor, name):
for t in files(anchor).iterdir():
if t.name == name:
return t.read_text()
return None

def initialize_template(resource_location):
return Template(_open_text(*resource_location))
with open_text(*resource_location) as template_file:
template_str = template_file.read()

return Template(template_str)


def validate(configuration, content_type):
"""
Expand All @@ -687,11 +686,12 @@ def validate(configuration, content_type):
logger = logging.getLogger(constants.ROOT_LOGGER)
logger.info("")
logger.info(f"Validating files in {output_file_path}...")
with open_text(*schema_resource_location) as sf:
schema = json.load(sf)

schema = json.load(_open_text(*schema_resource_location))
# loop through all files and validate each one
for json_file in output_file_path.glob("*.json"):
apply_schema(schema, json_file, dummy_json)
# loop through all files and validate each one
for json_file in output_file_path.glob("*.json"):
apply_schema(schema, json_file, dummy_json)

logger.info("Validations complete.")
return True
Expand Down

0 comments on commit 41f515a

Please sign in to comment.