Skip to content

Commit

Permalink
Merge pull request #5 from RasaHQ/scoped-imports
Browse files Browse the repository at this point in the history
scoped imports
  • Loading branch information
wochinge committed Feb 13, 2019
2 parents 4417304 + 5d5d28c commit 49a8894
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 80 deletions.
21 changes: 12 additions & 9 deletions rasa/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@
import argparse
import logging

import rasa_core.utils

from rasa.cli import scaffold, run, train, configure, interactive, shell, test, \
show, data
from rasa.utils import print_versions
from rasa import version
from rasa.cli import (scaffold, run, train, configure, interactive, shell, test,
show, data)
from rasa_core.cli.arguments import add_logging_option_arguments
from rasa_core.utils import configure_colored_logging

logger = logging.getLogger(__name__)


def create_argument_parser():
"""Parse all the command line arguments for the training script."""

parser = argparse.ArgumentParser(
prog="rasa",
description='Rasa command line interface. Rasa allows you to build '
Expand All @@ -26,7 +25,7 @@ def create_argument_parser():
help="Print installed Rasa version.")

parent_parser = argparse.ArgumentParser(add_help=False)
rasa_core.utils.add_logging_option_arguments(parent_parser)
add_logging_option_arguments(parent_parser)
parent_parsers = [parent_parser]

subparsers = parser.add_subparsers(help='Rasa commands')
Expand All @@ -44,16 +43,20 @@ def create_argument_parser():
return parser


def print_version():
print("Rasa", version.__version__)


def main():
# Running as standalone python application
arg_parser = create_argument_parser()
cmdline_arguments = arg_parser.parse_args()

if hasattr(cmdline_arguments, "func"):
rasa_core.utils.configure_colored_logging(cmdline_arguments.loglevel)
configure_colored_logging(cmdline_arguments.loglevel)
cmdline_arguments.func(cmdline_arguments)
elif cmdline_arguments.version:
print_versions()
print_version()
else:
# user has not provided a subcommand, let's print the help
logger.error("No command specified.")
Expand Down
2 changes: 1 addition & 1 deletion rasa/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import rasa.cli.run
import rasa.cli.train
import rasa.cli.train
5 changes: 3 additions & 2 deletions rasa/cli/configure.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import os

import questionary
import rasa_core.utils
from rasa_core.utils import print_error, print_success


def add_subparser(subparsers):
Expand All @@ -17,6 +15,9 @@ def add_subparser(subparsers):


def configure_channel(channel):
from rasa_core.utils import print_error, print_success
import rasa_core.utils

credentials_file = questionary.text(
"Please enter a path where to store the credentials file",
default="credentials.yml").ask()
Expand Down
7 changes: 3 additions & 4 deletions rasa/cli/data.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from rasa_nlu import convert


def add_subparser(subparsers, parents):
from rasa_nlu import convert

data_parser = subparsers.add_parser(
"data",
conflict_handler="resolve",
Expand All @@ -13,7 +12,7 @@ def add_subparser(subparsers, parents):
"convert", help="Convert Rasa data between different formats.")

