Skip to content

Commit

Permalink
Merge pull request #192 from tristan-ranff/master
Browse files Browse the repository at this point in the history
try and use importlib where possible
  • Loading branch information
whitews authored Apr 19, 2024
2 parents c5e79dc + 9f7da99 commit fb19604
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions src/flowkit/_resources/__init__.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
"""
Contains non-code resources used in FlowKit
"""
from pkg_resources import resource_filename

from importlib import resources
from lxml import etree
import os
import pathlib

resource_path = resource_filename('flowkit', '_resources')
# force POSIX-style path, even on Windows
resource_path = pathlib.Path(resource_path).as_posix()
try:
resource_dir = resources.files("flowkit")
xsd_file = resource_dir / "_resources" / "Gating-ML.v2.0.xsd"
except AttributeError:
from pkg_resources import resource_filename
from pathlib import Path

resource_dir = resource_filename("flowkit", "_resources")
xsd_file = Path(resource_dir) / "Gating-ML.v2.0.xsd"

# We used to edit the import paths for Transformations & DataTypes,
# but it still caused an XMLSchemaParseError when FlowKit was
# installed in a location where the path contained "special"
# characters (i.e. accented letters). Instead, we now change
# directories temporarily to the XSD location, read in the files,
# and then change back to the original CWD.
orig_dir = os.getcwd()
os.chdir(resource_path)
gml_tree = etree.parse('Gating-ML.v2.0.xsd')
with xsd_file.open("rb") as file:
gml_tree = etree.parse(file)
gml_schema = etree.XMLSchema(gml_tree)
os.chdir(orig_dir)

0 comments on commit fb19604

Please sign in to comment.