python: don't use importlib as_file for a directory

The only reason to use as_file is to support copying a file from a
frozen package. We don't currently support this anyway, and as_file
isn't supported until Python 3.9, so get rid of it.

Fixes #1605
This commit is contained in:
Jared Van Bortel 2023-12-11 13:35:56 -05:00
parent 1df3da0a88
commit 778264fbab

View File

@ -1,4 +1,3 @@
import atexit
import ctypes import ctypes
import importlib.resources import importlib.resources
import logging import logging
@ -8,20 +7,14 @@ import re
import subprocess import subprocess
import sys import sys
import threading import threading
from contextlib import ExitStack
from queue import Queue from queue import Queue
from typing import Callable, Iterable, List from typing import Callable, Iterable, List
logger: logging.Logger = logging.getLogger(__name__) logger: logging.Logger = logging.getLogger(__name__)
file_manager = ExitStack()
atexit.register(file_manager.close) # clean up files on exit
# TODO: provide a config file to make this more robust # TODO: provide a config file to make this more robust
MODEL_LIB_PATH = file_manager.enter_context(importlib.resources.as_file( MODEL_LIB_PATH = importlib.resources.files("gpt4all") / "llmodel_DO_NOT_MODIFY" / "build"
importlib.resources.files("gpt4all") / "llmodel_DO_NOT_MODIFY" / "build",
))
def load_llmodel_library(): def load_llmodel_library():