convert_subparsers = convert_parser.add_subparsers()
convert_nlu_parser=convert_subparsers.add_parser(
convert_nlu_parser = convert_subparsers.add_parser(
"nlu", help="Convert NLU training data between markdown and json.")

convert.add_arguments(convert_parser)
Expand Down
7 changes: 3 additions & 4 deletions rasa/cli/interactive.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import os
import shutil

import rasa.cli as cli
from rasa.model import unpack_model

from rasa_core.train import do_interactive_learning


def add_subparser(subparsers, parents):
interactive_parser = subparsers.add_parser(
Expand All @@ -32,7 +29,9 @@ def _add_interactive_arguments(parser):


def interactive(args):
args.finetune = False # Don't support finetuning
from rasa_core.train import do_interactive_learning

args.finetune = False # Don't support finetuning

zipped_model = cli.train.train(args)
model_path, core_path, nlu_path = unpack_model(zipped_model,
Expand Down
27 changes: 16 additions & 11 deletions rasa/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,9 @@
import logging
import os
import shutil
import tempfile

from rasa_core.broker import PikaProducer
from rasa_core.interpreter import RasaNLUInterpreter
import rasa_core.run
from rasa_core.tracker_store import TrackerStore
from rasa_core.utils import AvailableEndpoints
import rasa_nlu.server

from rasa.cli.default_arguments import add_model_param
from rasa.model import get_latest_model, get_model, DEFAULT_MODELS_PATH
from rasa.model import DEFAULT_MODELS_PATH, get_latest_model, get_model

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -46,7 +38,6 @@ def add_subparser(subparsers, parents):
help="Run a trained NLU model"
)

rasa_nlu.server.add_run_arguments(nlu_subparser)
_add_nlu_arguments(nlu_subparser)
nlu_subparser.set_defaults(func=run_nlu)

Expand All @@ -62,7 +53,9 @@ def add_subparser(subparsers, parents):


def add_run_arguments(parser):
rasa_core.run.add_run_options(parser)
from rasa_core.cli.run import add_run_arguments

add_run_arguments(parser)
add_model_param(parser)

parser.add_argument(
Expand All @@ -72,6 +65,9 @@ def add_run_arguments(parser):


def _add_nlu_arguments(parser):
from rasa_nlu.cli.server import add_server_arguments

add_server_arguments(parser)
parser.add_argument('--path',
default=DEFAULT_MODELS_PATH,
help="working directory of the server. Models are"
Expand All @@ -82,6 +78,9 @@ def _add_nlu_arguments(parser):


def run_nlu(args):
import rasa_nlu.server
import tempfile

model = get_latest_model(args.model)
working_directory = tempfile.mkdtemp()
model_path = model.unpack_model(model, working_directory)
Expand All @@ -97,6 +96,12 @@ def run_sdk(args):


def run(args):
from rasa_core.broker import PikaProducer
from rasa_core.interpreter import RasaNLUInterpreter
import rasa_core.run
from rasa_core.tracker_store import TrackerStore
from rasa_core.utils import AvailableEndpoints

model_paths = get_model(args.model, subdirectories=True)

if model_paths is None:
Expand Down
10 changes: 6 additions & 4 deletions rasa/cli/scaffold.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import os
from distutils.dir_util import copy_tree

import questionary
from rasa.cli import train
from rasa_core.utils import print_success
from rasa_core import constants

from rasa.cli.shell import shell
from rasa.cli.train import create_default_output_path

Expand All @@ -24,6 +20,8 @@ def scaffold_path():


def print_train_or_instructions(args, path):
from rasa_core.utils import print_success

print_success("Your bot initial_project is ready to go!")
should_train = questionary.confirm("Do you want me to train an initial "
"model for the bot?").ask()
Expand All @@ -44,6 +42,8 @@ def print_train_or_instructions(args, path):


def print_run_or_instructions(args, path):
from rasa_core import constants

should_run = questionary.confirm("Do you want me to run the trained model "
"in the command line?").ask()

Expand All @@ -63,6 +63,8 @@ def print_run_or_instructions(args, path):


def init_project(args, path):
from distutils.dir_util import copy_tree

copy_tree(scaffold_path(), path)

print("Created project directory at '{}'.".format(os.path.abspath(path)))
Expand Down
13 changes: 8 additions & 5 deletions rasa/cli/show.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import argparse
import os

import rasa_core.visualize as visualize

from rasa.cli.default_arguments import add_domain_param, add_stories_param, \
add_config_param
from rasa.cli.default_arguments import (
add_config_param, add_domain_param,
add_stories_param)
from rasa.model import DEFAULTS_NLU_DATA_PATH


Expand All @@ -30,12 +29,16 @@ def add_subparser(subparsers, parents):


def add_core_visualization_params(parser):
visualize.add_visualization_arguments(parser)
from rasa_core.cli.visualization import add_visualization_arguments

add_visualization_arguments(parser)
add_domain_param(parser)
add_stories_param(parser)


def show(args):
import rasa_core.visualize as visualize

args.config = [args.config]
args.url = None

Expand Down
21 changes: 11 additions & 10 deletions rasa/cli/test.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
import argparse
import logging
import os
import tempfile

import rasa_core.evaluate
import rasa_nlu
from rasa_core.utils import AvailableEndpoints
from rasa_nlu import utils as nlu_utils
from rasa_core.interpreter import NaturalLanguageInterpreter
from rasa_core.agent import Agent

from rasa.cli.default_arguments import add_model_param, add_stories_param
from rasa.model import get_model, get_latest_model, DEFAULT_MODELS_PATH
from rasa.model import DEFAULT_MODELS_PATH, get_latest_model, get_model

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -54,8 +46,9 @@ def add_subparser(subparsers, parents):


def _add_core_arguments(parser):
rasa_core.evaluate.add_args_to_parser(parser)
from rasa_core.cli.evaluation import add_evaluation_arguments

add_evaluation_arguments(parser)
add_model_param(parser, "Core")
add_stories_param(parser, "test")

Expand Down Expand Up @@ -117,6 +110,12 @@ def _add_nlu_subparser_arguments(parser):


def test_core(args, model_path=None):
import rasa_core.evaluate
from rasa_nlu import utils as nlu_utils
from rasa_core.utils import AvailableEndpoints
from rasa_core.interpreter import NaturalLanguageInterpreter
from rasa_core.agent import Agent

logging.basicConfig(level=args.loglevel)
_endpoints = AvailableEndpoints.read_endpoints(
args.endpoints)
Expand Down Expand Up @@ -159,6 +158,8 @@ def test_core(args, model_path=None):


def test_nlu(args, model_path=None):
import rasa_nlu

model_path = model_path or args.model
if model_path:
unpacked_model = get_model(args.model)
Expand Down

0 comments on commit 49a8894

Please sign in to comment.