Skip to content

Commit

Permalink
2.2.3 (#574)
Browse files Browse the repository at this point in the history
* Migrate to using rich for terminal color and formatting
  • Loading branch information
mmcauliffe authored Feb 17, 2023
1 parent c2ef519 commit 415129e
Show file tree
Hide file tree
Showing 60 changed files with 369 additions and 877 deletions.
4 changes: 2 additions & 2 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ dependencies:
- librosa
- tqdm
- requests
- colorama
- ansiwrap
- pyyaml
- dataclassy
- kaldi=*=*cpu*
Expand Down Expand Up @@ -42,6 +40,8 @@ dependencies:
- matplotlib
- seaborn
- pip
- rich
- rich-click
- pip:
- build
- twine
Expand Down
3 changes: 3 additions & 0 deletions montreal_forced_aligner/__main__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from rich.traceback import install

from montreal_forced_aligner.command_line.mfa import mfa_cli

install(show_locals=True)
mfa_cli()
2 changes: 1 addition & 1 deletion montreal_forced_aligner/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ def check_previous_run(self) -> bool:
return True
conf = load_configuration(self.worker_config_path)
clean = self._validate_previous_configuration(conf)
if not clean:
if not GLOBAL_CONFIG.current_profile.clean and not clean:
logger.warning(
"The previous run had a different configuration than the current, which may cause issues."
" Please see the log for details or use --clean flag if issues are encountered."
Expand Down
4 changes: 2 additions & 2 deletions montreal_forced_aligner/acoustic_modeling/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
from typing import TYPE_CHECKING, List

import sqlalchemy.engine
import tqdm
from sqlalchemy.orm import Session
from tqdm.rich import tqdm

from montreal_forced_aligner.abc import MfaWorker, ModelExporterMixin, TrainerMixin
from montreal_forced_aligner.alignment import AlignMixin
Expand Down Expand Up @@ -327,7 +327,7 @@ def acc_stats(self) -> None:
"""
logger.info("Accumulating statistics...")
arguments = self.acc_stats_arguments()
with tqdm.tqdm(total=self.num_current_utterances, disable=GLOBAL_CONFIG.quiet) as pbar:
with tqdm(total=self.num_current_utterances, disable=GLOBAL_CONFIG.quiet) as pbar:
if GLOBAL_CONFIG.use_mp:
error_dict = {}
return_queue = mp.Queue()
Expand Down
6 changes: 3 additions & 3 deletions montreal_forced_aligner/acoustic_modeling/lda.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from queue import Empty
from typing import TYPE_CHECKING, Dict, List

import tqdm
from tqdm.rich import tqdm

from montreal_forced_aligner.abc import KaldiFunction
from montreal_forced_aligner.acoustic_modeling.triphone import TriphoneTrainer
Expand Down Expand Up @@ -412,7 +412,7 @@ def lda_acc_stats(self) -> None:
if os.path.exists(worker_lda_path):
os.remove(worker_lda_path)
arguments = self.lda_acc_stats_arguments()
with tqdm.tqdm(total=self.num_current_utterances, disable=GLOBAL_CONFIG.quiet) as pbar:
with tqdm(total=self.num_current_utterances, disable=GLOBAL_CONFIG.quiet) as pbar:
if GLOBAL_CONFIG.use_mp:
error_dict = {}
return_queue = mp.Queue()
Expand Down Expand Up @@ -509,7 +509,7 @@ def calc_lda_mllt(self) -> None:
"""
logger.info("Re-calculating LDA...")
arguments = self.calc_lda_mllt_arguments()
with tqdm.tqdm(total=self.num_current_utterances, disable=GLOBAL_CONFIG.quiet) as pbar:
with tqdm(total=self.num_current_utterances, disable=GLOBAL_CONFIG.quiet) as pbar:
if GLOBAL_CONFIG.use_mp:
error_dict = {}
return_queue = mp.Queue()
Expand Down
4 changes: 2 additions & 2 deletions montreal_forced_aligner/acoustic_modeling/monophone.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from pathlib import Path
from queue import Empty

import tqdm
from sqlalchemy.orm import Session, joinedload, subqueryload
from tqdm.rich import tqdm

from montreal_forced_aligner.abc import KaldiFunction
from montreal_forced_aligner.acoustic_modeling.base import AcousticModelTrainingMixin
Expand Down Expand Up @@ -240,7 +240,7 @@ def mono_align_equal(self) -> None:

logger.info("Generating initial alignments...")
arguments = self.mono_align_equal_arguments()
with tqdm.tqdm(total=self.num_current_utterances, disable=GLOBAL_CONFIG.quiet) as pbar:
with tqdm(total=self.num_current_utterances, disable=GLOBAL_CONFIG.quiet) as pbar:
if GLOBAL_CONFIG.use_mp:
error_dict = {}
return_queue = mp.Queue()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import typing
from pathlib import Path

import tqdm
from sqlalchemy.orm import joinedload
from tqdm.rich import tqdm

from montreal_forced_aligner.acoustic_modeling.base import AcousticModelTrainingMixin
from montreal_forced_aligner.alignment.multiprocessing import (
Expand Down Expand Up @@ -186,7 +186,7 @@ def train_g2p_lexicon(self) -> None:
)
for x in self.worker.dictionary_lookup.values()
}
with tqdm.tqdm(total=self.num_current_utterances, disable=GLOBAL_CONFIG.quiet) as pbar:
with tqdm(total=self.num_current_utterances, disable=GLOBAL_CONFIG.quiet) as pbar:
for dict_id, utt_id, phones in run_kaldi_function(
GeneratePronunciationsFunction, arguments, pbar.update
):
Expand Down
4 changes: 2 additions & 2 deletions montreal_forced_aligner/acoustic_modeling/sat.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from queue import Empty
from typing import Dict, List

import tqdm
from tqdm.rich import tqdm

from montreal_forced_aligner.acoustic_modeling.triphone import TriphoneTrainer
from montreal_forced_aligner.config import GLOBAL_CONFIG
Expand Down Expand Up @@ -341,7 +341,7 @@ def create_align_model(self) -> None:
begin = time.time()

arguments = self.acc_stats_two_feats_arguments()
with tqdm.tqdm(total=self.num_current_utterances, disable=GLOBAL_CONFIG.quiet) as pbar:
with tqdm(total=self.num_current_utterances, disable=GLOBAL_CONFIG.quiet) as pbar:
if GLOBAL_CONFIG.use_mp:
error_dict = {}
return_queue = mp.Queue()
Expand Down
4 changes: 2 additions & 2 deletions montreal_forced_aligner/acoustic_modeling/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
from queue import Empty
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple

import tqdm
from sqlalchemy.orm import Session, joinedload, subqueryload
from tqdm.rich import tqdm

from montreal_forced_aligner.abc import KaldiFunction, ModelExporterMixin, TopLevelMfaWorker
from montreal_forced_aligner.config import GLOBAL_CONFIG
Expand Down Expand Up @@ -583,7 +583,7 @@ def compute_phone_pdf_counts(self) -> None:
log_directory = self.working_log_directory
os.makedirs(log_directory, exist_ok=True)
arguments = self.transition_acc_arguments()
with tqdm.tqdm(total=self.num_utterances, disable=GLOBAL_CONFIG.quiet) as pbar:
with tqdm(total=self.num_utterances, disable=GLOBAL_CONFIG.quiet) as pbar:
if GLOBAL_CONFIG.use_mp:
error_dict = {}
return_queue = mp.Queue()
Expand Down
4 changes: 2 additions & 2 deletions montreal_forced_aligner/acoustic_modeling/triphone.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from queue import Empty
from typing import TYPE_CHECKING, Dict, List

import tqdm
from tqdm.rich import tqdm

from montreal_forced_aligner.acoustic_modeling.base import AcousticModelTrainingMixin
from montreal_forced_aligner.config import GLOBAL_CONFIG
Expand Down Expand Up @@ -294,7 +294,7 @@ def convert_alignments(self) -> None:
"""
logger.info("Converting alignments...")
arguments = self.convert_alignments_arguments()
with tqdm.tqdm(total=self.num_current_utterances, disable=GLOBAL_CONFIG.quiet) as pbar:
with tqdm(total=self.num_current_utterances, disable=GLOBAL_CONFIG.quiet) as pbar:
if GLOBAL_CONFIG.use_mp:
error_dict = {}
return_queue = mp.Queue()
Expand Down
4 changes: 2 additions & 2 deletions montreal_forced_aligner/alignment/adapting.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from queue import Empty
from typing import TYPE_CHECKING, List

import tqdm
from tqdm.rich import tqdm

from montreal_forced_aligner.abc import AdapterMixin
from montreal_forced_aligner.alignment.multiprocessing import AccStatsArguments, AccStatsFunction
Expand Down Expand Up @@ -124,7 +124,7 @@ def acc_stats(self, alignment: bool = False) -> None:
initial_mdl_path = self.working_directory.joinpath("unadapted.mdl")
final_mdl_path = self.working_directory.joinpath("final.mdl")
logger.info("Accumulating statistics...")
with tqdm.tqdm(total=self.num_current_utterances, disable=GLOBAL_CONFIG.quiet) as pbar:
with tqdm(total=self.num_current_utterances, disable=GLOBAL_CONFIG.quiet) as pbar:
if GLOBAL_CONFIG.use_mp:
error_dict = {}
return_queue = mp.Queue()
Expand Down
10 changes: 5 additions & 5 deletions montreal_forced_aligner/alignment/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
from typing import Dict, List, Optional

import sqlalchemy
import tqdm
from sqlalchemy.orm import joinedload, subqueryload
from tqdm.rich import tqdm

from montreal_forced_aligner.abc import FileExporterMixin
from montreal_forced_aligner.alignment.mixins import AlignMixin
Expand Down Expand Up @@ -327,7 +327,7 @@ def compute_pronunciation_probabilities(self):
}
logger.info("Generating pronunciations...")
arguments = self.generate_pronunciations_arguments()
with tqdm.tqdm(total=self.num_current_utterances, disable=GLOBAL_CONFIG.quiet) as pbar:
with tqdm(total=self.num_current_utterances, disable=GLOBAL_CONFIG.quiet) as pbar:
if GLOBAL_CONFIG.use_mp:
error_dict = {}
return_queue = mp.Queue()
Expand Down Expand Up @@ -696,7 +696,7 @@ def collect_alignments(self) -> None:
if max_word_interval_id is None:
max_word_interval_id = 0

with tqdm.tqdm(total=self.num_current_utterances, disable=GLOBAL_CONFIG.quiet) as pbar:
with tqdm(total=self.num_current_utterances, disable=GLOBAL_CONFIG.quiet) as pbar:
logger.info(f"Collecting phone and word alignments from {workflow.name} lattices...")

arguments = self.alignment_extraction_arguments()
Expand Down Expand Up @@ -867,7 +867,7 @@ def fine_tune_alignments(self) -> None:
"""
logger.info("Fine tuning alignments...")
begin = time.time()
with self.session() as session, tqdm.tqdm(
with self.session() as session, tqdm(
total=self.num_utterances, disable=GLOBAL_CONFIG.quiet
) as pbar:
update_mappings = []
Expand Down Expand Up @@ -1027,7 +1027,7 @@ def export_textgrids(
begin = time.time()
error_dict = {}

with tqdm.tqdm(total=self.num_files, disable=GLOBAL_CONFIG.quiet) as pbar:
with tqdm(total=self.num_files, disable=GLOBAL_CONFIG.quiet) as pbar:
with self.session() as session:
files = (
session.query(
Expand Down
8 changes: 4 additions & 4 deletions montreal_forced_aligner/alignment/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from queue import Empty
from typing import TYPE_CHECKING, Dict, List

import tqdm
from tqdm.rich import tqdm

from montreal_forced_aligner.alignment.multiprocessing import (
AlignArguments,
Expand Down Expand Up @@ -298,7 +298,7 @@ def compile_train_graphs(self) -> None:
logger.info("Compiling training graphs...")
error_sum = 0
arguments = self.compile_train_graphs_arguments()
with tqdm.tqdm(total=self.num_current_utterances, disable=GLOBAL_CONFIG.quiet) as pbar:
with tqdm(total=self.num_current_utterances, disable=GLOBAL_CONFIG.quiet) as pbar:
if GLOBAL_CONFIG.use_mp:
error_dict = {}
return_queue = mp.Queue()
Expand Down Expand Up @@ -351,7 +351,7 @@ def get_phone_confidences(self):
begin = time.time()

with self.session() as session:
with tqdm.tqdm(total=self.num_current_utterances, disable=GLOBAL_CONFIG.quiet) as pbar:
with tqdm(total=self.num_current_utterances, disable=GLOBAL_CONFIG.quiet) as pbar:
arguments = self.phone_confidence_arguments()
interval_update_mappings = []
if GLOBAL_CONFIG.use_mp:
Expand Down Expand Up @@ -416,7 +416,7 @@ def align_utterances(self, training=False) -> None:
"""
begin = time.time()
logger.info("Generating alignments...")
with tqdm.tqdm(
with tqdm(
total=self.num_current_utterances, disable=GLOBAL_CONFIG.quiet
) as pbar, self.session() as session:
if not training:
Expand Down
2 changes: 1 addition & 1 deletion montreal_forced_aligner/command_line/adapt.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os
from pathlib import Path

import click
import rich_click as click

from montreal_forced_aligner.alignment import AdaptingAligner
from montreal_forced_aligner.command_line.utils import (
Expand Down
2 changes: 1 addition & 1 deletion montreal_forced_aligner/command_line/align.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os
from pathlib import Path

import click
import rich_click as click
import yaml

from montreal_forced_aligner.alignment import PretrainedAligner
Expand Down
8 changes: 5 additions & 3 deletions montreal_forced_aligner/command_line/anchor.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
"""Command line functions for launching anchor annotation"""
from __future__ import annotations

import logging
import sys

import click
import rich_click as click

__all__ = ["anchor_cli"]

logger = logging.getLogger("mfa")


@click.command(name="anchor", short_help="Launch Anchor")
@click.help_option("-h", "--help")
Expand All @@ -17,8 +20,7 @@ def anchor_cli(*args, **kwargs) -> None: # pragma: no cover
try:
from anchor.command_line import main
except ImportError:
raise
print(
logger.error(
"Anchor annotator utility is not installed, please install it via pip install anchor-annotator."
)
sys.exit(1)
Expand Down
2 changes: 1 addition & 1 deletion montreal_forced_aligner/command_line/configure.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os

import click
import rich_click as click

from montreal_forced_aligner.config import GLOBAL_CONFIG, MFA_PROFILE_VARIABLE

Expand Down
2 changes: 1 addition & 1 deletion montreal_forced_aligner/command_line/create_segments.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os
from pathlib import Path

import click
import rich_click as click

from montreal_forced_aligner.command_line.utils import (
check_databases,
Expand Down
2 changes: 1 addition & 1 deletion montreal_forced_aligner/command_line/diarize_speakers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os
from pathlib import Path

import click
import rich_click as click

from montreal_forced_aligner.command_line.utils import (
check_databases,
Expand Down
2 changes: 1 addition & 1 deletion montreal_forced_aligner/command_line/g2p.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os
from pathlib import Path

import click
import rich_click as click

from montreal_forced_aligner.command_line.utils import (
check_databases,
Expand Down
11 changes: 7 additions & 4 deletions montreal_forced_aligner/command_line/history.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import logging
import time

import click
import rich_click as click

from montreal_forced_aligner.config import GLOBAL_CONFIG, load_command_history

__all__ = ["history_cli"]

logger = logging.getLogger("mfa")


@click.command(
"history",
Expand All @@ -26,14 +29,14 @@ def history_cli(depth: int, verbose: bool) -> None:
"""
history = load_command_history()[-depth:]
if verbose:
print("command\tDate\tExecution time\tVersion\tExit code\tException")
logger.info("command\tDate\tExecution time\tVersion\tExit code\tException")
for h in history:
execution_time = time.strftime("%H:%M:%S", time.gmtime(h["execution_time"]))
d = h["date"].isoformat()
print(
logger.info(
f"{h['command']}\t{d}\t{execution_time}\t{h.get('version', 'unknown')}\t{h['exit_code']}\t{h['exception']}"
)
pass
else:
for h in history:
print(h["command"])
logger.info(h["command"])
Loading

0 comments on commit 415129e

Please sign in to comment.