Skip to content

Commit

Permalink
Fixing icu_datagen no-download path (#3446)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertbastian authored May 23, 2023
1 parent 5436b31 commit d8cc2f3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
6 changes: 2 additions & 4 deletions provider/datagen/src/bin/datagen/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,21 +121,19 @@ pub struct Cli {
icuexport_tag: String,

#[arg(long, value_name = "PATH")]
#[cfg_attr(not(feature = "networking"), arg(default_value = "builtin"))]
#[arg(
help = "Path to a local icuexport directory (see https://github.com/unicode-org/icu/releases).\n\
Note that some keys do not support versions before release-71-1."
)]
icuexport_root: Option<PathBuf>,

#[arg(long, value_name = "TAG")]
#[arg(long, value_name = "TAG", default_value = "latest")]
#[arg(
help = "Download segmentation LSTM models from this GitHub tag (https://github.com/unicode-org/lstm_word_segmentation/tags)\n\
Use 'latest' for the latest version verified to work with this version of the binary.\n\
Ignored if '--segmenter-lstm-root' is present. Requires binary to be built with `networking` Cargo feature (enabled by default)."
)]
#[cfg_attr(not(feature = "networking"), arg(hide = true))]
#[cfg_attr(feature = "networking", arg(default_value = "latest"))]
segmenter_lstm_tag: String,

#[arg(long, value_name = "PATH")]
Expand Down Expand Up @@ -333,7 +331,7 @@ impl Cli {
#[cfg(feature = "networking")]
(_, tag) => config::PathOrTag::Tag(String::from(tag)),
#[cfg(not(feature = "networking"))]
_ => eyre::bail!("--{root_arg} flag is mandatory unless datagen is built with the `\"networking\"` Cargo feature"),
_ => config::PathOrTag::None,
})
}

Expand Down
2 changes: 2 additions & 0 deletions provider/datagen/src/bin/datagen/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ pub enum PathOrTag {
Tag(String),
#[cfg(feature = "networking")]
Latest,
#[cfg(not(feature = "networking"))]
None,
}

#[derive(Debug, serde::Serialize, serde::Deserialize, PartialEq)]
Expand Down
7 changes: 6 additions & 1 deletion provider/datagen/src/bin/datagen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ fn main() -> eyre::Result<()> {
}
#[cfg(feature = "networking")]
config::PathOrTag::Tag(tag) => source_data.with_cldr_for_tag(&tag, Default::default())?,
#[cfg(not(feature = "networking"))]
config::PathOrTag::None => source_data,
};

source_data = match config.icu_export {
Expand All @@ -62,17 +64,20 @@ fn main() -> eyre::Result<()> {
}
#[cfg(feature = "networking")]
config::PathOrTag::Tag(tag) => source_data.with_icuexport_for_tag(&tag)?,
#[cfg(not(feature = "networking"))]
config::PathOrTag::None => source_data,
};

source_data = match config.segmenter_lstm {
config::PathOrTag::Path(path) if path.as_os_str() == "builtin" => source_data,
config::PathOrTag::Path(path) => source_data.with_icuexport(path)?,
#[cfg(feature = "networking")]
config::PathOrTag::Latest => {
source_data.with_segmenter_lstm_for_tag(SourceData::LATEST_TESTED_SEGMENTER_LSTM_TAG)?
}
#[cfg(feature = "networking")]
config::PathOrTag::Tag(tag) => source_data.with_segmenter_lstm_for_tag(&tag)?,
#[cfg(not(feature = "networking"))]
config::PathOrTag::None => source_data,
};

let provider = DatagenProvider::try_new(options, source_data)?;
Expand Down

0 comments on commit d8cc2f3

Please sign in to comment.