def build_subset(app, config): # Convert to list of docs to build docs_to_build = config.docs_to_build.split(',') # Exclude all documents which were not set as docs_to_build when build_docs were called exclude_docs = [ filename for filename in get_matching_files( app.srcdir, compile_matchers(docs_to_build)) ] docs = [ filename for filename in get_matching_files( app.srcdir, compile_matchers(exclude_docs)) ] app.config.exclude_patterns.extend(exclude_docs) # Get all docs that will be built docs = [ filename for filename in get_matching_files( app.srcdir, compile_matchers(exclude_docs)) ] if not docs: raise ValueError("No documents to build") print("Building a subset of the documents: {}".format(docs)) # Sphinx requires a master document, if there is a document name 'index' then we pick that index_docs = [doc for doc in docs if 'index' in doc] if index_docs: config.master_doc = index_docs[0].replace('.rst', '') else: config.master_doc = docs[0].replace('.rst', '')
def discover(self, exclude_paths: List[str] = []) -> Set[str]: """Find all document files in the source directory and put them in :attr:`docnames`. """ self.docnames = set() excludes = compile_matchers(exclude_paths + EXCLUDE_PATHS) for filename in get_matching_files(self.srcdir, excludes): # type: ignore 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
def get_matching_docs(dirname, exclude_matchers=()): """ Get all file names (without suffix) matching a suffix in a directory, recursively. Exclude files and dirs matching a pattern in *exclude_patterns*. """ for filename in get_matching_files(dirname, exclude_matchers): if not fnmatch.fnmatch(filename, "*.rst"): continue yield filename[:-4] for filename in get_matching_files(dirname+"/..", exclude_matchers): if not fnmatch.fnmatch(filename, "*.yay"): continue yield ':cfg:' + filename[:-4]
def discover(self, exclude_paths=[]): # type: (List[str]) -> Set[str] """Find all document files in the source directory and put them in :attr:`docnames`. """ self.docnames = set() excludes = compile_matchers(exclude_paths + EXCLUDE_PATHS) for filename in get_matching_files(self.srcdir, excludes): # type: ignore docname = self.path2doc(filename) if docname: if 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
def _get_matching_docs(dirname, suffixes, exclude_matchers=()): """Get all file names (without suffixes) matching a suffix in a directory, recursively. Exclude files and dirs matching a pattern in *exclude_patterns*. """ suffixpatterns = ['*' + s for s in suffixes] # The following two lines were added. exclude_matchers += compile_matchers(_config.CodeChat_excludes) for filename in get_matching_files(dirname, exclude_matchers): for suffixpattern in suffixpatterns: if fnmatch.fnmatch(filename, suffixpattern): yield filename[:-len(suffixpattern) + 1] break # The following code was added. if is_supported_language(filename): yield filename
def find_all_files(srcdir: str, exclude_patterns: List[str], suffixes=(".rst", )): """Adapted from ``sphinx.environment.BuildEnvironment.find_files``""" from sphinx.project import EXCLUDE_PATHS from sphinx.util import get_matching_files from sphinx.util.matching import compile_matchers exclude_patterns.extend(EXCLUDE_PATHS) excludes = compile_matchers(exclude_patterns) docnames = set() for filename in get_matching_files(srcdir, excludes): if not any(filename.endswith(s) for s in suffixes): continue if os.access(os.path.join(srcdir, filename), os.R_OK): filename = os.path.realpath(filename) docnames.add(filename) return docnames
def _get_matching_docs(dirname, suffixes, exclude_matchers=()): """Get all file names (without suffixes) matching a suffix in a directory, recursively. Exclude files and dirs matching a pattern in *exclude_patterns*. """ suffixpatterns = ['*' + s for s in suffixes] # The following line was added. source_suffixpatterns = (SUPPORTED_GLOBS | set(_config.CodeChat_lexer_for_glob.keys())) for filename in get_matching_files(dirname, exclude_matchers): for suffixpattern in suffixpatterns: if fnmatch.fnmatch(filename, suffixpattern): yield filename[:-len(suffixpattern) + 1] break # The following code was added. for source_suffixpattern in source_suffixpatterns: if fnmatch.fnmatch(filename, source_suffixpattern): yield filename break
def _get_matching_docs(dirname, suffixes, exclude_matchers=()): """Get all file names (without suffixes) matching a suffix in a directory, recursively. Exclude files and dirs matching a pattern in *exclude_patterns*. """ suffixpatterns = ['*' + s for s in suffixes] # The following line was added. source_suffixpatterns = ( SUPPORTED_GLOBS | set(_config.CodeChat_lexer_for_glob.keys()) ) for filename in get_matching_files(dirname, exclude_matchers): for suffixpattern in suffixpatterns: if fnmatch.fnmatch(filename, suffixpattern): yield filename[:-len(suffixpattern)+1] break # The following code was added. for source_suffixpattern in source_suffixpatterns: if fnmatch.fnmatch(filename, source_suffixpattern): yield filename break