mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-09 07:16:04 +00:00
chore: fix imports
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import importlib
|
||||
import importlib.util
|
||||
import importlib.resources
|
||||
import os
|
||||
import typing
|
||||
|
||||
@@ -25,7 +25,7 @@ def import_dot_style_dir(dot_sep_path: str):
|
||||
return import_dir(os.path.join(*sec))
|
||||
|
||||
|
||||
def import_dir(path: str):
|
||||
def import_dir(path: str, path_prefix: str = 'langbot.'):
|
||||
for file in os.listdir(path):
|
||||
if file.endswith('.py') and file != '__init__.py':
|
||||
full_path = os.path.join(path, file)
|
||||
@@ -33,10 +33,13 @@ def import_dir(path: str):
|
||||
rel_path = rel_path[1:]
|
||||
rel_path = rel_path.replace('/', '.')[:-3]
|
||||
rel_path = rel_path.replace('\\', '.')
|
||||
importlib.import_module(rel_path)
|
||||
importlib.import_module(f'{path_prefix}{rel_path}')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from pkg.platform import types
|
||||
def read_resource_file(resource_path: str) -> str:
|
||||
with importlib.resources.files('langbot').joinpath(resource_path).open('r', encoding='utf-8') as f:
|
||||
return f.read()
|
||||
|
||||
import_modules_in_pkg(types)
|
||||
|
||||
def list_resource_files(resource_path: str) -> list[str]:
|
||||
return [f.name for f in importlib.resources.files('langbot').joinpath(resource_path).iterdir()]
|
||||
|
||||
Reference in New Issue
Block a user