Exemple #1
0
    def discover(
        self,
        exclude_paths: Iterable[str] = (),
        include_paths: Iterable[str] = ("**", )
    ) -> Set[str]:
        """Find all document files in the source directory and put them in
        :attr:`docnames`.
        """
        self.docnames = set()
        for filename in get_matching_files(
                self.srcdir,
                include_paths,
            [*exclude_paths] + EXCLUDE_PATHS,
        ):
            docname = self.path2doc(filename)
            if docname:
                if docname in self.docnames:
                    pattern = os.path.join(self.srcdir, docname) + '.*'
                    files = [relpath(f, self.srcdir) for f in glob(pattern)]
                    logger.warning(__(
                        'multiple files found for the document "%s": %r\n'
                        'Use %r for the build.'),
                                   docname,
                                   files,
                                   self.doc2path(docname),
                                   once=True)
                elif os.access(os.path.join(self.srcdir, filename), os.R_OK):
                    self.docnames.add(docname)
                else:
                    logger.warning(__("document not readable. Ignored."),
                                   location=docname)

        return self.docnames
Exemple #2
0
def test_get_matching_files_all_exclude_multiple(rootdir):
    files = get_matching_files(rootdir / "test-root", exclude_patterns=["**.html", "**.inc"])
    assert sorted(files) == [
        'Makefile', 'autodoc.txt', 'autodoc_target.py', 'bom.txt', 'conf.py',
        'extapi.txt', 'extensions.txt', 'file_with_special_#_chars.xyz', 'footnote.txt',
        'images.txt', 'img.foo.png', 'img.gif', 'img.pdf', 'img.png', 'includes.txt',
        'index.txt', 'lists.txt', 'markup.txt', 'math.txt', 'objects.txt', 'otherext.foo',
        'parsermod.py', 'rimg.png', 'special/api.h', 'special/code.py', 'subdir/excluded.txt',
        'subdir/images.txt', 'subdir/img.png', 'subdir/includes.txt', 'subdir/simg.png',
        'svgimg.pdf', 'svgimg.svg',
    ]
Exemple #3
0
def test_get_matching_files_all(rootdir):
    files = get_matching_files(rootdir / "test-root")
    assert sorted(files) == [
        'Makefile', '_templates/contentssb.html', '_templates/customsb.html',
        '_templates/layout.html', 'autodoc.txt', 'autodoc_target.py', 'bom.txt', 'conf.py',
        'extapi.txt', 'extensions.txt', 'file_with_special_#_chars.xyz', 'footnote.txt',
        'images.txt', 'img.foo.png', 'img.gif', 'img.pdf', 'img.png', 'includes.txt',
        'index.txt', 'lists.txt', 'literal.inc', 'literal_orig.inc', 'markup.txt', 'math.txt',
        'objects.txt', 'otherext.foo', 'parsermod.py', 'quotes.inc', 'rimg.png',
        'special/api.h', 'special/code.py', 'subdir/excluded.txt', 'subdir/images.txt',
        'subdir/img.png', 'subdir/include.inc', 'subdir/includes.txt', 'subdir/simg.png',
        'svgimg.pdf', 'svgimg.svg', 'tabs.inc', 'test.inc', 'wrongenc.inc',
    ]
Exemple #4
0
def test_get_matching_files_all_include_question_mark(rootdir):
    files = get_matching_files(rootdir / "test-root", include_patterns=["img.???"])
    assert sorted(files) == [
        'img.gif', 'img.pdf', 'img.png',
    ]
Exemple #5
0
def test_get_matching_files_all_include_prefix(rootdir):
    files = get_matching_files(rootdir / "test-root", include_patterns=["autodoc*"])
    assert sorted(files) == [
        'autodoc.txt', 'autodoc_target.py',
    ]
Exemple #6
0
def test_get_matching_files_all_include_nonexistent(rootdir):
    files = get_matching_files(rootdir / "test-root", include_patterns=["halibut/**"])
    assert sorted(files) == []
Exemple #7
0
def test_get_matching_files_all_include_multiple(rootdir):
    files = get_matching_files(rootdir / "test-root", include_patterns=["special/**", "subdir/**"])
    assert sorted(files) == [
        'special/api.h', 'special/code.py', 'subdir/excluded.txt', 'subdir/images.txt',
        'subdir/img.png', 'subdir/include.inc', 'subdir/includes.txt', 'subdir/simg.png',
    ]
Exemple #8
0
def test_get_matching_files_all_include_single(rootdir):
    files = get_matching_files(rootdir / "test-root", include_patterns=["subdir/**"])
    assert sorted(files) == [
        'subdir/excluded.txt', 'subdir/images.txt', 'subdir/img.png', 'subdir/include.inc',
        'subdir/includes.txt', 'subdir/simg.png',
    ]