Example #1
0
def main_standalone(argv=sys.argv[1:]):
    freeze_support()
    global ui  # global variable hack, will get rid of a bit later
    warnings.simplefilter('ignore')
    parsed_args = parse_args(argv, standalone=True)
    exit_code = 1

    generic_opts = parse_generic_options(parsed_args)
    import_id = parsed_args['import_id']

    if generic_opts['dry_run']:
        base_url = ''
        ui.info('Running in dry-run mode')
    else:
        try:
            base_url = get_endpoint(parsed_args['host'], PRED_API_V10)
            ui.info('Will be using API endpoint: {}'.format(base_url))
        except ValueError as e:
            ui.fatal(str(e))

    try:
        exit_code = run_batch_predictions(base_url=base_url,
                                          base_headers={},
                                          user=None,
                                          pwd=None,
                                          api_token=None,
                                          create_api_token=False,
                                          pid=None,
                                          lid=None,
                                          import_id=import_id,
                                          ui=ui,
                                          **generic_opts)
    except SystemError:
        pass
    except ShelveError as e:
        ui.error(str(e))
    except KeyboardInterrupt:
        ui.info('Keyboard interrupt')
    except Exception as e:
        ui.fatal(str(e))
    finally:
        ui.close()
        return exit_code
Example #2
0
def main_standalone(argv=sys.argv[1:]):
    freeze_support()
    global ui  # global variable hack, will get rid of a bit later
    warnings.simplefilter('ignore')
    parsed_args = parse_args(argv, standalone=True)
    exit_code = 1

    generic_opts = parse_generic_options(parsed_args)
    import_id = parsed_args['import_id']

    if generic_opts['dry_run']:
        base_url = ''
        ui.info('Running in dry-run mode')
    else:
        try:
            base_url = get_endpoint(parsed_args['host'],
                                    PRED_API_V10)
            ui.info('Will be using API endpoint: {}'.format(base_url))
        except ValueError as e:
            ui.fatal(str(e))

    try:
        exit_code = run_batch_predictions(
            base_url=base_url,
            base_headers={}, user=None, pwd=None,
            api_token=None, create_api_token=False,
            pid=None, lid=None, import_id=import_id, ui=ui, **generic_opts
        )
    except SystemError:
        pass
    except ShelveError as e:
        ui.error(str(e))
    except KeyboardInterrupt:
        ui.info('Keyboard interrupt')
    except Exception as e:
        ui.fatal(str(e))
    finally:
        ui.close()
        return exit_code
Example #3
0
def test_get_endpoint_raises():
    with pytest.raises(ValueError):
        get_endpoint('localhost', 'api/v2.0')
Example #4
0
def test_get_endpoint(host, api_version, result):
    assert get_endpoint(host, api_version) == result
