Skip to content

Commit

Permalink
Do not accept stacks with TF 2.1 and urllib3 that cause issues
Browse files Browse the repository at this point in the history
  • Loading branch information
fridex committed Sep 16, 2020
1 parent c01dd4c commit 46da6d0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 25 deletions.
18 changes: 6 additions & 12 deletions tests/steps/test_tensorflow_21_urllib3.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
import flexmock
import pytest

from thoth.adviser.exceptions import NotAcceptable
from thoth.adviser.steps import TensorFlow21Urllib3Step
from thoth.adviser.state import State
from thoth.common import get_justification_link as jl
from thoth.python import PackageVersion
from thoth.python import Source

Expand Down Expand Up @@ -53,17 +53,11 @@ def test_tf_21(self, urllib3_version: str, tf_version: str) -> None:
context = flexmock()
with TensorFlow21Urllib3Step.assigned_context(context):
unit = TensorFlow21Urllib3Step()
assert unit.run(state, urllib3_package_version) == (
-0.8,
[
{
"message": "TensorFlow in version 2.1 can cause runtime errors when "
"imported, caused by incompatibility between urllib3 and six packages",
"type": "WARNING",
"link": jl("tf_21_urllib3"),
}
],
)
unit.pre_run()
assert unit._message_logged is False
with pytest.raises(NotAcceptable):
assert unit.run(state, urllib3_package_version)
assert unit._message_logged is True

@pytest.mark.parametrize("urllib3_version,tf_version", [("1.2", "2.2.0"), ("1.25.10", "2.1")])
def test_no_tf_21(self, urllib3_version: str, tf_version: str) -> None:
Expand Down
29 changes: 16 additions & 13 deletions thoth/adviser/steps/tensorflow_21_urllib3.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

"""Suggest not to use TensorFlow 2.1 with specific urllib3 versions that cause six import issues."""

import attr
from typing import Any
from typing import Optional
from typing import Tuple
Expand All @@ -29,6 +30,7 @@
from thoth.python import PackageVersion

from ..enums import RecommendationType
from ..exceptions import NotAcceptable
from ..state import State
from ..step import Step

Expand All @@ -40,26 +42,23 @@
_LOGGER = logging.getLogger(__name__)


@attr.s(slots=True)
class TensorFlow21Urllib3Step(Step):
"""A step that suggests not to use TensorFlow 2.1 with specific urllib3 versions that cause six import issues."""

_message_logged = attr.ib(type=bool, default=False, init=False)

# Run this step each time, regardless of when TensorFlow and urllib3 are resolved.
MULTI_PACKAGE_RESOLUTIONS = True

_SCORE_ADDITION = -0.8
_JUSTIFICATION_ADDITION = [
{
"type": "WARNING",
"message": (
"TensorFlow in version 2.1 can cause runtime errors when imported, caused by "
"incompatibility between urllib3 and six packages"
),
"link": jl("tf_21_urllib3"),
}
]

_MESSAGE = f"TensorFlow in version 2.1 can cause runtime errors when imported, caused by " \
f"incompatibility between urllib3 and six packages - see {jl('tf_21_urllib3')}"
_AFFECTED_URLLIB3_VERSIONS = frozenset({(1, 2), (1, 3), (1, 4), (1, 5)})

def pre_run(self) -> None:
"""Initialize this pipeline unit before each run."""
self._message_logged = False

@classmethod
def should_include(cls, builder_context: "PipelineBuilderContext") -> Optional[Dict[str, Any]]:
"""Register this pipeline unit for adviser if not using latest recommendations."""
Expand Down Expand Up @@ -87,4 +86,8 @@ def run(
if "tensorflow" not in state.resolved_dependencies or state.resolved_dependencies["tensorflow"][1][:3] != "2.1":
return None

return self._SCORE_ADDITION, self._JUSTIFICATION_ADDITION
if not self._message_logged:
self._message_logged = True
_LOGGER.warning(self._MESSAGE)

raise NotAcceptable

0 comments on commit 46da6d0

Please sign in to comment.