From 053911b6294dae5547e385ef22e69fbd4ad3b57b Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Mon, 27 Jan 2025 09:07:39 -0800 Subject: [PATCH] Installer: don't ignore .whl requirements if the commit has changed By the user manually switching branches or calling git pull. --- one_click.py | 45 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/one_click.py b/one_click.py index 54e29501..e1b2be53 100644 --- a/one_click.py +++ b/one_click.py @@ -1,6 +1,7 @@ import argparse import glob import hashlib +import json import os import platform import re @@ -148,6 +149,11 @@ def check_env(): sys.exit(1) +def get_current_commit(): + result = run_cmd("git rev-parse HEAD", capture_output=True, environment=True) + return result.stdout.decode('utf-8').strip() + + def clear_cache(): run_cmd("conda clean -a -y", environment=True) run_cmd("python -m pip cache purge", environment=True) @@ -351,10 +357,21 @@ def update_requirements(initial_installation=False, pull=True): else: requirements_file = "requirements" + ("_noavx2" if not cpu_has_avx2() else "") + ".txt" - # Check and clear the wheels changed flag - wheels_changed = os.path.exists('.wheels_changed_flag') - if wheels_changed: - os.remove('.wheels_changed_flag') + # Load state from JSON file + state_file = '.installer_state.json' + wheels_changed = False + if os.path.exists(state_file): + with open(state_file, 'r') as f: + last_state = json.load(f) + + wheels_changed = last_state.get('wheels_changed', False) + else: + last_state = {} + + # Check wheels changed from state file and commit differences + current_commit = get_current_commit() + if last_state.get('last_commit') != current_commit: + wheels_changed = True if pull: # Read .whl lines before pulling @@ -387,12 +404,30 @@ def update_requirements(initial_installation=False, pull=True): if before_hashes[file] != after_hashes[file]: print_big_message(f"File '{file}' was updated during 'git pull'. Please run the script again.") if before_pull_whl_lines != after_pull_whl_lines: - open('.wheels_changed_flag', 'w').close() + wheels_changed = True + + # Save state before exiting + current_state = { + 'last_commit': current_commit, + 'wheels_changed': wheels_changed + } + + with open(state_file, 'w') as f: + json.dump(current_state, f) exit(1) wheels_changed = wheels_changed or (before_pull_whl_lines != after_pull_whl_lines) + # Save current state + current_state = { + 'last_commit': current_commit, + 'wheels_changed': wheels_changed + } + + with open(state_file, 'w') as f: + json.dump(current_state, f) + if os.environ.get("INSTALL_EXTENSIONS", "").lower() in ("yes", "y", "true", "1", "t", "on"): install_extensions_requirements()