Skip to content

Commit 121bb48

Browse files
committed
Move to importlib.resources.files()
1 parent 877c43e commit 121bb48

File tree

3 files changed

+13
-20
lines changed

3 files changed

+13
-20
lines changed

mergekit/architecture/json_definitions.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,7 @@ def _template_substitution(
136136
return TemplateWithArithmetic(template).substitute(substitutions)
137137

138138

139-
def _load_architecture_json(name: str) -> ModelArchitecture:
140-
with importlib.resources.open_text(mergekit._data.architectures, name) as f:
141-
text = f.read()
139+
def _load_architecture_json(text: str) -> ModelArchitecture:
142140
data = json.loads(text)
143141
kind = data.get("kind", "module")
144142
if kind == "modular":
@@ -174,9 +172,10 @@ def _load_all_architectures() -> (
174172
Tuple[List[ModelArchitecture], Dict[str, List[ModelArchitecture]]]
175173
):
176174
architectures: List[ModelArchitecture] = []
177-
for f in importlib.resources.contents(mergekit._data.architectures):
178-
if f.lower().endswith(".json"):
179-
architectures.append(_load_architecture_json(f))
175+
for f in importlib.resources.files(mergekit._data.architectures).iterdir():
176+
if f.is_file() and f.name.lower().endswith(".json"):
177+
text = f.read_text()
178+
architectures.append(_load_architecture_json(text))
180179

181180
name_to_arch: Dict[str, List[JsonModuleArchitecture]] = {}
182181
for arch_info in architectures:

mergekit/merge.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,12 @@ def _set_chat_template(
187187
chat_template = Counter(model_templates).most_common(1)[0][0]
188188
LOG.info(f"Auto-selected chat template: {chat_template}")
189189

190-
elif importlib.resources.is_resource(chat_templates, chat_template + ".jinja"):
191-
with importlib.resources.open_text(
192-
chat_templates, chat_template + ".jinja"
193-
) as fp:
194-
chat_template = fp.read()
190+
elif (
191+
t := importlib.resources.files(chat_templates).joinpath(
192+
chat_template + ".jinja"
193+
)
194+
).is_file():
195+
chat_template = t.read_text()
195196

196197
elif len(chat_template) < 20 or "{" not in chat_template:
197198
raise RuntimeError(f"Invalid chat template: {chat_template}")

pyproject.toml

+2-9
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,11 @@ minversion = "6.0"
8585
filterwarnings = [
8686
"ignore::pydantic.PydanticDeprecatedSince20:huggingface_hub.*:",
8787
"ignore::FutureWarning:huggingface_hub.*:",
88-
"ignore:(read_text|open_text|contents|is_resource) is deprecated:DeprecationWarning", # yes i know, but files() doesn't exist in 3.8
8988
"ignore:Attempting Automatic Merge:UserWarning",
9089
"ignore:No architecture config available:UserWarning",
9190
]
9291
testpaths = ["tests"]
9392

9493
[dependency-groups]
95-
test = [
96-
"pytest~=8.3.5",
97-
]
98-
dev = [
99-
"black~=24.10.0",
100-
"isort~=5.13.2",
101-
"pre-commit~=4.1.0",
102-
]
94+
test = ["pytest~=8.3.5"]
95+
dev = ["black~=24.10.0", "isort~=5.13.2", "pre-commit~=4.1.0"]

0 commit comments

Comments
 (0)