Skip to content

Commit

Permalink
Allow to bypass version check (#830)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienball authored Jul 17, 2019
1 parent 080fcf6 commit 1176c44
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog
All notable changes to this project will be documented in this file.

## [Unreleased]
### Added
- Allow to bypass the model version check [#830](https://github.com/snipsco/snips-nlu/pull/830)

## [0.20.0]
### Added
- Add new intent parser: `LookupIntentParser` [#759](https://github.com/snipsco/snips-nlu/pull/759)
Expand Down Expand Up @@ -312,6 +316,7 @@ several commands.
- Fix compiling issue with `bindgen` dependency when installing from source
- Fix issue in `CRFSlotFiller` when handling builtin entities

[Unreleased]: https://github.com/snipsco/snips-nlu/compare/0.20.0...HEAD
[0.20.0]: https://github.com/snipsco/snips-nlu/compare/0.19.8...0.20.0
[0.19.8]: https://github.com/snipsco/snips-nlu/compare/0.19.7...0.19.8
[0.19.7]: https://github.com/snipsco/snips-nlu/compare/0.19.6...0.19.7
Expand Down
1 change: 1 addition & 0 deletions snips_nlu/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
CUSTOM_ENTITY_PARSER = "custom_entity_parser"
MATCHING_STRICTNESS = "matching_strictness"
RANDOM_STATE = "random_state"
BYPASS_VERSION_CHECK = "bypass_version_check"

# resources
RESOURCES = "resources"
Expand Down
11 changes: 9 additions & 2 deletions snips_nlu/nlu_engine/nlu_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
AUTOMATICALLY_EXTENSIBLE, BUILTIN_ENTITY_PARSER, CUSTOM_ENTITY_PARSER,
ENTITIES, ENTITY_KIND, LANGUAGE, RESOLVED_VALUE, RES_ENTITY,
RES_INTENT, RES_INTENT_NAME, RES_MATCH_RANGE, RES_PROBA, RES_SLOTS,
RES_VALUE, RESOURCES)
RES_VALUE, RESOURCES, BYPASS_VERSION_CHECK)
from snips_nlu.dataset import validate_and_format_dataset
from snips_nlu.default_configs import DEFAULT_CONFIGS
from snips_nlu.entity_parser import CustomEntityParser
Expand Down Expand Up @@ -349,7 +349,14 @@ def from_path(cls, path, **shared):
model = json.load(f)
model_version = model.get("model_version")
if model_version is None or model_version != __model_version__:
raise IncompatibleModelError(model_version)
bypass_version_check = shared.get(BYPASS_VERSION_CHECK, False)
if bypass_version_check:
logger.warning(
"Incompatible model version found. The library expected "
"'%s' but the loaded engine is '%s'. The NLU engine may "
"not load correctly.", __model_version__, model_version)
else:
raise IncompatibleModelError(model_version)

dataset_metadata = model["dataset_metadata"]
if shared.get(RESOURCES) is None and dataset_metadata is not None:
Expand Down
18 changes: 18 additions & 0 deletions snips_nlu/tests/test_nlu_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,24 @@ def test_should_raise_with_incompatible_model(self):
with self.assertRaises(IncompatibleModelError):
SnipsNLUEngine.from_path(self.tmp_file_path)

def test_should_bypass_model_version_check_when_specified(self):
# Given
dataset_stream = io.StringIO("""
---
type: intent
name: Greeting
utterances:
- hello world""")
dataset = Dataset.from_yaml_files("en", [dataset_stream]).json

with patch("snips_nlu.nlu_engine.nlu_engine.__model_version__",
"0.1.0"):
engine = SnipsNLUEngine().fit(dataset)
engine.persist(self.tmp_file_path)

# When / Then
SnipsNLUEngine.from_path(self.tmp_file_path, bypass_version_check=True)

def test_should_raise_when_persisting_at_existing_path(self):
# Given
self.tmp_file_path.mkdir()
Expand Down

0 comments on commit 1176c44

Please # to comment.