How to use the disdat.common function in disdat

To help you get started, we’ve selected a few disdat examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kyocum / disdat / disdat / infrastructure / dockerizer / context.template / bin / entrypoint.py View on Github external
sys.exit(os.EX_IOERR)

    # Pull the remote branch into the local branch or download individual items
    try:
        if not args.no_pull:
            disdat.api.pull(args.branch, localize=not incremental_pull)
    except Exception as e:
        _logger.error("Failed to pull and localize all bundles from context {} due to {}".format(args.branch, e))
        sys.exit(os.EX_IOERR)

    # If specified, decode the ordinary 'key:value' strings into a dictionary of tags.
    input_tags = disdat.common.parse_args_tags(args.input_tag)
    output_tags = disdat.common.parse_args_tags(args.output_tag)

    # Convert string of pipeline args into dictionary for api.apply
    deser_user_params = disdat.common.parse_params(args.pipe_cls, args.pipeline_args)

    # If the user wants final and intermediate, then inc push.
    if not args.no_push and not args.no_push_intermediates:
        incremental_push = True
    else:
        incremental_push = False

    try:
        result = disdat.api.apply(args.branch,
                                  args.pipe_cls,
                                  output_bundle=args.output_bundle,
                                  input_tags=input_tags,
                                  output_tags=output_tags,
                                  params=deser_user_params,
                                  output_bundle_uuid=args.output_bundle_uuid,
                                  force=args.force,
github kyocum / disdat / disdat / dockerize.py View on Github external
None or if subprocess has output

    """
    retval = 0

    dot_file_path = os.path.join(docker_context, dot_file_name)
    if disdat_config.parser.has_option(_MODULE_NAME, option_name):
        dot_file = os.path.expanduser(disdat_config.parser.get(_MODULE_NAME, option_name))
        shutil.copy(dot_file, dot_file_path)
        print("Copying dot file {} into {}".format(dot_file, docker_context))
    else:
        touch_command = [
            'touch',
            dot_file_path
        ]
        retval = disdat.common.do_subprocess(touch_command, cli)

    return retval
github kyocum / disdat / disdat / infrastructure / dockerizer / context.template / bin / entrypoint.py View on Github external
pipeline_parser.add_argument(
        '--force',
        action='store_true',
        help='Force recomputation of the last task.',
    )

    pipeline_parser.add_argument(
        '--force-all',
        action='store_true',
        help='Force recomputation of all upstream tasks.',
    )

    pipeline_parser.add_argument(
        'pipe_cls',
        default=None,
        type=disdat.common.load_class,
        help=add_argument_help_string("Name of the pipeline class to run, e.g., 'package.module.ClassName'"),
    )

    pipeline_parser.add_argument(
        "pipeline_args",
        nargs=argparse.REMAINDER,
        type=str,
        help="Optional set of parameters for this pipe '--parameter value'"
    )

    args = parser.parse_args(input_args)

    log_level = logging.INFO

    log.enable(level=log_level)  # TODO: Add configurable verbosity
github kyocum / disdat / disdat / dockerize.py View on Github external
build_command.append('CONFIG_ROOT={}'.format(config_dir))
        if sagemaker:
            build_command.append('SAGEMAKER_TRAIN_IMAGE_NAME={}'.format(disdat.common.make_sagemaker_project_image_name(setup_file)))
            build_command.append('sagemaker')
        retval = disdat.common.do_subprocess(build_command, cli)
        if retval: return retval

    if push:
        docker_client = docker.from_env()

        repository_name_prefix = None

        if disdat_config.parser.has_option('docker', 'repository_prefix'):
            repository_name_prefix = disdat_config.parser.get('docker', 'repository_prefix')
        if sagemaker:
            repository_name = disdat.common.make_sagemaker_project_repository_name(repository_name_prefix, setup_file)
            pipeline_image_name = disdat.common.make_sagemaker_project_image_name(setup_file)
        else:
            repository_name = disdat.common.make_project_repository_name(repository_name_prefix, setup_file)

        # Figure out the fully-qualified repository name, i.e., the name
        # including the registry.
        if disdat_config.parser.has_option('docker','registry'):
            registry_name = disdat_config.parser.get('docker', 'registry').strip('/')
            if registry_name == '*ECR*':
                policy_resource_name = None
                if disdat_config.parser.has_option('docker', 'ecr_policy'):
                    policy_resource_name = disdat_config.parser.get('docker', 'ecr_policy')
                fq_repository_name = aws.ecr_create_fq_respository_name(
                    repository_name,
                    policy_resource_package=disdat.resources,
                    policy_resource_name=policy_resource_name
github kyocum / disdat / disdat / dockerize.py View on Github external
build_command.append('sagemaker')
        retval = disdat.common.do_subprocess(build_command, cli)
        if retval: return retval

    if push:
        docker_client = docker.from_env()

        repository_name_prefix = None

        if disdat_config.parser.has_option('docker', 'repository_prefix'):
            repository_name_prefix = disdat_config.parser.get('docker', 'repository_prefix')
        if sagemaker:
            repository_name = disdat.common.make_sagemaker_project_repository_name(repository_name_prefix, setup_file)
            pipeline_image_name = disdat.common.make_sagemaker_project_image_name(setup_file)
        else:
            repository_name = disdat.common.make_project_repository_name(repository_name_prefix, setup_file)

        # Figure out the fully-qualified repository name, i.e., the name
        # including the registry.
        if disdat_config.parser.has_option('docker','registry'):
            registry_name = disdat_config.parser.get('docker', 'registry').strip('/')
            if registry_name == '*ECR*':
                policy_resource_name = None
                if disdat_config.parser.has_option('docker', 'ecr_policy'):
                    policy_resource_name = disdat_config.parser.get('docker', 'ecr_policy')
                fq_repository_name = aws.ecr_create_fq_respository_name(
                    repository_name,
                    policy_resource_package=disdat.resources,
                    policy_resource_name=policy_resource_name
                )
            else:
                fq_repository_name = '{}/{}'.format(registry_name, repository_name)
github kyocum / disdat / disdat / pipe_base.py View on Github external
np.uint64,
            np.float16,
            np.float32,
            np.float64,
            six.binary_type,
            six.text_type,
            np.unicode_,
            np.string_
        )

        frames = []

        if val is None:
            """ None's stored as json.dumps([None]) or '[null]' """
            presentation = hyperframe_pb2.JSON
            frames.append(data_context.convert_scalar2frame(hfid, common.DEFAULT_FRAME_NAME + ':0', val))

        elif isinstance(val, HyperFrameRecord):
            presentation = hyperframe_pb2.HF
            frames.append(FrameRecord.make_hframe_frame(hfid, pipe.human_id(), [val]))

        elif isinstance(val, np.ndarray) or isinstance(val, list):
            presentation = hyperframe_pb2.TENSOR
            if isinstance(val, list):
                val = np.array(val)
            frames.append(data_context.convert_serieslike2frame(hfid, common.DEFAULT_FRAME_NAME + ':0', val))

        elif isinstance(val, tuple):
            presentation = hyperframe_pb2.ROW
            val = np.array(val)
            frames.append(data_context.convert_serieslike2frame(hfid, common.DEFAULT_FRAME_NAME + ':0', val))
github kyocum / disdat / disdat / dockerize.py View on Github external
pipeline_root: Root of the Python source tree containing the
        setuptools-style setup.py file.
        config_dir (str):  Configuration of image (.deb, requires.txt, etc.)
        os_type (str): OS type string
        os_version (str): Version of OS
        build (bool): Build the image (default True)
        push (bool): Push to registry listed in Disdat config file
        sagemaker (bool): Build a container for 'train' or 'serve' in SageMaker
        cli (bool): Whether dockerize was called from the CLI (True) or an API (False -- default)

    Returns:
        (int): 0 equals success, >0 for error

    """

    disdat_config = disdat.common.DisdatConfig.instance()

    # Get configuration parameters
    image_os_type = os_type if os_type is not None else disdat_config.parser.get(_MODULE_NAME, 'os_type')
    image_os_version = os_version if os_version is not None else disdat_config.parser.get(_MODULE_NAME, 'os_version')
    docker_context = None

    if docker_context is None:
        docker_context = tempfile.mkdtemp(suffix=_MODULE_NAME)
    docker_makefile = os.path.join(_DOCKERIZER_ROOT, 'Makefile')
    _logger.debug('Using Docker context {}'.format(docker_context))

    # Populate the Docker context with the template containing dockerfiles,
    # entrypoints, etc.
    rsync_command = [
        'rsync',
        '-aq',  # Archive mode, no non-error messages
github kyocum / disdat / disdat / run.py View on Github external
Produce the fully qualified docker repo name.

    Args:
        is_sagemaker (bool): for sagemaker image
        pipeline_setup_file (str): the path to the setup.py file used to dockerize this pipeline

    Returns:
        (str): The fully qualified docker image repository name
    """
    disdat_config = DisdatConfig.instance()

    repository_prefix = None
    if disdat_config.parser.has_option('docker', 'repository_prefix'):
        repository_prefix = disdat_config.parser.get('docker', 'repository_prefix')
    if is_sagemaker:
        repository_name = common.make_sagemaker_project_repository_name(repository_prefix, pipeline_setup_file)
    else:
        repository_name = common.make_project_repository_name(repository_prefix, pipeline_setup_file)

    # Figure out the fully-qualified repository name, i.e., the name
    # including the registry.
    registry_name = disdat_config.parser.get('docker', 'registry').strip('/')
    if registry_name == '*ECR*':
        fq_repository_name = aws.ecr_get_fq_repository_name(repository_name)
    else:
        fq_repository_name = '{}/{}'.format(registry_name, repository_name)

    return fq_repository_name
github kyocum / disdat / disdat / fs.py View on Github external
before = _parse_date(args.before)
        if before is None:
            return

    for f in fs.ls(arg,
                   args.print_tags,
                   args.intermediates,
                   args.roots,
                   args.verbose,
                   args.print_args,
                   uuid=args.uuid,
                   committed=committed,
                   before=before,
                   after=after,
                   maxbydate=args.latest_by_date,
                   tags=common.parse_args_tags(args.tag)):
        print(f)
github kyocum / disdat / disdat / hyperframe.py View on Github external
else:
            raise ValueError("Bad file paths -- cannot determine link type: example path {}".format(file_paths[0]))

        if link_type is FileLinkRecord:
            to_remove = "file://" + local_managed_path
        elif link_type is S3LinkRecord:
            assert remote_managed_path.startswith('s3://')
            to_remove = remote_managed_path

        frame = FrameRecord(name=name,
                            hframe_uuid=hfid,
                            type='LINK')

        frame_uuid = frame.get_uuid()

        file_paths = [common.BUNDLE_URI_SCHEME + os.path.relpath(fn, to_remove) for fn in file_paths]
        links = [link_type(frame_uuid, None, fn) for fn in file_paths]

        return frame.add_links(links)