Skip to content

Commit

Permalink
Merge pull request #20 from datamol-io/fix/dataloading
Browse files Browse the repository at this point in the history
Fix issues with loading data on python 3.9
  • Loading branch information
maclandrol authored Jan 28, 2024
2 parents a63bd6f + a389c84 commit 2085ba6
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.11"]
python-version: ["3.9", "3.11"]

runs-on: "ubuntu-latest"
timeout-minutes: 30
Expand Down
Empty file added medchem/data/__init__.py
Empty file.
Empty file.
Empty file.
Empty file.
15 changes: 12 additions & 3 deletions medchem/utils/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@

import os
import io
import sys
import functools
import importlib.resources

try:
import importlib.resources as importlib_resources
except ImportError:
import importlib_resources

import fsspec

Expand All @@ -14,7 +19,11 @@
def get_data_path(filename: str, module: str = "medchem.data"):
"""Return the filepath of an internal data file."""

path = importlib.resources.files(module).joinpath(filename)
if sys.version_info < (3, 9, 0):
with importlib_resources.path(module, filename) as p:
path = p
else:
path = importlib_resources.files(module).joinpath(filename)
return str(path)


Expand All @@ -29,7 +38,7 @@ def get_grammar(
as_string: If True, return the grammar as a string. Defaults to False.
"""
if grammar is None:
_grammar = importlib.resources.files("medchem.data").joinpath("grammar.lark")
_grammar = get_data_path("grammar.lark")
_grammar = str(_grammar)
else:
_grammar = str(grammar)
Expand Down

0 comments on commit 2085ba6

Please sign in to comment.