<commit_before>#!/usr/bin/env python3
from yaml import load


class ComposePlantuml:

    def __init__(self):
        pass

    def parse(self, data):
        return load(data)

    def link_graph(self, compose):
        result = 'skinparam componentStyle uml2\n'

        for component in sorted(self.components(compose)):
            result += '[{0}]\n'.format(component)
        for source, destination in sorted(self.links(compose)):
            result += '[{0}] --> [{1}]\n'.format(source, destination)
        for source, destination in sorted(self.dependencies(compose)):
            result += '[{0}] ..> [{1}] : depends on\n'.format(source, destination)
        return result.strip()

    def boundaries(self, compose):
        result = 'skinparam componentStyle uml2\n'

        result += 'cloud system {\n'
        for component in sorted(self.components(compose)):
            result += '  [{0}]\n'.format(component)
        result += '}\n'
        volume_registry = {}
        for volume in sorted(self.volumes(compose)):
            result += 'database {0}'.format(volume) + ' {\n'
            for usage in sorted(self.volume_usage(compose, volume)):
                registry_name = 'volume_{0}'.format(len(volume_registry.keys()) + 1)
                volume_registry['{0}.{1}'.format(volume, usage)] = registry_name
                result += '  [{0}] as {1}\n'.format(usage, registry_name)
            result += '}\n'

        for service, host, container in sorted(self.ports(compose)):
            port = host
            if container is not None:
                port = '{0} : {1}'.format(host, container)
            result += '[{0}] --> {1}\n'.format(service, port)

        for volume in sorted(self.volumes(compose)):
            for service, volume_path in sorted(self.service_using_path(compose, volume)):
                name = volume_path
                if '{0}.{1}'.format(volume, volume_path) in volume_registry:
                    name = volume_registry['{0}.{1}'.format(volume, volume_path)]
                result += '[{0}] --> {1}\n'.format(service, name)
        return result.strip()

    @staticmethod
    def components(compose):
        if 'version' not in compose:
            return [component for component in compose]
        return [component for component in compose.get('services', [])]

    @staticmethod
    def links(compose):
        result = []
        components = compose if 'version' not in compose else compose.get('services', {})

        for component_name, component in components.items():
            for link in component.get('links', []):
                link = link if ':' not in link else link.split(':')[0]
                result.append((component_name, link))
        return result

    @staticmethod<commit_msg>just use volumes once<commit_after>#!/usr/bin/env python3
from yaml import load


class ComposePlantuml:

    def __init__(self):
        pass

    def parse(self, data):
        return load(data)

    def link_graph(self, compose):
        result = 'skinparam componentStyle uml2\n'

        for component in sorted(self.components(compose)):
            result += '[{0}]\n'.format(component)
        for source, destination in sorted(self.links(compose)):
            result += '[{0}] --> [{1}]\n'.format(source, destination)
        for source, destination in sorted(self.dependencies(compose)):
            result += '[{0}] ..> [{1}] : depends on\n'.format(source, destination)
        return result.strip()

    def boundaries(self, compose):
        result = 'skinparam componentStyle uml2\n'

        result += 'cloud system {\n'
        for component in sorted(self.components(compose)):
            result += '  [{0}]\n'.format(component)
        result += '}\n'
        volume_registry = {}

        for volume in sorted(self.volumes(compose)):
            result += 'database {0}'.format(volume) + ' {\n'
            for path in sorted(self.volume_usage(compose, volume)):
                id = self.volume_identifier(volume, path)

                if id in volume_registry:
                    continue
                volume_registry[id] = 'volume_{0}'.format(len(volume_registry.keys()) + 1)
                result += '  [{0}] as {1}\n'.format(path, volume_registry[id])

            result += '}\n'

        for service, host, container in sorted(self.ports(compose)):
            port = host
            if container is not None:
                port = '{0} : {1}'.format(host, container)
            result += '[{0}] --> {1}\n'.format(service, port)

        for volume in sorted(self.volumes(compose)):
            for service, volume_path in sorted(self.service_using_path(compose, volume)):
                name = volume_path
                if '{0}.{1}'.format(volume, volume_path) in volume_registry:
                    name = volume_registry['{0}.{1}'.format(volume, volume_path)]
                result += '[{0}] --> {1}\n'.format(service, name)
        return result.strip()

    @staticmethod
    def volume_identifier(volume, path):
        return '{0}.{1}'.format(volume, path)

    @staticmethod
    def components(compose):
        if 'version' not in compose:
            return [component for component in compose]
        return [component for component in compose.get('services', [])]

    @staticmethod
    def links(compose):
        result = []
        components = compose if 'version' not in compose else compose.get('services', {})

        for component_name, component in components.items():
            for link in component.get('links', []):
                link = link if ':' not in link else link.split(':')[0]
                result.append((component_name, link))
        return result

    @staticmethod
{'fraction_non_alphanumeric': 0.13864152261218787, 'fraction_numerical': 0.009429020429544265, 'mean_word_length': 2.2526973310618965, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2106351', 'n_tokens_mistral': 1626, 'n_tokens_neox': 1551, 'n_words': 412}