Compare commits
2 Commits
a956c745ea
...
17250b7615
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
17250b7615 | ||
|
|
b70c0bf466 |
@@ -143,13 +143,14 @@ RUN chmod -R 755 /app && \
|
|||||||
chmod -R 777 /app/data /app/logs /app/uploaded_files
|
chmod -R 777 /app/data /app/logs /app/uploaded_files
|
||||||
|
|
||||||
# Environment variables
|
# Environment variables
|
||||||
# PYTHONPATH=/app allows importing peikarband from /app/peikarband/
|
# PYTHONPATH includes both /app and /app/peikarband
|
||||||
# which makes peikarband.peikarband available from /app/peikarband/peikarband/
|
# - /app: allows importing peikarband from /app/peikarband/
|
||||||
# Note: Current directory (.) is added to sys.path, but PYTHONPATH entries come first
|
# - /app/peikarband: allows importing src from /app/peikarband/src/
|
||||||
|
# This makes both peikarband.peikarband and src.* imports work correctly
|
||||||
# REFLEX_DIR points to the directory containing rxconfig.py
|
# REFLEX_DIR points to the directory containing rxconfig.py
|
||||||
ENV PYTHONUNBUFFERED=1 \
|
ENV PYTHONUNBUFFERED=1 \
|
||||||
PYTHONDONTWRITEBYTECODE=1 \
|
PYTHONDONTWRITEBYTECODE=1 \
|
||||||
PYTHONPATH=/app \
|
PYTHONPATH=/app:/app/peikarband \
|
||||||
PATH="/app/.venv/bin:$PATH" \
|
PATH="/app/.venv/bin:$PATH" \
|
||||||
REFLEX_DIR=/app/peikarband \
|
REFLEX_DIR=/app/peikarband \
|
||||||
NODE_ENV=production
|
NODE_ENV=production
|
||||||
|
|||||||
@@ -1,86 +1,6 @@
|
|||||||
"""Peikarband Landing Application Package.
|
"""Peikarband Landing Application Package.
|
||||||
|
|
||||||
This package exports the Reflex app instance.
|
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__ = []
|
__all__ = []
|
||||||
|
|
||||||
|
|||||||
@@ -1,43 +1,8 @@
|
|||||||
"""Peikarband submodule for Reflex compatibility.
|
"""Peikarband submodule for Reflex compatibility.
|
||||||
|
|
||||||
Reflex expects to find 'app' in peikarband.peikarband when app_name='peikarband'.
|
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
|
from ..app import app
|
||||||
# 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
|
|
||||||
|
|
||||||
__all__ = ["app"]
|
__all__ = ["app"]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user