How to use the identify.identify.tags_from_filename function in identify

To help you get started, we’ve selected a few identify 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 asottile / git-code-debt / git_code_debt / metrics / View on Github external
def get_metrics_from_stat(self, _, file_diff_stats):
        total_curses = 0
        curses_by_file_type = collections.defaultdict(int)

        for file_diff_stat in file_diff_stats:
            curses_added = count_curse_words(file_diff_stat.lines_added)
            curses_removed = count_curse_words(file_diff_stat.lines_removed)
            curses_changed = curses_added - curses_removed

            # Track total overall
            total_curses = total_curses + curses_changed

            # Track by file extension -> type mapping
            filename = file_diff_stat.filename.decode('UTF-8')
            tags = identify.tags_from_filename(filename) or {UNKNOWN}

            for tag in tags:
                curses_by_file_type[tag] += curses_changed

        # Yield overall metric and one per type of expected mapping types
        yield Metric('TotalCurseWords', total_curses)
        for tag, value in curses_by_file_type.items():
            if tag in ALL_TAGS and value:
                yield Metric('TotalCurseWords_{}'.format(tag), value)
github andreoliwa / nitpick / src / nitpick / View on Github external
def _find_subclasses(self, data, handled_tags, new_files_found):
        for possible_file in data.keys():
            found_subclasses = []
            for file_tag in identify.tags_from_filename(possible_file):
                handler_subclass = handled_tags.get(file_tag)
                if handler_subclass:

            for found_subclass in found_subclasses:
                new_files_found.update(self.file_field_pair(possible_file, found_subclass))