Skip to content

Commit

Permalink
Tests pass even when fire and numpydoc are not installed. (#411)
Browse files Browse the repository at this point in the history
Import fire and numpydoc library lazily in cli.py. This way, there is
no error when in helper.py when these libraries are not installed.
  • Loading branch information
benjamin-work authored and ottonemo committed Dec 13, 2018
1 parent 9ce4cb4 commit 6774e65
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions skorch/cli.py
Expand Up @@ -14,18 +14,6 @@
from sklearn.pipeline import FeatureUnion
from sklearn.pipeline import Pipeline

try:
from fire.parser import DefaultParseValue
except ImportError:
raise ImportError("Using skorch cli helpers requires the fire library,"
" you can install it with pip: pip install fire.")

try:
from numpydoc.docscrape import ClassDoc
except ImportError:
raise ImportError("Using skorch cli helpers requires the numpydoc library,"
" you can install it with pip: pip install numpydoc.")


__all__ = ['parse_args']

Expand Down Expand Up @@ -98,6 +86,8 @@ def _substitute_default(s, new_value):


def _parse_args_kwargs(params):
from fire.parser import DefaultParseValue

args = ()
kwargs = {}
for param in _param_split(params):
Expand Down Expand Up @@ -239,6 +229,8 @@ def _get_help_for_params(params, prefix='--', defaults=None, indent=2):

def _get_help_for_estimator(prefix, estimator, defaults=None):
"""Yield help lines for the given estimator and prefix."""
from numpydoc.docscrape import ClassDoc

defaults = defaults or {}
estimator = _extract_estimator_cls(estimator)
yield "<{}> options:".format(estimator.__name__)
Expand Down Expand Up @@ -321,6 +313,17 @@ def parse_args(kwargs, defaults=None):
the estimator and return it.
"""
try:
import fire
except ImportError:
raise ImportError("Using skorch cli helpers requires the fire library,"
" you can install it with pip: pip install fire.")
try:
import numpydoc.docscrape
except ImportError:
raise ImportError("Using skorch cli helpers requires the numpydoc library,"
" you can install it with pip: pip install numpydoc.")

defaults = defaults or {}

def print_help_and_exit(estimator):
Expand Down

0 comments on commit 6774e65

Please sign in to comment.