Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
13 changes: 3 additions & 10 deletions capycli/bom/check_granularity.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
# SPDX-License-Identifier: MIT
# -------------------------------------------------------------------------------

try:
import importlib.resources as pkg_resources
except ImportError:
# Try backported to PY<37 `importlib_resources`.
import importlib_resources as pkg_resources # type: ignore
import importlib.resources as pkg_resources
import os
import sys
from typing import Any, List, Optional
Expand Down Expand Up @@ -78,11 +74,8 @@ def read_granularity_list(self, download_url: str = "", local_read_granularity:
except Exception as e:
print(f"An unexpected error occurred: {e}")
if not text_list:
if sys.version_info >= (3, 9):
resources = pkg_resources.files("capycli.data")
text_list = (resources / "granularity_list.csv").read_text()
else:
text_list = pkg_resources.read_text("capycli.data", "granularity_list.csv")
resources = pkg_resources.files("capycli.data")
text_list = (resources / "granularity_list.csv").read_text()

for line in text_list.splitlines():
# ignore header (first) line
Expand Down
18 changes: 4 additions & 14 deletions capycli/bom/component_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,9 @@
# SPDX-License-Identifier: MIT
# -------------------------------------------------------------------------------

import logging

try:
import importlib.resources as pkg_resources
except ImportError:
# Try backported to PY<37 `importlib_resources`.
import importlib_resources as pkg_resources # type: ignore

import importlib.resources as pkg_resources
import json
import logging
import os
import sys
from typing import Any, Dict, List
Expand Down Expand Up @@ -75,12 +69,8 @@ def read_component_check_list(self, download_url: str = "", local_check_list_fil
except Exception as e:
print_red(f"An unexpected error occurred: {e}")
if not self.component_check_list:
text_list = ""
if sys.version_info >= (3, 9):
resources = pkg_resources.files("capycli.data")
text_list = (resources / "component_checks.json").read_text()
else:
text_list = pkg_resources.read_text("capycli.data", "component_checks.json")
resources = pkg_resources.files("capycli.data")
text_list = (resources / "component_checks.json").read_text()

self.component_check_list = json.loads(text_list)

Expand Down
Loading
Loading