Skip to content

Commit

Permalink
モジュールレベルのglob importをすべて取り除く
Browse files Browse the repository at this point in the history
  • Loading branch information
qryxip committed Dec 11, 2023
1 parent 0788c2e commit fb6b65a
Show file tree
Hide file tree
Showing 25 changed files with 110 additions and 84 deletions.
5 changes: 4 additions & 1 deletion crates/test_util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ use tokio::{
io::{AsyncReadExt, AsyncWriteExt},
sync::Mutex,
};
pub use typing::*;

pub use self::typing::{
DecodeExampleData, DurationExampleData, ExampleData, IntonationExampleData,
};

pub const OPEN_JTALK_DIC_DIR: &str = concat!(
env!("CARGO_MANIFEST_DIR"),
Expand Down
9 changes: 6 additions & 3 deletions crates/voicevox_core/src/devices.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use derive_getters::Getters;
use serde::{Deserialize, Serialize};

use super::*;
use crate::{infer::InferenceRuntime, synthesizer::InferenceRuntimeImpl};
use crate::{infer::InferenceRuntime, synthesizer::InferenceRuntimeImpl, Result};

/// このライブラリで利用可能なデバイスの情報。
///
Expand Down Expand Up @@ -53,7 +53,10 @@ impl SupportedDevices {

#[cfg(test)]
mod tests {
use super::*;
use rstest::rstest;

use super::SupportedDevices;

#[rstest]
fn supported_devices_create_works() {
let result = SupportedDevices::create();
Expand Down
6 changes: 3 additions & 3 deletions crates/voicevox_core/src/engine/acoustic_feature_extractor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ impl OjtPhoneme {

#[cfg(test)]
mod tests {
use super::*;
use pretty_assertions::assert_eq;
use rstest::rstest;

use crate::*;
use super::OjtPhoneme;

const STR_HELLO_HIHO: &str = "sil k o N n i ch i w a pau h i h o d e s U sil";

Expand All @@ -130,7 +130,7 @@ mod tests {
#[case(38, "ts")]
#[case(41, "v")]
fn test_phoneme_list(#[case] index: usize, #[case] phoneme_str: &str) {
assert_eq!(PHONEME_LIST[index], phoneme_str);
assert_eq!(super::PHONEME_LIST[index], phoneme_str);
}

#[rstest]
Expand Down
11 changes: 5 additions & 6 deletions crates/voicevox_core/src/engine/kana_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ pub fn create_kana(accent_phrases: &[AccentPhraseModel]) -> String {

#[cfg(test)]
mod tests {
use super::*;
use crate::engine::mora_list::MORA_LIST_MINIMUM;
use pretty_assertions::assert_eq;
use rstest::rstest;
Expand All @@ -207,7 +206,7 @@ mod tests {
#[case(Some("O"), "_オ")]
#[case(None, "fail")]
fn test_text2mora_with_unvoice(#[case] mora: Option<&str>, #[case] text: &str) {
let text2mora = &TEXT2MORA_WITH_UNVOICE;
let text2mora = &super::TEXT2MORA_WITH_UNVOICE;
assert_eq!(text2mora.len(), MORA_LIST_MINIMUM.len() * 2 - 2); // added twice except ン and ッ
let res = text2mora.get(text);
assert_eq!(mora.is_some(), res.is_some());
Expand All @@ -230,7 +229,7 @@ mod tests {
#[case("'アクセントハジマリ", false)]
#[case("不明な'文字", false)]
fn test_text_to_accent_phrase(#[case] text: &str, #[case] result_is_ok_expected: bool) {
let result = text_to_accent_phrase(text);
let result = super::text_to_accent_phrase(text);
assert_eq!(result.is_ok(), result_is_ok_expected, "{:?}", result);
}

Expand All @@ -239,14 +238,14 @@ mod tests {
#[case("クウハクノ'//フレーズ'", false)]
#[case("フレー?ズノ'/トチュウニ'、ギモ'ンフ", false)]
fn test_parse_kana(#[case] text: &str, #[case] result_is_ok_expected: bool) {
let result = parse_kana(text);
let result = super::parse_kana(text);
assert_eq!(result.is_ok(), result_is_ok_expected, "{:?}", result);
}
#[rstest]
fn test_create_kana() {
let text = "アンドロ'イドワ、デンキ'/ヒ'_ツジノ/ユメ'オ/ミ'ルカ?";
let phrases = parse_kana(text).unwrap();
let text_created = create_kana(&phrases);
let phrases = super::parse_kana(text).unwrap();
let text_created = super::create_kana(&phrases);
assert_eq!(text, &text_created);
}
}
8 changes: 4 additions & 4 deletions crates/voicevox_core/src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ mod model;
mod mora_list;
pub(crate) mod open_jtalk;

pub use self::acoustic_feature_extractor::*;
pub use self::full_context_label::*;
pub use self::kana_parser::*;
pub use self::model::*;
pub(crate) use self::acoustic_feature_extractor::OjtPhoneme;
pub(crate) use self::full_context_label::{FullContextLabelError, Utterance};
pub(crate) use self::kana_parser::{create_kana, parse_kana, KanaParseError};
pub use self::model::{AccentPhraseModel, AudioQueryModel, MoraModel};
pub(crate) use self::mora_list::mora2text;
pub use self::open_jtalk::FullcontextExtractor;
5 changes: 3 additions & 2 deletions crates/voicevox_core/src/engine/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,12 @@ impl AudioQueryModel {

#[cfg(test)]
mod tests {
use super::*;
use crate::*;
use pretty_assertions::assert_eq;
use rstest::rstest;
use serde_json::json;

use super::AudioQueryModel;

#[rstest]
fn check_audio_query_model_json_field_snake_case() {
let audio_query_model =
Expand Down
3 changes: 1 addition & 2 deletions crates/voicevox_core/src/engine/mora_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ pub fn mora2text(mora: &str) -> &str {

#[cfg(test)]
mod tests {
use super::*;
use pretty_assertions::assert_eq;
use rstest::rstest;

Expand All @@ -212,6 +211,6 @@ mod tests {
#[case("u", "ウ")]
#[case("fail", "fail")]
fn test_mora2text(#[case] mora: &str, #[case] text: &str) {
assert_eq!(mora2text(mora), text);
assert_eq!(super::mora2text(mora), text);
}
}
4 changes: 3 additions & 1 deletion crates/voicevox_core/src/engine/open_jtalk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use std::{path::Path, sync::Mutex};
use anyhow::anyhow;
use tempfile::NamedTempFile;

use ::open_jtalk::*;
use ::open_jtalk::{
mecab_dict_index, text2mecab, JpCommon, ManagedResource, Mecab, Njd, Text2MecabError,
};

use crate::error::ErrorRepr;

Expand Down
7 changes: 5 additions & 2 deletions crates/voicevox_core/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use self::engine::{FullContextLabelError, KanaParseError};
use super::*;
use crate::{
engine::{FullContextLabelError, KanaParseError},
user_dict::InvalidWordError,
StyleId, VoiceModelId,
};
//use engine::
use duplicate::duplicate_item;
use std::path::PathBuf;
Expand Down
4 changes: 2 additions & 2 deletions crates/voicevox_core/src/infer/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use crate::{
infer::{InferenceOperation, ParamInfo},
manifest::ModelInnerId,
metas::{SpeakerMeta, StyleId, StyleMeta, VoiceModelMeta},
voice_model::VoiceModelId,
Result, VoiceModelHeader,
voice_model::{VoiceModelHeader, VoiceModelId},
Result,
};

use super::{
Expand Down
34 changes: 13 additions & 21 deletions crates/voicevox_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,16 @@ pub mod tokio;
#[cfg(test)]
mod test_util;

#[cfg(test)]
use self::test_util::*;

pub use self::engine::{AccentPhraseModel, AudioQueryModel, FullcontextExtractor};
pub use self::error::*;
pub use self::metas::*;
pub use self::result::*;
pub use self::voice_model::*;
pub use devices::*;
pub use manifest::*;
pub use synthesizer::{AccelerationMode, InitializeOptions, SynthesisOptions, TtsOptions};
pub use user_dict::*;
pub use version::*;

use derive_getters::*;
use derive_new::new;
use nanoid::nanoid;
#[cfg(test)]
use rstest::*;

use cfg_if::cfg_if;
pub use self::{
devices::SupportedDevices,
engine::{AccentPhraseModel, AudioQueryModel, FullcontextExtractor},
error::{Error, ErrorKind},
metas::{
RawStyleId, RawStyleVersion, SpeakerMeta, StyleId, StyleMeta, StyleVersion, VoiceModelMeta,
},
result::Result,
synthesizer::{AccelerationMode, InitializeOptions, SynthesisOptions, TtsOptions},
user_dict::{UserDictWord, UserDictWordType},
version::VERSION,
voice_model::{RawVoiceModelId, VoiceModelId},
};
11 changes: 4 additions & 7 deletions crates/voicevox_core/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,12 @@ use derive_getters::Getters;
use derive_new::new;
use serde::{Deserialize, Serialize};

use super::*;
use crate::StyleId;

pub type RawManifestVersion = String;
#[derive(Deserialize, Clone, Debug, PartialEq, new)]
pub struct ManifestVersion(RawManifestVersion);

impl ManifestVersion {
pub fn raw_manifest_version(&self) -> &RawManifestVersion {
&self.0
}
}

impl Display for ManifestVersion {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
Expand All @@ -42,6 +36,9 @@ impl Display for ModelInnerId {

#[derive(Deserialize, Getters, Clone)]
pub struct Manifest {
// FIXME: UUIDにする
// https://github.com/VOICEVOX/voicevox_core/issues/581
#[allow(dead_code)]
manifest_version: ManifestVersion,
metas_filename: String,
decode_filename: String,
Expand Down
2 changes: 1 addition & 1 deletion crates/voicevox_core/src/metas.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fmt::Display;

use super::*;
use derive_getters::Getters;
use derive_new::new;
use serde::{Deserialize, Serialize};

/// [`StyleId`]の実体。
Expand Down
3 changes: 1 addition & 2 deletions crates/voicevox_core/src/result.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
use super::*;
pub type Result<T> = std::result::Result<T, Error>;
pub type Result<T> = std::result::Result<T, crate::Error>;
11 changes: 6 additions & 5 deletions crates/voicevox_core/src/synthesizer.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use std::io::{Cursor, Write as _};

use cfg_if::cfg_if;
use enum_map::enum_map;

use crate::{
engine::{
create_kana, parse_kana, AccentPhraseModel, FullcontextExtractor, MoraModel, OjtPhoneme,
Utterance,
self, create_kana, parse_kana, AccentPhraseModel, FullcontextExtractor, MoraModel,
OjtPhoneme, Utterance,
},
error::ErrorRepr,
infer::{
domain::{
DecodeInput, DecodeOutput, InferenceOperationImpl, PredictDurationInput,
Expand All @@ -17,10 +19,9 @@ use crate::{
InferenceSessionOptions,
},
numerics::F32Ext as _,
AudioQueryModel, Result, StyleId, SupportedDevices, VoiceModelId, VoiceModelMeta,
};

use super::*;

/// [`blocking::Synthesizer::synthesis`]および[`tokio::Synthesizer::synthesis`]のオプション。
///
/// [`blocking::Synthesizer::synthesis`]: blocking::Synthesizer::synthesis
Expand Down Expand Up @@ -1379,7 +1380,7 @@ mod tests {

use super::{AccelerationMode, InitializeOptions, PerformInference as _};
use crate::{
engine::MoraModel, macros::tests::assert_debug_fmt_eq, open_default_vvm_file,
engine::MoraModel, macros::tests::assert_debug_fmt_eq, test_util::open_default_vvm_file,
AccentPhraseModel, Result, StyleId,
};
use ::test_util::OPEN_JTALK_DIC_DIR;
Expand Down
3 changes: 1 addition & 2 deletions crates/voicevox_core/src/user_dict/dict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ use indexmap::IndexMap;
use itertools::join;
use uuid::Uuid;

use super::word::*;
use crate::{error::ErrorRepr, Result};
use crate::{error::ErrorRepr, Result, UserDictWord};

impl self::blocking::UserDict {
/// ユーザー辞書を作成する。
Expand Down
3 changes: 2 additions & 1 deletion crates/voicevox_core/src/user_dict/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ pub(crate) mod dict;
mod part_of_speech_data;
mod word;

pub use word::*;
pub(crate) use self::word::{to_zenkaku, validate_pronunciation, InvalidWordError};
pub use self::word::{UserDictWord, UserDictWordType};
7 changes: 4 additions & 3 deletions crates/voicevox_core/src/user_dict/word.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,16 +245,17 @@ impl UserDictWord {

#[cfg(test)]
mod tests {
use super::*;
use rstest::rstest;

use super::{InvalidWordError, UserDictWord, UserDictWordType};

#[rstest]
#[case("abcdefg", "abcdefg")]
#[case("あいうえお", "あいうえお")]
#[case("a_b_c_d_e_f_g", "a_b_c_d_e_f_g")]
#[case("a b c d e f g", "a b c d e f g")]
fn to_zenkaku_works(#[case] before: &str, #[case] after: &str) {
assert_eq!(to_zenkaku(before), after);
assert_eq!(super::to_zenkaku(before), after);
}

#[rstest]
Expand Down Expand Up @@ -285,7 +286,7 @@ mod tests {
#[case] pronunciation: &str,
#[case] expected_error_message: Option<&str>,
) {
let result = validate_pronunciation(pronunciation);
let result = super::validate_pronunciation(pronunciation);

if let Some(expected_error_message) = expected_error_message {
match result {
Expand Down
6 changes: 3 additions & 3 deletions crates/voicevox_core/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ pub const VERSION: &str = env!("CARGO_PKG_VERSION");

#[cfg(test)]
mod tests {
use super::*;
use crate::*;
use rstest::rstest;

#[rstest]
fn get_version_works() {
assert_eq!("0.0.0", VERSION);
assert_eq!("0.0.0", super::VERSION);
}
}
11 changes: 9 additions & 2 deletions crates/voicevox_core/src/voice_model.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
use derive_getters::Getters;
use derive_new::new;
use enum_map::EnumMap;
use futures::future::join3;
use nanoid::nanoid;
use ouroboros::self_referencing;
use rayon::iter::{IntoParallelIterator as _, ParallelIterator as _};
use serde::{de::DeserializeOwned, Deserialize};

use super::*;
use crate::infer::domain::InferenceOperationImpl;
use crate::{
error::{LoadModelError, LoadModelErrorKind, LoadModelResult},
infer::domain::InferenceOperationImpl,
manifest::{Manifest, ModelInnerId},
Result, SpeakerMeta, StyleId, StyleMeta, VoiceModelMeta,
};
use std::{
collections::{BTreeMap, HashMap},
io::{self, Cursor},
Expand Down
2 changes: 1 addition & 1 deletion crates/voicevox_core_c_api/src/c_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{ffi::CString, path::Path};

use voicevox_core::{InitializeOptions, Result, VoiceModelId};

use crate::{CApiResult, OpenJtalkRc, VoicevoxSynthesizer, VoicevoxVoiceModel};
use crate::{helpers::CApiResult, OpenJtalkRc, VoicevoxSynthesizer, VoicevoxVoiceModel};

impl OpenJtalkRc {
pub(crate) fn new(open_jtalk_dic_dir: impl AsRef<Path>) -> Result<Self> {
Expand Down
Loading

0 comments on commit fb6b65a

Please sign in to comment.