<commit_before># Copyright 2015-2017 Autodesk Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import print_function

import collections
import os
import sys
import textwrap

import yaml
import docker

_dockerclient = None


def get_client_api():
    return get_client().api


def get_client():
    global _dockerclient

    if _dockerclient is None:
        _dockerclient = docker.from_env(version='auto')

    return _dockerclient


def list_image_defs(args, defs):
    from . import imagedefs

    print('TARGETS in `%s`' % args.makefile)
    for item in sorted(defs.ymldefs.keys()):
        if item in imagedefs.SPECIAL_FIELDS:
            continue
        print(' *', item)
    return


def generate_name(image, args):
    repo_base = args.repository

    if repo_base is not None:
        if repo_base[-1] not in ':/':
            repo_base += '/'
        repo_name = repo_base + image
    else:
        repo_name = image

    if args.tag:
        if ':' in repo_name:
            repo_name += '-'+args.tag
        else:
            repo_name += ':'+args.tag

    return repo_name


def get_build_targets(args, defs):
    if args.requires or args.name:
        # Assemble a custom target from requirements
        assert args.requires and args.name
        assert args.name not in defs.ymldefs
        defs.ymldefs[args.name] = {'requires': args.requires,
                                   '_sourcefile': "command line arguments"}
        targets = [args.name]

    elif args.all:
        # build all targets in the file
        assert len(args.TARGETS) == 0, "Pass either a list of targets or `--all`, not both"
        if defs.all_targets is not None:
            targets = defs.all_targets
        else:
            targets = list(defs.ymldefs.keys())
    else:
        # build the user-specified targets
        targets = args.TARGETS

    return targets


def build_targets(args, defs, targets):
    if args.no_build:
        client = None
    else:
        client = get_client_api()
    built, warnings = [], []
    builders = [defs.generate_build(t, generate_name(t, args), rebuilds=args.bust_cache)
                for t in targets]
    for b in builders:
        b.build(client,
                nobuild=args.no_build,
                usecache=not args.no_cache,
                pull=args.pull)
        if not args.no_build:
            print('  docker-make built:', b.targetname)

        if args.print_dockerfiles or args.no_build:
            b.write_dockerfile(args.dockerfile_dir)

        built.append(b.targetname)
        if args.push_to_registry and not args.nobuild:
            success, w = push(client, b.targetname)
            warnings.extend(w)
            if not success:<commit_msg>Issue #16 - Fix broken push-to-registry option by correcting typo in dockermake/utils.py build_targets(). 'args.nobuild' was referenced instead of 'args.no_build'<commit_after># Copyright 2015-2017 Autodesk Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import print_function

import collections
import os
import sys
import textwrap

import yaml
import docker

_dockerclient = None


def get_client_api():
    return get_client().api


def get_client():
    global _dockerclient

    if _dockerclient is None:
        _dockerclient = docker.from_env(version='auto')

    return _dockerclient


def list_image_defs(args, defs):
    from . import imagedefs

    print('TARGETS in `%s`' % args.makefile)
    for item in sorted(defs.ymldefs.keys()):
        if item in imagedefs.SPECIAL_FIELDS:
            continue
        print(' *', item)
    return


def generate_name(image, args):
    repo_base = args.repository

    if repo_base is not None:
        if repo_base[-1] not in ':/':
            repo_base += '/'
        repo_name = repo_base + image
    else:
        repo_name = image

    if args.tag:
        if ':' in repo_name:
            repo_name += '-'+args.tag
        else:
            repo_name += ':'+args.tag

    return repo_name


def get_build_targets(args, defs):
    if args.requires or args.name:
        # Assemble a custom target from requirements
        assert args.requires and args.name
        assert args.name not in defs.ymldefs
        defs.ymldefs[args.name] = {'requires': args.requires,
                                   '_sourcefile': "command line arguments"}
        targets = [args.name]

    elif args.all:
        # build all targets in the file
        assert len(args.TARGETS) == 0, "Pass either a list of targets or `--all`, not both"
        if defs.all_targets is not None:
            targets = defs.all_targets
        else:
            targets = list(defs.ymldefs.keys())
    else:
        # build the user-specified targets
        targets = args.TARGETS

    return targets


def build_targets(args, defs, targets):
    if args.no_build:
        client = None
    else:
        client = get_client_api()
    built, warnings = [], []
    builders = [defs.generate_build(t, generate_name(t, args), rebuilds=args.bust_cache)
                for t in targets]
    for b in builders:
        b.build(client,
                nobuild=args.no_build,
                usecache=not args.no_cache,
                pull=args.pull)
        if not args.no_build:
            print('  docker-make built:', b.targetname)

        if args.print_dockerfiles or args.no_build:
            b.write_dockerfile(args.dockerfile_dir)

        built.append(b.targetname)
        if args.push_to_registry and not args.no_build:
            success, w = push(client, b.targetname)
            warnings.extend(w)
            if not success:
{'fraction_non_alphanumeric': 0.08663441185364379, 'fraction_numerical': 0.004535833081342607, 'mean_word_length': 2.36984207845135, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4290176', 'n_tokens_mistral': 2015, 'n_tokens_neox': 1889, 'n_words': 616}