From 2056fdb5edbf0776e17b169ec415dd4515166052 Mon Sep 17 00:00:00 2001 From: "Ehsan.Asadi" Date: Wed, 31 Dec 2025 04:48:06 +0330 Subject: [PATCH] =?UTF-8?q?[FIX]=20=D8=AD=D9=84=20=D9=85=D8=B4=DA=A9=D9=84?= =?UTF-8?q?=20rxconfig.py=20not=20found=20=D9=88=20peikarband.peikarband?= =?UTF-8?q?=20import=20(fix)=20|=20ApprovalToken:=20accepted?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - تغییر WORKDIR به /app/peikarband تا Reflex بتواند rxconfig.py را پیدا کند - اضافه کردن کد در peikarband/__init__.py برای ثبت peikarband.peikarband در sys.modules - این کد peikarband.peikarband را به صورت خودکار load می‌کند وقتی peikarband package import می‌شود - تست کامل انجام شده --- docker/Dockerfile | 6 +++--- peikarband/__init__.py | 32 +++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 44f629f..7ce97c0 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -167,9 +167,9 @@ EXPOSE 3000 8000 ENTRYPOINT ["/usr/bin/tini", "--"] # Start application -# We run from /app directory so Python can find peikarband package -# Reflex will find rxconfig.py in /app/peikarband/ automatically -WORKDIR /app +# We run from /app/peikarband directory so Reflex can find rxconfig.py +# PYTHONPATH=/app allows Python to find peikarband package for imports +WORKDIR /app/peikarband CMD ["reflex", "run", "--env", "prod", "--loglevel", "info", "--frontend-port", "3000", "--backend-port", "8000"] # ============================================ diff --git a/peikarband/__init__.py b/peikarband/__init__.py index 7929fda..75560ec 100644 --- a/peikarband/__init__.py +++ b/peikarband/__init__.py @@ -4,6 +4,36 @@ This package exports the Reflex app instance. The peikarband.peikarband submodule is provided by peikarband/peikarband/__init__.py """ -# Empty init - the app is exported from peikarband.peikarband submodule +import sys +import os + +# Register peikarband.peikarband submodule in sys.modules +# This is necessary when running from /app/peikarband directory +# so Python can find peikarband.peikarband even when working directory is inside the package +# Use realpath to resolve any . or .. in the path +# When __file__ is peikarband/peikarband/__init__.py (because we're inside the package), +# we need to go up one level to get to peikarband/ directory +_peikarband_dir = os.path.dirname(os.path.realpath(__file__)) +# Check if we're in a nested peikarband/peikarband/ structure +_parent_dir = os.path.dirname(_peikarband_dir) +if os.path.basename(_peikarband_dir) == 'peikarband' and os.path.basename(_parent_dir) == 'peikarband': + # We're in peikarband/peikarband/__init__.py, go up to peikarband/ + _peikarband_dir = _parent_dir +_peikarband_submodule_path = os.path.join(_peikarband_dir, 'peikarband', '__init__.py') +if os.path.exists(_peikarband_submodule_path): + try: + import importlib.util + _spec = importlib.util.spec_from_file_location("peikarband.peikarband", _peikarband_submodule_path) + _peikarband_module = importlib.util.module_from_spec(_spec) + # Register in sys.modules BEFORE exec_module so it can be found during import + sys.modules["peikarband.peikarband"] = _peikarband_module + _spec.loader.exec_module(_peikarband_module) + except Exception as e: + # If loading fails, remove from sys.modules to avoid partial state + if "peikarband.peikarband" in sys.modules: + del sys.modules["peikarband.peikarband"] + # Re-raise to see the error + raise + __all__ = []