Skip to content

Commit

Permalink
meta: use pathlib to join paths in class Index
Browse files Browse the repository at this point in the history
This commit moves the joining of path fragements from f-strings
to pathlib.
  • Loading branch information
mvo5 committed Oct 16, 2024
1 parent 8f7a3d7 commit 7a70867
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions osbuild/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import importlib.util
import json
import os
import pathlib
import pkgutil
import sys
from collections import deque
Expand Down Expand Up @@ -648,7 +649,7 @@ class Index:
"""

def __init__(self, path: str):
self.path = os.path.abspath(path)
self.path = pathlib.Path(path).absolute()
self._module_info: Dict[Tuple[str, Any], Any] = {}
self._format_info: Dict[Tuple[str, Any], Any] = {}
self._schemata: Dict[Tuple[str, Any, str], Schema] = {}
Expand Down Expand Up @@ -697,9 +698,9 @@ def list_modules_for_class(self, klass: str) -> List[str]:
if not module_path:
raise ValueError(f"Unsupported nodule class: {klass}")

path = os.path.join(self.path, module_path)
modules = filter(lambda f: os.path.isfile(f"{path}/{f}") and not path.endswith(".meta.json"),
os.listdir(path))
path = self.path / module_path
modules = (f for f in path.iterdir()
if f.is_file() and not f.name.endswith(".meta.json"))
return list(modules)

def get_module_info(self, klass, name) -> Optional[ModuleInfo]:
Expand Down Expand Up @@ -728,9 +729,9 @@ def get_schema(self, klass, name=None, version="1") -> Schema:
return cached_schema

if klass == "Manifest":
path = f"{self.path}/schemas/osbuild{version}.json"
path = self.path / f"schemas/osbuild{version}.json"
with contextlib.suppress(FileNotFoundError):
with open(path, "r", encoding="utf8") as f:
with path.open("r", encoding="utf8") as f:
schema = json.load(f)
elif klass in ModuleInfo.MODULES:
info = self.get_module_info(klass, name)
Expand All @@ -752,10 +753,9 @@ def list_runners(self, distro: Optional[str] = None) -> List[RunnerInfo]:
will be returned.
"""
if not self._runners:
path = os.path.join(self.path, "runners")
names = filter(lambda f: os.path.isfile(f"{path}/{f}"),
os.listdir(path))
paths = map(lambda n: os.path.join(path, n), names)
path = self.path / "runners"
names = (f for f in path.iterdir() if f.is_file())
paths = (path / n for n in names)
mapped = map(RunnerInfo.from_path, paths)
self._runners = sorted(mapped, key=lambda r: (r.distro, r.version))

Expand Down

0 comments on commit 7a70867

Please sign in to comment.