Example #5
0
def _main(argv, deployment_aware=False):
    freeze_support()
    global ui  # global variable hack, will get rid of a bit later
    warnings.simplefilter('ignore')
    parsed_args = parse_args(argv, deployment_aware=deployment_aware)
    exit_code = 1

    generic_opts = parse_generic_options(parsed_args)

    # parse args
    if deployment_aware:
        deployment_id = parsed_args['deployment_id']
        verify_objectid(deployment_id)
        pid, lid = None, None
    else:
        ui.warning('batch_scoring command is deprecated. '
                   'Use batch_scoring_deployment_aware command instead.')
        deployment_id = None
        pid = parsed_args['project_id']
        lid = parsed_args['model_id']
        try:
            verify_objectid(pid)
            verify_objectid(lid)
        except ValueError as e:
            ui.fatal(str(e))

    # auth only ---
    datarobot_key = parsed_args.get('datarobot_key')
    api_token = parsed_args.get('api_token')
    create_api_token = parsed_args.get('create_api_token')
    user = parsed_args.get('user')
    pwd = parsed_args.get('password')

    if not generic_opts['dry_run']:
        user = user or ui.prompt_user()
        user = user.lower()
        user = user.strip()

        if not api_token and not pwd:
            pwd = ui.getpass()

    base_headers = {}
    if datarobot_key:
        base_headers['datarobot-key'] = datarobot_key
    # end auth ---

    if generic_opts['dry_run']:
        base_url = ''
        ui.info('Running in dry-run mode')
    else:
        try:
            base_url = get_endpoint(parsed_args['host'],
                                    parsed_args['api_version'])
            ui.info('Will be using API endpoint: {}'.format(base_url))
        except ValueError as e:
            ui.fatal(str(e))

    try:
        exit_code = run_batch_predictions(base_url=base_url,
                                          base_headers=base_headers,
                                          user=user,
                                          pwd=pwd,
                                          api_token=api_token,
                                          create_api_token=create_api_token,
                                          pid=pid,
                                          lid=lid,
                                          import_id=None,
                                          deployment_id=deployment_id,
                                          ui=ui,
                                          **generic_opts)
    except SystemError:
        pass
    except ShelveError as e:
        ui.error(str(e))
    except KeyboardInterrupt:
        ui.info('Keyboard interrupt')
    except UnicodeDecodeError as e:
        ui.error(str(e))
        if generic_opts.get('fast_mode'):
            ui.error("You are using --fast option, which uses a small sample "
                     "of data to figuring out the encoding of your file. You "
                     "can try to specify the encoding directly for this file "
                     "by using the encoding flag (e.g. --encoding utf-8). "
                     "You could also try to remove the --fast mode to auto-"
                     "detect the encoding with a larger sample size")
    except Exception as e:
        ui.fatal(str(e))
    finally:
        ui.close()
        return exit_code
Example #6
0
def main(argv=sys.argv[1:]):
    freeze_support()
    global ui  # global variable hack, will get rid of a bit later
    warnings.simplefilter('ignore')
    parsed_args = parse_args(argv)
    exit_code = 1

    generic_opts = parse_generic_options(parsed_args)

    # parse args
    pid = parsed_args['project_id']
    lid = parsed_args['model_id']
    try:
        verify_objectid(pid)
        verify_objectid(lid)
    except ValueError as e:
        ui.fatal(str(e))

    # auth only ---
    datarobot_key = parsed_args.get('datarobot_key')
    api_token = parsed_args.get('api_token')
    create_api_token = parsed_args.get('create_api_token')
    user = parsed_args.get('user')
    pwd = parsed_args.get('password')

    if not generic_opts['dry_run']:
        user = user or ui.prompt_user()
        user = user.strip()

        if not api_token and not pwd:
            pwd = ui.getpass()

    base_headers = {}
    if datarobot_key:
        base_headers['datarobot-key'] = datarobot_key
    # end auth ---

    if generic_opts['dry_run']:
        base_url = ''
        ui.info('Running in dry-run mode')
    else:
        try:
            base_url = get_endpoint(parsed_args['host'],
                                    parsed_args['api_version'])
            ui.info('Will be using API endpoint: {}'.format(base_url))
        except ValueError as e:
            ui.fatal(str(e))

    try:
        exit_code = run_batch_predictions(
            base_url=base_url, base_headers=base_headers, user=user, pwd=pwd,
            api_token=api_token, create_api_token=create_api_token,
            pid=pid, lid=lid, import_id=None, ui=ui, **generic_opts
        )
    except SystemError:
        pass
    except ShelveError as e:
        ui.error(str(e))
    except KeyboardInterrupt:
        ui.info('Keyboard interrupt')
    except UnicodeDecodeError as e:
        ui.error(str(e))
        if generic_opts.get('fast_mode'):
            ui.error("You are using --fast option, which uses a small sample "
                     "of data to figuring out the encoding of your file. You "
                     "can try to specify the encoding directly for this file "
                     "by using the encoding flag (e.g. --encoding utf-8). "
                     "You could also try to remove the --fast mode to auto-"
                     "detect the encoding with a larger sample size")
    except Exception as e:
        ui.fatal(str(e))
    finally:
        ui.close()
        return exit_code