diff --git a/peikarband/__init__.py b/peikarband/__init__.py index 6249c0c..a1a3a68 100644 --- a/peikarband/__init__.py +++ b/peikarband/__init__.py @@ -18,18 +18,30 @@ except: pass # Register peikarband.peikarband submodule in sys.modules # This is necessary when running from /app/peikarband directory -# We use a simple approach: find peikarband/peikarband/__init__.py using current working directory -# This works because in Docker, WORKDIR is /app/peikarband +# We need to find peikarband/peikarband/__init__.py relative to this __init__.py file try: import importlib.util - # Use current working directory as the base (should be /app/peikarband in Docker) - _cwd = os.getcwd() - _peikarband_submodule_path = os.path.join(_cwd, 'peikarband', '__init__.py') + # Get the directory containing this __init__.py file + # __file__ might be peikarband/__init__.py or peikarband/./peikarband/__init__.py + _this_dir = os.path.dirname(os.path.abspath(__file__)) - # If not found, try relative to __file__ - if not os.path.exists(_peikarband_submodule_path): - _this_dir = os.path.dirname(os.path.abspath(__file__)) - _peikarband_submodule_path = os.path.join(_this_dir, 'peikarband', '__init__.py') + # If we're in peikarband/peikarband/__init__.py, go up one level + # If we're in peikarband/__init__.py, use current directory + if os.path.basename(_this_dir) == 'peikarband': + # Check if parent is also peikarband (we're in peikarband/peikarband/__init__.py) + _parent_dir = os.path.dirname(_this_dir) + if os.path.basename(_parent_dir) == 'peikarband': + # We're in peikarband/peikarband/__init__.py, use parent + _peikarband_dir = _parent_dir + else: + # We're in peikarband/__init__.py, use current directory + _peikarband_dir = _this_dir + else: + # Fallback: use current directory + _peikarband_dir = os.getcwd() + + # Look for peikarband/peikarband/__init__.py + _peikarband_submodule_path = os.path.join(_peikarband_dir, 'peikarband', '__init__.py') if os.path.exists(_peikarband_submodule_path): _spec = importlib.util.spec_from_file_location("peikarband.peikarband", _peikarband_submodule_path)