hash dirpath for sys modules

This commit is contained in:
Jakub Trllo 2025-07-25 17:03:37 +02:00
parent 1bdd64ae3d
commit c398e1fca3

View file

@ -5,6 +5,7 @@ import sys
import inspect import inspect
import copy import copy
import warnings import warnings
import hashlib
import xml.etree.ElementTree import xml.etree.ElementTree
from typing import TYPE_CHECKING, Optional, Union, List from typing import TYPE_CHECKING, Optional, Union, List
@ -257,15 +258,18 @@ def publish_plugins_discover(
filenames.append(os.path.basename(path)) filenames.append(os.path.basename(path))
path = os.path.dirname(path) path = os.path.dirname(path)
dirpath_hash = hashlib.md5(path.encode("utf-8")).hexdigest()
for filename in filenames: for filename in filenames:
mod_name, mod_ext = os.path.splitext(filename) mod_name, mod_ext = os.path.splitext(filename)
if mod_ext.lower() != ".py": if mod_ext.lower() != ".py":
continue continue
filepath = os.path.join(path, filename) filepath = os.path.join(path, filename)
sys_module_name = f"{dirpath_hash}.{mod_name}"
try: try:
module = import_filepath( module = import_filepath(
filepath, mod_name, sys_module_name=mod_name filepath, mod_name, sys_module_name=sys_module_name
)
except Exception as err: # noqa: BLE001 except Exception as err: # noqa: BLE001
# we need broad exception to catch all possible errors. # we need broad exception to catch all possible errors.