diff --git a/iso18245/__init__.py b/iso18245/__init__.py index fba5edf..d32d693 100644 --- a/iso18245/__init__.py +++ b/iso18245/__init__.py @@ -1,8 +1,7 @@ import csv -import os.path -from typing import Any, Dict, List, NamedTuple +from typing import Dict, List, NamedTuple -from pkg_resources import resource_filename +from importlib_resources import files ISO_VERSION_YEAR = 2003 @@ -41,13 +40,13 @@ class MCC(NamedTuple): def _load_csv(path: str) -> List[List[str]]: - if path not in _cached_csv: - full_path = resource_filename("iso18245", os.path.join("data", path)) - with open(full_path, "r") as f: - reader = csv.reader(f) - _cached_csv[path] = list(reader)[1:] + if path not in _cached_csv: + ref = files("iso18245") / "data" / path + with ref.open("r") as f: + reader = csv.reader(f) + _cached_csv[path] = list(reader)[1:] - return _cached_csv[path] + return _cached_csv[path] def _find_mcc_in_csv(mcc: str, path: str) -> List[str]: diff --git a/pyproject.toml b/pyproject.toml index 5ae69cd..a2a1167 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,6 +17,7 @@ classifiers = [ [tool.poetry.dependencies] python = "^3.8" +importlib_resources = "^5.4.0" [tool.poetry.group.dev.dependencies] mypy = "^1.2.0"