From 53e3d26be08acb7c079b9fba789e1c625ea0f738 Mon Sep 17 00:00:00 2001 From: Mohsin Khan Date: Thu, 18 Sep 2025 14:04:37 +0530 Subject: [PATCH 1/4] Fix: Windows support for lore server by using subprocess.run --- lore/__main__.py | 7 +++++++ lore/env.py | 23 +++++++++++++++-------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/lore/__main__.py b/lore/__main__.py index a8cdf18..473ba5f 100644 --- a/lore/__main__.py +++ b/lore/__main__.py @@ -21,7 +21,14 @@ import lore from lore import ansi, env, util + + from lore.util import timer, which +if platform.system() == "Windows": + subprocess.run([env.BIN_FLASK] + sys.argv[1:], shell=True) +else: + os.execv(env.BIN_FLASK, args) + logger = logging.getLogger(__name__) diff --git a/lore/env.py b/lore/env.py index 3403a56..45a5374 100644 --- a/lore/env.py +++ b/lore/env.py @@ -24,11 +24,9 @@ import glob import locale -import os import re import socket import subprocess -import sys import platform from io import open @@ -36,6 +34,14 @@ from lore import ansi +import os +import sys +import subprocess +# Determine the path to flask.exe depending on OS +if sys.platform == "win32": + BIN_FLASK = os.path.normpath(os.path.join(os.getcwd(), ".venv", "Scripts", "flask.exe")) +else: + BIN_FLASK = os.path.join(os.getcwd(), ".venv", "bin", "flask") # -- Python 2/3 Compatability ------------------------------------------------ @@ -170,10 +176,8 @@ def validate(): ) ) - def launch(): - """Ensure that python is running from the Lore virtualenv past this point. - """ + """Ensure that python is running from the Lore virtualenv past this point.""" if launched(): check_version() os.chdir(ROOT) @@ -188,8 +192,11 @@ def launch(): import lore.__main__ lore.__main__.install(None, None) - reboot('--env-launched') - + # Windows-safe call + if platform.system() == "Windows": + subprocess.run([BIN_FLASK] + sys.argv[1:], shell=True) + else: + os.execv(BIN_FLASK, sys.argv) def reboot(*args): """Reboot python in the Lore virtualenv @@ -285,7 +292,7 @@ def get_config(path): conf = open(path, 'rt').read() conf = os.path.expandvars(conf) - config = configparser.SafeConfigParser() + config = configparser.ConfigParser() if sys.version_info[0] == 2: from io import StringIO config.readfp(StringIO(unicode(conf))) From a845ee105441ab6ac11b803e13d0d37280af2998 Mon Sep 17 00:00:00 2001 From: Mohsin Khan Date: Fri, 19 Sep 2025 12:19:19 +0530 Subject: [PATCH 2/4] Add DAG to automate model training --- lore/dags/model_training_dag.py | 51 +++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 lore/dags/model_training_dag.py diff --git a/lore/dags/model_training_dag.py b/lore/dags/model_training_dag.py new file mode 100644 index 0000000..265111e --- /dev/null +++ b/lore/dags/model_training_dag.py @@ -0,0 +1,51 @@ +from airflow import DAG +from airflow.operators.python import PythonOperator +from datetime import datetime, timedelta +import subprocess +import sys +import os + +# Path to your Lore repo +LORE_PATH = r"C:\MY WORK\open-source\lore" + +# Default args for DAG +default_args = { + 'owner': 'mohsinkhan85090', + 'depends_on_past': False, + 'email_on_failure': False, + 'email_on_retry': False, + 'retries': 1, + 'retry_delay': timedelta(minutes=5), +} + +# Task 1: Train model +def train_model(): + # Run the main script (adjust if your training function is elsewhere) + subprocess.run([sys.executable, os.path.join(LORE_PATH, 'lore', '__main__.py'), 'train'], check=True) + +# Task 2: Evaluate model +def evaluate_model(): + subprocess.run([sys.executable, os.path.join(LORE_PATH, 'lore', '__main__.py'), 'evaluate'], check=True) + +# Define DAG +with DAG( + 'lore_model_training', + default_args=default_args, + description='Automate Lore model training using Airflow', + schedule_interval='@daily', + start_date=datetime(2025, 9, 19), + catchup=False +) as dag: + + train_task = PythonOperator( + task_id='train_model', + python_callable=train_model + ) + + evaluate_task = PythonOperator( + task_id='evaluate_model', + python_callable=evaluate_model + ) + + # Task dependencies + train_task >> evaluate_task From 55bf8fbecb8e98dd213ba8553d3e6f59f01472bb Mon Sep 17 00:00:00 2001 From: Mohsin Khan Date: Fri, 19 Sep 2025 12:33:23 +0530 Subject: [PATCH 3/4] Add DAG to automate model training --- {lore/dags => dags}/model_training_dag.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {lore/dags => dags}/model_training_dag.py (100%) diff --git a/lore/dags/model_training_dag.py b/dags/model_training_dag.py similarity index 100% rename from lore/dags/model_training_dag.py rename to dags/model_training_dag.py From 9bd9f8d8f1a03a3c3c3020cff05ba568cb50ddf9 Mon Sep 17 00:00:00 2001 From: Mohsin Khan Date: Fri, 19 Sep 2025 13:11:00 +0530 Subject: [PATCH 4/4] Fix Windows support and update requirements --- lore/util.py | 44 +++++++++++++++++++++----------------------- requirements.txt | 10 +++++++++- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/lore/util.py b/lore/util.py index cb6af65..c70bc67 100644 --- a/lore/util.py +++ b/lore/util.py @@ -338,34 +338,32 @@ def report_exception(exc_type=None, value=None, tb=None): sys.excepthook = report_exception # Librato +import os +import threading + +_librato = None +_librato_aggregator = None +_librato_timer = None +_librato_start = None +_librato_lock = threading.RLock() + +# Only connect to Librato if both env variables are present +LIBRATO_USER = os.getenv('LIBRATO_USER') +LIBRATO_TOKEN = os.getenv('LIBRATO_TOKEN') + +if LIBRATO_USER and LIBRATO_TOKEN: try: import librato from librato.aggregator import Aggregator - - # client side aggregation - LIBRATO_MIN_AGGREGATION_PERIOD = 5 - LIBRATO_MAX_AGGREGATION_PERIOD = 60 - + _librato = librato.connect(LIBRATO_USER, LIBRATO_TOKEN) + logger.info('Connected to Librato with user: %s' % LIBRATO_USER) + except Exception as e: _librato = None - if os.getenv('LIBRATO_USER'): - try: - _librato = librato.connect(os.getenv('LIBRATO_USER'), os.getenv('LIBRATO_TOKEN')) - _librato_aggregator = None - _librato_timer = None - _librato_start = None - _librato_lock = threading.RLock() - logger.info('connected to librato with user: %s' % os.getenv('LIBRATO_USER')) - except: - logger.exception('unable to start librato') - report_exception() - _librato = None - else: - logger.warning('librato variables not found') - - except env.ModuleNotFoundError: - pass - + logger.warning('Could not connect to Librato: %s' % str(e)) +else: + logger.warning('Librato environment variables not found') + def librato_record(name, value): global _librato, _librato_lock, _librato_aggregator, _librato_timer, _librato_start diff --git a/requirements.txt b/requirements.txt index d6e1198..d4d3bab 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,9 @@ --e . +click==8.2.1 +colorama==0.4.6 +Flask==0.12.5 +itsdangerous==2.2.0 +Jinja2==3.1.6 +MarkupSafe==3.0.2 +Werkzeug==0.16.1 +-e . +