Skip to content

Commit

Permalink
Merge pull request #212 from kkovary/211-fix-resource-warning
Browse files Browse the repository at this point in the history
Fix ResourceWarning due to unclosed file
  • Loading branch information
hadim committed Sep 18, 2023
2 parents 22b5bb0 + 4bf712c commit e3c4a38
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions datamol/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import sys
import io
import functools

try:
import importlib.resources as importlib_resources
Expand All @@ -27,6 +28,17 @@
from ..convert import render_mol_df


@functools.lru_cache()
def datamol_data_file_path(filename: str, dm_module: str = "datamol.data") -> str:
if sys.version_info < (3, 9, 0):
with importlib_resources.path(dm_module, filename) as p:
data_path = p
else:
data_path = importlib_resources.files(dm_module).joinpath(filename)

return str(data_path)


def open_datamol_data_file(
filename: str,
open_binary: bool = False,
Expand Down
2 changes: 1 addition & 1 deletion datamol/mol.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
AROMATIC_BOND = Chem.rdchem.BondType.AROMATIC
DATIVE_BOND = Chem.rdchem.BondType.DATIVE
UNSPECIFIED_BOND = Chem.rdchem.BondType.UNSPECIFIED
SALT_SOLVENT_PATH = datamol.data.open_datamol_data_file("salts_solvents.smi").name
SALT_SOLVENT_PATH = datamol.data.datamol_data_file_path("salts_solvents.smi")
SALT_SOLVENT_REMOVER = SaltRemover(defnFilename=SALT_SOLVENT_PATH)


Expand Down

0 comments on commit e3c4a38

Please sign in to comment.