-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor import style and disallow direct imports
- Loading branch information
Showing
9 changed files
with
72 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,57 @@ | ||
from .registry import * | ||
from .builders import * | ||
from .configs import * | ||
from .data import * | ||
from .embeddings import * | ||
from .metrics import * | ||
from .models import * | ||
from .preprocessors import * | ||
from .trainer import * | ||
from .utils import * | ||
""" | ||
Direct importing from hezar's root is no longer supported nor recommended since version 0.33.0. The following is just a | ||
workaround for backward compatibility. Any class, functions, etc. must be imported from its main submodule under hezar. | ||
""" | ||
import warnings | ||
|
||
|
||
__version__ = "0.32.1" | ||
|
||
|
||
def _warn_on_import(name: str, submodule: str): | ||
warnings.warn( | ||
f"Importing {name} from hezar root is deprecated and will be removed soon. " | ||
f"Please use `from {submodule} import {name}`" | ||
) | ||
|
||
|
||
def __getattr__(name: str): | ||
if name == "Model": | ||
from hezar.models import Model | ||
_warn_on_import(name, "hezar.models") | ||
return Model | ||
elif name == "Dataset": | ||
from .data import Dataset | ||
_warn_on_import(name, "hezar.data") | ||
return Dataset | ||
elif name == "Trainer": | ||
from .trainer import Trainer | ||
_warn_on_import(name, "hezar.trainer") | ||
return Trainer | ||
elif name == "Embedding": | ||
from .embeddings import Embedding | ||
_warn_on_import(name, "hezar.embeddings") | ||
return Embedding | ||
elif name == "Preprocessor": | ||
from .preprocessors import Preprocessor | ||
_warn_on_import(name, "hezar.preprocessors") | ||
return Preprocessor | ||
elif name == "Metric": | ||
from .metrics import Metric | ||
_warn_on_import(name, "hezar.metrics") | ||
return Metric | ||
elif "Config" in name: | ||
from .configs import Config | ||
_warn_on_import(name, "hezar.configs") | ||
return Config | ||
|
||
|
||
__all__ = [ | ||
"Config", | ||
"Model", | ||
"Dataset", | ||
"Trainer", | ||
"Preprocessor", | ||
"Embedding", | ||
"Metric", | ||
] |
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,3 +1,4 @@ | ||
from .embedding import Embedding | ||
from ..registry import register_embedding # noqa | ||
from .embedding import Embedding, EmbeddingConfig # noqa | ||
from .fasttext import FastText, FastTextConfig | ||
from .word2vec import Word2Vec, Word2VecConfig |
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
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
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,3 +1,3 @@ | ||
from .trainer import Trainer | ||
from .trainer import Trainer, TrainerConfig # noqa | ||
from .trainer_utils import * | ||
from .metrics_handlers import * |
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