From c909f5f1f24cc879065aa8791b68ac356a8bcbce Mon Sep 17 00:00:00 2001 From: Adriane Boyd Date: Mon, 18 Oct 2021 09:25:42 +0200 Subject: [PATCH 1/3] Use local error messages, fix error references --- spacy_loggers/errors.py | 10 ++++++++++ spacy_loggers/wandb.py | 8 ++++---- 2 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 spacy_loggers/errors.py diff --git a/spacy_loggers/errors.py b/spacy_loggers/errors.py new file mode 100644 index 0000000..a9b37bf --- /dev/null +++ b/spacy_loggers/errors.py @@ -0,0 +1,10 @@ +from spacy.errors import add_codes + + +# fmt: off + +@add_codes +class Errors: + E880 = ("The 'wandb' library could not be found - did you install it? " + "Alternatively, specify the 'ConsoleLogger' in the 'training.logger' " + "config section, instead of the 'WandbLogger'.") diff --git a/spacy_loggers/wandb.py b/spacy_loggers/wandb.py index 3619a75..a8cefcf 100644 --- a/spacy_loggers/wandb.py +++ b/spacy_loggers/wandb.py @@ -5,10 +5,10 @@ from typing import Dict, Any, Tuple, Callable, List, Optional, IO import sys -from spacy import util, errors +from spacy import util from spacy import Language from spacy.training.loggers import console_logger -from spacy.errors import Errors +from .errors import Errors # entry point: spacy.WandbLogger.v3 @@ -108,7 +108,7 @@ def wandb_logger_v2( # test that these are available from wandb import init, log, join # noqa: F401 except ImportError: - raise ImportError(errors.E880) + raise ImportError(Errors.E880) console = console_logger(progress_bar=False) @@ -181,7 +181,7 @@ def wandb_logger_v1(project_name: str, remove_config_values: List[str] = []): # test that these are available from wandb import init, log, join # noqa: F401 except ImportError: - raise ImportError(errors.E880) + raise ImportError(Errors.E880) console = console_logger(progress_bar=False) From acde03454d84cb6d5607974926c094ad3738e08d Mon Sep 17 00:00:00 2001 From: Adriane Boyd Date: Mon, 18 Oct 2021 11:59:34 +0200 Subject: [PATCH 2/3] Use custom error codes --- spacy_loggers/errors.py | 6 +++--- spacy_loggers/wandb.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/spacy_loggers/errors.py b/spacy_loggers/errors.py index a9b37bf..1adeb23 100644 --- a/spacy_loggers/errors.py +++ b/spacy_loggers/errors.py @@ -5,6 +5,6 @@ @add_codes class Errors: - E880 = ("The 'wandb' library could not be found - did you install it? " - "Alternatively, specify the 'ConsoleLogger' in the 'training.logger' " - "config section, instead of the 'WandbLogger'.") + SPACY_LOGGERS_E880 = ("The 'wandb' library could not be found - did you " + "install it? Alternatively, specify the 'ConsoleLogger' in the " + "'training.logger' config section, instead of the 'WandbLogger'.") diff --git a/spacy_loggers/wandb.py b/spacy_loggers/wandb.py index a8cefcf..1ebbb5f 100644 --- a/spacy_loggers/wandb.py +++ b/spacy_loggers/wandb.py @@ -26,7 +26,7 @@ def wandb_logger_v3( # test that these are available from wandb import init, log, join # noqa: F401 except ImportError: - raise ImportError(Errors.E880) + raise ImportError(Errors.SPACY_LOGGERS_E880) console = console_logger(progress_bar=False) @@ -108,7 +108,7 @@ def wandb_logger_v2( # test that these are available from wandb import init, log, join # noqa: F401 except ImportError: - raise ImportError(Errors.E880) + raise ImportError(Errors.SPACY_LOGGERS_E880) console = console_logger(progress_bar=False) @@ -181,7 +181,7 @@ def wandb_logger_v1(project_name: str, remove_config_values: List[str] = []): # test that these are available from wandb import init, log, join # noqa: F401 except ImportError: - raise ImportError(Errors.E880) + raise ImportError(Errors.SPACY_LOGGERS_E880) console = console_logger(progress_bar=False) From 007880d39186528c254ec051abffca14aece99f4 Mon Sep 17 00:00:00 2001 From: Adriane Boyd Date: Tue, 19 Oct 2021 09:30:53 +0200 Subject: [PATCH 3/3] Switch to hard-coded errors --- spacy_loggers/errors.py | 10 ---------- spacy_loggers/wandb.py | 23 ++++++++++++++++++----- 2 files changed, 18 insertions(+), 15 deletions(-) delete mode 100644 spacy_loggers/errors.py diff --git a/spacy_loggers/errors.py b/spacy_loggers/errors.py deleted file mode 100644 index 1adeb23..0000000 --- a/spacy_loggers/errors.py +++ /dev/null @@ -1,10 +0,0 @@ -from spacy.errors import add_codes - - -# fmt: off - -@add_codes -class Errors: - SPACY_LOGGERS_E880 = ("The 'wandb' library could not be found - did you " - "install it? Alternatively, specify the 'ConsoleLogger' in the " - "'training.logger' config section, instead of the 'WandbLogger'.") diff --git a/spacy_loggers/wandb.py b/spacy_loggers/wandb.py index 1ebbb5f..012be44 100644 --- a/spacy_loggers/wandb.py +++ b/spacy_loggers/wandb.py @@ -8,7 +8,6 @@ from spacy import util from spacy import Language from spacy.training.loggers import console_logger -from .errors import Errors # entry point: spacy.WandbLogger.v3 @@ -26,7 +25,11 @@ def wandb_logger_v3( # test that these are available from wandb import init, log, join # noqa: F401 except ImportError: - raise ImportError(Errors.SPACY_LOGGERS_E880) + raise ImportError( + "The 'wandb' library could not be found - did you install it? " + "Alternatively, specify the 'ConsoleLogger' in the " + "'training.logger' config section, instead of the 'WandbLogger'." + ) console = console_logger(progress_bar=False) @@ -38,7 +41,9 @@ def setup_logger( for field in remove_config_values: del config_dot[field] config = util.dot_to_dict(config_dot) - run = wandb.init(project=project_name, config=config, entity=entity, reinit=True) + run = wandb.init( + project=project_name, config=config, entity=entity, reinit=True + ) if run_name: wandb.run.name = run_name @@ -108,7 +113,11 @@ def wandb_logger_v2( # test that these are available from wandb import init, log, join # noqa: F401 except ImportError: - raise ImportError(Errors.SPACY_LOGGERS_E880) + raise ImportError( + "The 'wandb' library could not be found - did you install it? " + "Alternatively, specify the 'ConsoleLogger' in the " + "'training.logger' config section, instead of the 'WandbLogger'." + ) console = console_logger(progress_bar=False) @@ -181,7 +190,11 @@ def wandb_logger_v1(project_name: str, remove_config_values: List[str] = []): # test that these are available from wandb import init, log, join # noqa: F401 except ImportError: - raise ImportError(Errors.SPACY_LOGGERS_E880) + raise ImportError( + "The 'wandb' library could not be found - did you install it? " + "Alternatively, specify the 'ConsoleLogger' in the " + "'training.logger' config section, instead of the 'WandbLogger'." + ) console = console_logger(progress_bar=False)