Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #313 remove handle #315

Merged
merged 6 commits into from
May 5, 2022
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions ontopy/ontology.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,12 +646,21 @@ def save(
revmap = {value: key for key, value in FMAP.items()}
super().save(file=filename, format=revmap[format], **kwargs)
else:
with tempfile.NamedTemporaryFile(suffix=".owl") as handle:
tmpname = handle.name
super().save(file=tmpname, format="rdfxml", **kwargs)
graph = rdflib.Graph()
graph.parse(tmpname, format="xml")
graph.serialize(destination=filename, format=format)
# The try-finally clause is needed for cleanup and because
# we have to provide delete=False to NamedTemporaryFile
# since Windows does not allow to reopen an already open
# file.
try:
with tempfile.NamedTemporaryFile(
suffix=".owl", delete=False
) as handle:
tmpfile = handle.name
super().save(tmpfile, format="rdfxml", **kwargs)
graph = rdflib.Graph()
graph.parse(tmpfile, format="xml")
graph.serialize(destination=filename, format=format)
finally:
os.remove(tmpfile)

def get_imported_ontologies(self, recursive=False):
"""Return a list with imported ontologies.
Expand Down