MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / is_included

Function is_included

src/commoncode/fileset.py:61–98  ·  view source on GitHub ↗

Return a True if `path` is included based on mapping of `includes` and `excludes` glob patterns. If the `path` is empty, return False. Matching is done based on the set of `includes` and `excludes` patterns maps of {fnmatch pattern: message}. If `includes` are provided they are tes

(path, includes=None, excludes=None)

Source from the content-addressed store, hash-verified

59
60
61def is_included(path, includes=None, excludes=None):
62 """
63 Return a True if `path` is included based on mapping of `includes` and
64 `excludes` glob patterns. If the `path` is empty, return False.
65
66 Matching is done based on the set of `includes` and `excludes` patterns maps
67 of {fnmatch pattern: message}. If `includes` are provided they are tested
68 first. The `excludes` are tested second if provided.
69
70 The ordering of the includes and excludes items does not matter and if a map
71 is empty, it is not used for matching.
72 """
73 if not path or not path.strip():
74 return False
75
76 if not includes and not excludes:
77 return True
78
79 includes = includes or {}
80 includes = {k: v for k, v in includes.items() if k}
81 excludes = excludes or {}
82 excludes = {k: v for k, v in excludes.items() if k}
83
84 if includes:
85 included = get_matches(path, includes, all_matches=False)
86 if TRACE:
87 logger.debug("in_fileset: path: %(path)r included:%(included)r" % locals())
88 if not included:
89 return False
90
91 if excludes:
92 excluded = get_matches(path, excludes, all_matches=False)
93 if TRACE:
94 logger.debug("in_fileset: path: %(path)r excluded:%(excluded)r ." % locals())
95 if excluded:
96 return False
97
98 return True
99
100
101def get_matches(path, patterns, all_matches=False):

Calls 2

get_matchesFunction · 0.70
debugMethod · 0.45