How to use the commoncode.fileset.is_included function in commoncode

To help you get started, we’ve selected a few commoncode 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 nexB / scancode-toolkit / tests / commoncode / test_ignore.py View on Github external
def test_fileset_is_included_with_default_ignore_does_not_skip_one_char_names(self):
        # use fileset directly to work on strings not locations
        from commoncode import fileset
        tests = [c for c in 'HFS+ Private Data'] + 'HFS+ Private Data'.split()
        result = [(t,
            fileset.is_included(t, excludes=ignore.default_ignores, includes={}))
            for t in tests]
        expected = [
            ('H', True),
            ('F', True),
            ('S', True),
            ('+', True),
            (' ', False),
            ('P', True),
            ('r', True),
            ('i', True),
            ('v', True),
            ('a', True),
            ('t', True),
            ('e', True),
            (' ', False),
            ('D', True),
github nexB / scancode-toolkit / tests / commoncode / test_fileset.py View on Github external
def test_is_included_dot_svn_with_excludes(self):
        incs = {'*/.svn/*': '.scanignore'}
        excs = {'*/.git/*': '.scanignore'}
        assert fileset.is_included('home/common/tools/elf/.svn/', incs, excs)
        assert fileset.is_included('home/common/tools/.svn/this', incs, excs)
        assert not fileset.is_included('home/common/.git/this', incs, excs)
github nexB / scancode-toolkit / tests / commoncode / test_fileset.py View on Github external
def test_is_included_dot_svn_with_excludes(self):
        incs = {'*/.svn/*': '.scanignore'}
        excs = {'*/.git/*': '.scanignore'}
        assert fileset.is_included('home/common/tools/elf/.svn/', incs, excs)
        assert fileset.is_included('home/common/tools/.svn/this', incs, excs)
        assert not fileset.is_included('home/common/.git/this', incs, excs)
github nexB / scancode-toolkit / tests / commoncode / test_fileset.py View on Github external
def test_is_included_in_fileset_2(self):
        incs = {'src*': '.scanignore'}
        excs = {'src/ab': '.scanignore'}
        assert not fileset.is_included(None, incs, excs)
        assert not fileset.is_included('', incs, excs)
        assert not fileset.is_included('/', incs, excs)
        assert fileset.is_included('/common/src/', incs, excs)
        assert not fileset.is_included('src/ab', incs, excs)
        assert fileset.is_included('src/abbab', incs, excs)
github nexB / scancode-toolkit / tests / commoncode / test_fileset.py View on Github external
def test_is_included_in_fileset(self):
        incs = {'/common/src/*': '.scanignore'}
        excs = {'/common/src/*.so':'.scanignore'}
        assert not fileset.is_included(None, incs, excs)
        assert not fileset.is_included('', incs, excs)
        assert not fileset.is_included('/', incs, excs)
        assert fileset.is_included('/common/src/', incs, excs)
        assert not fileset.is_included('/common/bin/', incs, excs)
github nexB / scancode-toolkit / tests / commoncode / test_fileset.py View on Github external
def test_is_included_is_included_exclusions(self):
        incs = {'/src/*': '.scanignore'}
        excs = {'/src/*.so':'.scanignore'}
        assert not fileset.is_included('/src/dist/build/mylib.so', incs, excs)
github nexB / scancode-toolkit / tests / commoncode / test_fileset.py View on Github external
def test_is_included_basic(self):
        assert fileset.is_included('/common/src/', {}, {})
        assert fileset.is_included('/common/src/', None, None)
        assert not fileset.is_included(None, None, None)
github nexB / scancode-toolkit / tests / commoncode / test_fileset.py View on Github external
def test_is_included_basic(self):
        assert fileset.is_included('/common/src/', {}, {})
        assert fileset.is_included('/common/src/', None, None)
        assert not fileset.is_included(None, None, None)
github nexB / scancode-toolkit / tests / commoncode / test_fileset.py View on Github external
def test_is_included_in_fileset(self):
        incs = {'/common/src/*': '.scanignore'}
        excs = {'/common/src/*.so':'.scanignore'}
        assert not fileset.is_included(None, incs, excs)
        assert not fileset.is_included('', incs, excs)
        assert not fileset.is_included('/', incs, excs)
        assert fileset.is_included('/common/src/', incs, excs)
        assert not fileset.is_included('/common/bin/', incs, excs)
github nexB / scancode-toolkit / src / scancode / plugin_ignore.py View on Github external
"""
        Keep only included and non-ignored Resources in the codebase.
        """

        if not (ignore or include):
            return

        excludes = {
            pattern: 'User ignore: Supplied by --ignore' for pattern in ignore
        }

        includes = {
            pattern: 'User include: Supplied by --include' for pattern in include
        }

        included = partial(is_included, includes=includes, excludes=excludes)

        rids_to_remove = set()
        rids_to_remove_add = rids_to_remove.add
        rids_to_remove_discard = rids_to_remove.discard

        # First, walk the codebase from the top-down and collect the rids of
        # Resources that can be removed.
        for resource in codebase.walk(topdown=True):
            if resource.is_root:
                continue
            resource_rid = resource.rid

            if not included(resource.path):
                for child in resource.children(codebase):
                    rids_to_remove_add(child.rid)
                rids_to_remove_add(resource_rid)