From d681b993e220b82863af14b070417cb3cc011b2c Mon Sep 17 00:00:00 2001 From: ZJaume Date: Tue, 29 Oct 2024 15:40:43 +0000 Subject: [PATCH] Need --force to binarize model if already exists --- src/cli.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/cli.rs b/src/cli.rs index b04418d..f1419a3 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -3,12 +3,13 @@ use std::fs::{copy, File}; use std::path::{Path, PathBuf}; use std::str::FromStr; use std::env; +use std::process::exit; use anyhow::{Context, Result}; use clap::{Parser, Subcommand, Args}; use itertools::Itertools; use pyo3::prelude::*; -use log::{info, debug}; +use log::{error, warn, info, debug}; use env_logger::Env; use strum::IntoEnumIterator; use target; @@ -43,6 +44,8 @@ struct BinarizeCmd { input_dir: Option, #[arg(help="Output directory to place the binary files")] output_dir: Option, + #[arg(short, long, help="Force overwrite of output files if they already exist")] + force: bool, } impl BinarizeCmd { @@ -50,6 +53,19 @@ impl BinarizeCmd { let model_path = self.input_dir.unwrap_or(PathBuf::from("./LanguageModels")); let save_path = self.output_dir.unwrap_or(module_path().unwrap()); + // Fail and warn the use if there is already a model + if !self.force && + save_path.join( + format!("{}.bin", OrderNgram::Word.to_string()) + ).exists() + { + warn!("Binarized models are now included in the PyPi package, \ + there is no need to binarize the model unless you are training a new one" + ); + error!("Output model already exists, use '-f' to force overwrite"); + exit(1); + } + for model_type in OrderNgram::iter() { let type_repr = model_type.to_string(); info!("Loading {type_repr} model");