Skip to content

Commit

Permalink
fix: change dataio to accept py3.7 and py3.8
Browse files Browse the repository at this point in the history
change importlib.resources.files (available py>3.9) to importlib.resources.path on dataio.py
  • Loading branch information
carlos-adir committed Feb 25, 2024
1 parent c8ef85b commit 7bce97e
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions src/compmec/section/dataio.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,11 @@ def read_nodes(self):
filepath: str
return: dict
"""
schema_name = "schema/curve.json"
folder = resources.files("compmec.section")
schema_path = str(folder.joinpath(schema_name))
matrix = self.read_json(schema_path)["nodes"]
schema_name = "curve.json"
with resources.path(
"compmec.section.schema", schema_name
) as schema_path:
matrix = self.read_json(str(schema_path))["nodes"]
if self.overwrite:
labels = tuple(int(line[0]) for line in matrix)
Node.clear(labels)
Expand All @@ -201,10 +202,11 @@ def read_curves(self):
filepath: str
return: dict
"""
schema_name = "schema/curve.json"
folder = resources.files("compmec.section")
schema_path = str(folder.joinpath(schema_name))
curves = self.read_json(schema_path)["curves"]
schema_name = "curve.json"
with resources.path(
"compmec.section.schema", schema_name
) as schema_path:
curves = self.read_json(str(schema_path))["curves"]
if self.overwrite:
labels = tuple(int(label) for label in curves.keys())
Curve.clear(labels)
Expand All @@ -224,10 +226,11 @@ def read_materials(self):
filepath: str
return: dict
"""
schema_name = "schema/material.json"
folder = resources.files("compmec.section")
schema_path = str(folder.joinpath(schema_name))
materials = self.read_json(schema_path)["materials"]
schema_name = "material.json"
with resources.path(
"compmec.section.schema", schema_name
) as schema_path:
materials = self.read_json(str(schema_path))["materials"]
if self.overwrite:
Material.clear(materials.keys())
for name, info in materials.items():
Expand All @@ -248,10 +251,11 @@ def read_sections(self):
The dictionary with all infos read from json
"""
schema_name = "schema/section.json"
folder = resources.files("compmec.section")
schema_path = str(folder.joinpath(schema_name))
sections = self.read_json(schema_path)["sections"]
schema_name = "section.json"
with resources.path(
"compmec.section.schema", schema_name
) as schema_path:
sections = self.read_json(str(schema_path))["sections"]
if self.overwrite:
Section.clear(sections.keys())
for name, info in sections.items():
Expand Down

0 comments on commit 7bce97e

Please sign in to comment.