-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from Forced-Alignment-and-Vowel-Extraction/ft-…
…config-hotfix update ft-config
- Loading branch information
Showing
3 changed files
with
46 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,28 @@ | ||
import yaml | ||
from pathlib import Path | ||
from fasttrackpy import Smoother | ||
from new_fave.utils.local_resources import fave_fasttrack | ||
|
||
def read_fasttrack(config:str|Path)->dict: | ||
with Path(fave_fasttrack).open('r') as c: | ||
ft_dict = yaml.safe_load(c) | ||
|
||
config_dict = dict() | ||
if config: | ||
if type(config) is str: | ||
config = Path(config) | ||
|
||
with config.open('r') as c: | ||
config_dict = yaml.safe_load(c) | ||
|
||
for key in config_dict: | ||
if key in ft_dict: | ||
ft_dict[key] = config_dict[key] | ||
|
||
def read_fasttrack(config = str|Path)->dict: | ||
if type(config) is str: | ||
config = Path(config) | ||
|
||
with config.open('r') as c: | ||
config_dict = yaml.safe_load(c) | ||
|
||
smoother = Smoother() | ||
if "smoother" in config_dict: | ||
smoother = Smoother(**config_dict["smoother"]) | ||
if "smoother" in ft_dict: | ||
smoother = Smoother(**ft_dict["smoother"]) | ||
|
||
config_dict["smoother"] = smoother | ||
ft_dict["smoother"] = smoother | ||
|
||
return config_dict | ||
return ft_dict |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import warnings | ||
from typing import Callable | ||
def safely( | ||
message: str = f"There was a problem a function's application." | ||
): | ||
""" | ||
A decorator for more graceful failing. | ||
If the decorated function raises an exception, | ||
it will return `None`. | ||
Args: | ||
message (str, optional): | ||
A warning message in the case of an exception. | ||
Defaults to `f"There was a problem a function's application."`. | ||
""" | ||
def decorator(func:Callable): | ||
def safe_func(*args, **kwargs): | ||
try: | ||
return func(*args, **kwargs) | ||
except Exception as e: | ||
warnings.warn(message + "\n" + str(e)) | ||
return None | ||
return safe_func | ||
return decorator |