Return `Path` from `_get_mod_abspath()` helper fn

repl_fixture
Tyler Goodlet 2025-05-14 20:26:15 -04:00
parent 006ee0752c
commit 5024e71d8e
1 changed files with 7 additions and 4 deletions

View File

@ -44,6 +44,7 @@ from functools import partial
import importlib import importlib
import importlib.util import importlib.util
import os import os
from pathlib import Path
from pprint import pformat from pprint import pformat
import signal import signal
import sys import sys
@ -111,8 +112,8 @@ if TYPE_CHECKING:
log = get_logger('tractor') log = get_logger('tractor')
def _get_mod_abspath(module): def _get_mod_abspath(module: ModuleType) -> Path:
return os.path.abspath(module.__file__) return Path(module.__file__).absolute()
def get_mod_nsps2fps(mod_ns_paths: list[str]) -> dict[str, str]: def get_mod_nsps2fps(mod_ns_paths: list[str]) -> dict[str, str]:
@ -124,7 +125,7 @@ def get_mod_nsps2fps(mod_ns_paths: list[str]) -> dict[str, str]:
nsp2fp: dict[str, str] = {} nsp2fp: dict[str, str] = {}
for nsp in mod_ns_paths: for nsp in mod_ns_paths:
mod: ModuleType = importlib.import_module(nsp) mod: ModuleType = importlib.import_module(nsp)
nsp2fp[nsp] = _get_mod_abspath(mod) nsp2fp[nsp] = str(_get_mod_abspath(mod))
return nsp2fp return nsp2fp
@ -406,7 +407,6 @@ class Actor:
def load_modules( def load_modules(
self, self,
# debug_mode: bool = False,
) -> None: ) -> None:
''' '''
Load explicitly enabled python modules from local fs after Load explicitly enabled python modules from local fs after
@ -428,6 +428,9 @@ class Actor:
parent_data['init_main_from_path']) parent_data['init_main_from_path'])
status: str = 'Attempting to import enabled modules:\n' status: str = 'Attempting to import enabled modules:\n'
modpath: str
filepath: str
for modpath, filepath in self.enable_modules.items(): for modpath, filepath in self.enable_modules.items():
# XXX append the allowed module to the python path which # XXX append the allowed module to the python path which
# should allow for relative (at least downward) imports. # should allow for relative (at least downward) imports.