From faba77f2b783e88b584402eda8fa371d522425a4 Mon Sep 17 00:00:00 2001 From: David Allada Date: Sun, 23 Mar 2025 16:57:34 +0000 Subject: [PATCH 1/3] Create general function to write the start options --- start.py | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/start.py b/start.py index 619b07eb..f78f9b21 100644 --- a/start.py +++ b/start.py @@ -158,6 +158,22 @@ def migrate_gpu_lib(): "The old file has been deleted." ) +def write_start_options_if_first_run(first_run, start_options): + # First run options + if first_run: + start_options["first_run_done"] = True + + # Save start options + with open("start_options.json", "w") as start_file: + start_file.write(json.dumps(start_options)) + + print( + "Successfully wrote your start script options to " + "`start_options.json`. \n" + "If something goes wrong, editing or deleting the file " + "will reinstall TabbyAPI as a first-time user." + ) + if __name__ == "__main__": subprocess.run(["pip", "-V"]) @@ -236,21 +252,11 @@ def migrate_gpu_lib(): subprocess.run(install_command) print() - if first_run: - start_options["first_run_done"] = True - - # Save start options on first run - with open("start_options.json", "w") as start_file: - start_file.write(json.dumps(start_options)) - - print( - "Successfully wrote your start script options to " - "`start_options.json`. \n" - "If something goes wrong, editing or deleting the file " - "will reinstall TabbyAPI as a first-time user." - ) - if args.update_deps: + # If the update_deps command is run on the first_run (like building in a docker container) + # Then write the start_options to avoid re-running + write_start_options_if_first_run(first_run, start_options) + print( f"Dependencies updated. Please run TabbyAPI with `start.{script_ext}`. " "Exiting." @@ -262,6 +268,9 @@ def migrate_gpu_lib(): "inside the `update_scripts` folder." ) + # Write the start_options to a file on the first run to save them for subsequent runs + write_start_options_if_first_run(first_run, start_options) + # Expand the parser if it's not fully created if not has_full_parser: from common.args import init_argparser @@ -296,4 +305,4 @@ def migrate_gpu_lib(): "This error was raised because a package was not found.\n" "Update your dependencies by running update_scripts/" f"update_deps.{'bat' if platform.system() == 'Windows' else 'sh'}\n\n" - ) + ) \ No newline at end of file From 2d904e08c51e525f21fc7f6113ffdf97753a04c6 Mon Sep 17 00:00:00 2001 From: David Allada Date: Sun, 23 Mar 2025 17:05:10 +0000 Subject: [PATCH 2/3] Fix ruff formatting --- start.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/start.py b/start.py index f78f9b21..d22de517 100644 --- a/start.py +++ b/start.py @@ -158,6 +158,7 @@ def migrate_gpu_lib(): "The old file has been deleted." ) + def write_start_options_if_first_run(first_run, start_options): # First run options if first_run: @@ -305,4 +306,4 @@ def write_start_options_if_first_run(first_run, start_options): "This error was raised because a package was not found.\n" "Update your dependencies by running update_scripts/" f"update_deps.{'bat' if platform.system() == 'Windows' else 'sh'}\n\n" - ) \ No newline at end of file + ) From 7b10423344efc248d5a8c16a6f495fd26566cee9 Mon Sep 17 00:00:00 2001 From: David Allada Date: Tue, 22 Apr 2025 20:57:29 -0400 Subject: [PATCH 3/3] Fix the ruff errors --- start.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/start.py b/start.py index d22de517..909c47d4 100644 --- a/start.py +++ b/start.py @@ -254,8 +254,9 @@ def write_start_options_if_first_run(first_run, start_options): print() if args.update_deps: - # If the update_deps command is run on the first_run (like building in a docker container) - # Then write the start_options to avoid re-running + # If the update_deps command is run on the first_run (like building + # in a docker container). Then write the start_options to + # avoid re-running write_start_options_if_first_run(first_run, start_options) print( @@ -269,7 +270,8 @@ def write_start_options_if_first_run(first_run, start_options): "inside the `update_scripts` folder." ) - # Write the start_options to a file on the first run to save them for subsequent runs + # Write the start_options to a file on the first run to save them for + # subsequent runs write_start_options_if_first_run(first_run, start_options) # Expand the parser if it's not fully created