File: grouper.py

package info (click to toggle)
pycallgraph 1.1.3-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 416 kB
  • sloc: python: 1,925; makefile: 47
file content (26 lines) | stat: -rw-r--r-- 805 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from fnmatch import fnmatch


class Grouper(object):
    """Group module names.

    By default, objects are grouped by their top-level module name. Additional
    groups can be specified with the groups list and all objects will be
    matched against it.
    """

    def __init__(self, groups=None):
        if groups is None:
            groups = []

        self.groups = groups

    def __call__(self, full_name=None):
        for pattern in self.groups:
            if fnmatch(full_name, pattern):
                if pattern[-2:] == ".*":
                    # a wildcard in the middle is probably meaningful, while at
                    # the end, it's only noise and can be removed
                    return pattern[:-2]
                return pattern
        return full_name.split('.', 1)[0]