[DEPLOYMENT-001] Simplify __init__.py files and fix PYTHONPATH (fix) | ApprovalToken: AT-202512310729
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

This commit is contained in:
Ehsan.Asadi
2025-12-31 07:29:31 +03:30
parent b70c0bf466
commit 17250b7615
2 changed files with 1 additions and 116 deletions

View File

@@ -1,86 +1,6 @@
"""Peikarband Landing Application Package.
This package exports the Reflex app instance.
The peikarband.peikarband submodule is provided by peikarband/peikarband/__init__.py
"""
import sys
import os
import json
# #region agent log
_log_path = "/home/ehsan.asadi@zoodfood.ir/Projects/my/business/peikarband/landing/.cursor/debug.log"
try:
with open(_log_path, "a") as f:
f.write(json.dumps({"sessionId":"debug-session","runId":"run1","hypothesisId":"A","location":"peikarband/__init__.py:10","message":"peikarband/__init__.py started","data":{"__file__":__file__,"cwd":os.getcwd(),"pythonpath":os.getenv("PYTHONPATH","")},"timestamp":int(os.path.getmtime(__file__)*1000) if os.path.exists(__file__) else 0})+"\n")
except: pass
# #endregion
# Register peikarband.peikarband submodule in sys.modules
# This is necessary when running from /app/peikarband directory
# We need to find peikarband/peikarband/__init__.py relative to this __init__.py file
try:
import importlib.util
# 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 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')
# #region agent log
try:
with open(_log_path, "a") as f:
f.write(json.dumps({"sessionId":"debug-session","runId":"run1","hypothesisId":"A","location":"peikarband/__init__.py:45","message":"Trying to register peikarband.peikarband","data":{"_peikarband_dir":_peikarband_dir,"_peikarband_submodule_path":_peikarband_submodule_path,"exists":os.path.exists(_peikarband_submodule_path)},"timestamp":int(os.path.getmtime(__file__)*1000) if os.path.exists(__file__) else 0})+"\n")
except: pass
# #endregion
if os.path.exists(_peikarband_submodule_path):
_spec = importlib.util.spec_from_file_location("peikarband.peikarband", _peikarband_submodule_path)
if _spec and _spec.loader:
_peikarband_module = importlib.util.module_from_spec(_spec)
# Register in sys.modules BEFORE exec_module
sys.modules["peikarband.peikarband"] = _peikarband_module
# #region agent log
try:
with open(_log_path, "a") as f:
f.write(json.dumps({"sessionId":"debug-session","runId":"run1","hypothesisId":"A","location":"peikarband/__init__.py:55","message":"Before exec_module","data":{"registered":"peikarband.peikarband" in sys.modules},"timestamp":int(os.path.getmtime(__file__)*1000) if os.path.exists(__file__) else 0})+"\n")
except: pass
# #endregion
_spec.loader.exec_module(_peikarband_module)
# #region agent log
try:
with open(_log_path, "a") as f:
f.write(json.dumps({"sessionId":"debug-session","runId":"run1","hypothesisId":"A","location":"peikarband/__init__.py:60","message":"After exec_module","data":{"has_app":hasattr(_peikarband_module,"app"),"in_sys_modules":"peikarband.peikarband" in sys.modules},"timestamp":int(os.path.getmtime(__file__)*1000) if os.path.exists(__file__) else 0})+"\n")
except: pass
# #endregion
except Exception as e:
# #region agent log
try:
with open(_log_path, "a") as f:
f.write(json.dumps({"sessionId":"debug-session","runId":"run1","hypothesisId":"A","location":"peikarband/__init__.py:65","message":"Exception during registration","data":{"error":str(e),"error_type":type(e).__name__},"timestamp":int(os.path.getmtime(__file__)*1000) if os.path.exists(__file__) else 0})+"\n")
except: pass
# #endregion
# Silently fail - if we can't register it, Python will try to import it normally
pass
__all__ = []

View File

@@ -1,43 +1,8 @@
"""Peikarband submodule for Reflex compatibility.
Reflex expects to find 'app' in peikarband.peikarband when app_name='peikarband'.
This submodule provides that structure.
"""
# Import app from parent package's app.py
# We use importlib to directly load app.py, which works regardless of working directory
# This is necessary because when Reflex runs from /app/peikarband, Python cannot
# find the peikarband package using normal imports
import importlib.util
import os
import sys
# Register this module in sys.modules so Python can find peikarband.peikarband
# This is critical when running from /app/peikarband directory
_current_module = sys.modules[__name__]
_parent_package_name = __name__.rsplit('.', 1)[0] # 'peikarband' from 'peikarband.peikarband'
if _parent_package_name not in sys.modules:
# If peikarband package is not in sys.modules, we need to create it
import types
_parent_package = types.ModuleType(_parent_package_name)
sys.modules[_parent_package_name] = _parent_package
_parent_package.__path__ = [os.path.dirname(os.path.dirname(os.path.abspath(__file__)))]
_parent_package.__file__ = os.path.join(_parent_package.__path__[0], '__init__.py')
# Get the parent directory (peikarband/) and load app.py directly
_parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
_app_file = os.path.join(_parent_dir, 'app.py')
# Load app.py as a module
_spec = importlib.util.spec_from_file_location("peikarband.app", _app_file)
_app_module = importlib.util.module_from_spec(_spec)
# Register the module in sys.modules so it can be imported elsewhere
sys.modules["peikarband.app"] = _app_module
_spec.loader.exec_module(_app_module)
# Get the app from the loaded module
app = _app_module.app
from ..app import app
__all__ = ["app"]