Update init.py
Browse files
init.py
CHANGED
|
@@ -15,9 +15,9 @@ st.set_page_config(
|
|
| 15 |
# --------------------------------------------------
|
| 16 |
# Secrets: GitHub Credentials & Repository Name
|
| 17 |
# --------------------------------------------------
|
| 18 |
-
# PRV_REPO: Name of the GitHub repository to clone
|
| 19 |
-
REPO_NAME = st.secrets["PRV_REPO"]
|
| 20 |
-
# The subdirectory inside the cloned repository where your app resides
|
| 21 |
APP_SUBDIR = "private_repo"
|
| 22 |
git_user = st.secrets["GIT_USR"]
|
| 23 |
git_token = st.secrets["GIT_TK"]
|
|
@@ -36,20 +36,29 @@ def clone_repository():
|
|
| 36 |
|
| 37 |
def install_custom_packages():
|
| 38 |
"""
|
| 39 |
-
Install custom Python packages from the 'packages' directory
|
| 40 |
-
|
|
|
|
| 41 |
"""
|
| 42 |
packages_dir = os.path.join(os.getcwd(), "packages")
|
| 43 |
if os.path.exists(packages_dir):
|
| 44 |
print("Installing custom packages...")
|
| 45 |
-
for
|
| 46 |
-
|
| 47 |
-
if os.path.isdir(
|
| 48 |
-
print(f"Installing package: {
|
| 49 |
subprocess.run(
|
| 50 |
-
[sys.executable, "-m", "pip", "install", "-e",
|
| 51 |
check=True
|
| 52 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
else:
|
| 54 |
print("No 'packages' directory found. Skipping custom packages installation.")
|
| 55 |
|
|
@@ -70,26 +79,30 @@ def install_requirements():
|
|
| 70 |
def setup_environment():
|
| 71 |
"""
|
| 72 |
Clone the repository and install dependencies if not already done.
|
| 73 |
-
A marker file (.setup_complete) is
|
| 74 |
"""
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
|
|
|
|
|
|
| 79 |
clone_repository()
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
install_custom_packages()
|
| 85 |
install_requirements()
|
| 86 |
-
# Create the marker file to note that setup is complete.
|
| 87 |
with open(marker, "w") as f:
|
| 88 |
f.write("done")
|
| 89 |
else:
|
| 90 |
-
|
| 91 |
-
os.chdir(REPO_NAME)
|
| 92 |
-
os.chdir(APP_SUBDIR)
|
| 93 |
|
| 94 |
# --------------------------------------------------
|
| 95 |
# Main Loading Process
|
|
@@ -101,11 +114,11 @@ try:
|
|
| 101 |
subprocess.run(["ls", "-l"], shell=True)
|
| 102 |
|
| 103 |
# Import and run the main app.
|
| 104 |
-
# Since your repository contains 'st_app.py'
|
| 105 |
# import main_app from st_app.py.
|
| 106 |
from st_app import main_app
|
| 107 |
main_app()
|
| 108 |
|
| 109 |
except Exception as e:
|
| 110 |
# Log errors to the console (these messages will not display in the UI)
|
| 111 |
-
print("Something went wrong! Error details:", e)
|
|
|
|
| 15 |
# --------------------------------------------------
|
| 16 |
# Secrets: GitHub Credentials & Repository Name
|
| 17 |
# --------------------------------------------------
|
| 18 |
+
# PRV_REPO: Name of the GitHub repository to clone
|
| 19 |
+
REPO_NAME = st.secrets["PRV_REPO"] # e.g. "internal_demo_signal_portfolio"
|
| 20 |
+
# APP_SUBDIR: The subdirectory inside the cloned repository where your app resides.
|
| 21 |
APP_SUBDIR = "private_repo"
|
| 22 |
git_user = st.secrets["GIT_USR"]
|
| 23 |
git_token = st.secrets["GIT_TK"]
|
|
|
|
| 36 |
|
| 37 |
def install_custom_packages():
|
| 38 |
"""
|
| 39 |
+
Install custom Python packages from the 'packages' directory.
|
| 40 |
+
- If an item is a directory, install it in editable mode.
|
| 41 |
+
- If an item is a tar.gz file, install it normally.
|
| 42 |
"""
|
| 43 |
packages_dir = os.path.join(os.getcwd(), "packages")
|
| 44 |
if os.path.exists(packages_dir):
|
| 45 |
print("Installing custom packages...")
|
| 46 |
+
for item in os.listdir(packages_dir):
|
| 47 |
+
item_path = os.path.join(packages_dir, item)
|
| 48 |
+
if os.path.isdir(item_path):
|
| 49 |
+
print(f"Installing package (editable): {item}")
|
| 50 |
subprocess.run(
|
| 51 |
+
[sys.executable, "-m", "pip", "install", "-e", item_path],
|
| 52 |
check=True
|
| 53 |
)
|
| 54 |
+
elif os.path.isfile(item_path) and item.endswith(".tar.gz"):
|
| 55 |
+
print(f"Installing package from tar.gz: {item}")
|
| 56 |
+
subprocess.run(
|
| 57 |
+
[sys.executable, "-m", "pip", "install", item_path],
|
| 58 |
+
check=True
|
| 59 |
+
)
|
| 60 |
+
else:
|
| 61 |
+
print(f"Skipping unknown package format: {item}")
|
| 62 |
else:
|
| 63 |
print("No 'packages' directory found. Skipping custom packages installation.")
|
| 64 |
|
|
|
|
| 79 |
def setup_environment():
|
| 80 |
"""
|
| 81 |
Clone the repository and install dependencies if not already done.
|
| 82 |
+
A marker file (.setup_complete) is stored in the app folder to avoid repeating setup.
|
| 83 |
"""
|
| 84 |
+
# Compute the absolute path to the app folder inside the cloned repository.
|
| 85 |
+
repo_app_path = os.path.join(os.getcwd(), REPO_NAME, APP_SUBDIR)
|
| 86 |
+
marker = os.path.join(repo_app_path, ".setup_complete")
|
| 87 |
+
|
| 88 |
+
# Clone repository if needed.
|
| 89 |
+
if not os.path.exists(REPO_NAME):
|
| 90 |
clone_repository()
|
| 91 |
+
|
| 92 |
+
# Change directory into the repository's app folder.
|
| 93 |
+
if not os.path.exists(repo_app_path):
|
| 94 |
+
raise FileNotFoundError(f"App folder not found: {repo_app_path}")
|
| 95 |
+
os.chdir(repo_app_path)
|
| 96 |
+
|
| 97 |
+
# If the marker file does not exist, run installation steps.
|
| 98 |
+
if not os.path.exists(marker):
|
| 99 |
+
print("Running environment setup in:", repo_app_path)
|
| 100 |
install_custom_packages()
|
| 101 |
install_requirements()
|
|
|
|
| 102 |
with open(marker, "w") as f:
|
| 103 |
f.write("done")
|
| 104 |
else:
|
| 105 |
+
print("Setup already completed. Skipping installation steps.")
|
|
|
|
|
|
|
| 106 |
|
| 107 |
# --------------------------------------------------
|
| 108 |
# Main Loading Process
|
|
|
|
| 114 |
subprocess.run(["ls", "-l"], shell=True)
|
| 115 |
|
| 116 |
# Import and run the main app.
|
| 117 |
+
# Since your repository contains 'st_app.py' in the app folder,
|
| 118 |
# import main_app from st_app.py.
|
| 119 |
from st_app import main_app
|
| 120 |
main_app()
|
| 121 |
|
| 122 |
except Exception as e:
|
| 123 |
# Log errors to the console (these messages will not display in the UI)
|
| 124 |
+
print("Something went wrong! Error details:", e)
|