Пример #1
0
    def test_get_logger(self, logging_mock):
        logging_mock.getLogger().handlers = []

        self.assertTrue(get_logger(level=10))
        logging_mock.getLogger.assert_called_with("fhdoc")
        logging_mock.getLogger().setLevel.assert_called_with(10)
        logging_mock.StreamHandler().setLevel.assert_called_with(10)
Пример #2
0
def create_external_configs(namespace):
    # type: (argparse.Namespace) -> None
    """
	Create `GitHub Pages` and `Read the Docs` configuration files.
	"""
    logger = get_logger()
    configs = (
        ("gh_pages_config.yml", namespace.output_path / "_config.yml"),
        ("mkdocs.yml", namespace.input_path / "mkdocs.yml"),
        ("readthedocs.yml", namespace.input_path / ".readthedocs.yml"),
    )
    for asset_name, target_path in configs:
        if target_path.exists():
            continue
        logger.info("Creating {} file".format(target_path))
        render_asset(
            asset_name,
            target_path,
            dict(
                source_code_url=namespace.source_code_url.replace(
                    "blob/master/", ""),
                project_name=make_title(namespace.input_path.name),
                docs_path=PathFinder(namespace.input_path).relative(
                    namespace.output_path).as_posix(),
            ),
        )
Пример #3
0
    def __init__(
            self,
            input_path,  # type: Path
            output_path,  # type: Path
            source_paths,  # type: Iterable[Path]
            project_name=None,  # type: Optional[Text]
            docstring_processor=None,  # type: Optional[BaseDocstringProcessor]
            loader=None,  # type: Optional[Loader]
            raise_errors=False,  # type: bool
            source_code_url=None,  # type: Optional[Text]
            toc_depth=1,  # type: int
    ):
        # type: (...) -> None
        self._logger = get_logger()
        self._root_path = input_path
        self._output_path = output_path
        self._project_name = project_name or make_title(input_path.name)
        self._root_path_finder = PathFinder(self._root_path)
        self._source_code_url = source_code_url
        self._toc_depth = toc_depth
        self._raise_errors = raise_errors

        # create output folder if it does not exist
        if not self._output_path.exists():
            self._logger.info("Creating folder {}".format(self._output_path))
            PathFinder(self._output_path).mkdir()

        self._loader = loader or Loader(root_path=self._root_path,
                                        output_path=self._output_path)
        self._docstring_processor = docstring_processor or SmartDocstringProcessor(
        )

        self._source_paths = sorted(source_paths)
        self._error_output_paths = set()  # type: Set[Path]
        self._logger.debug("Generating source map for {} source files".format(
            len(self._source_paths)))
        self._module_records = self._build_module_record_list()
        self._logger.debug("Source map generated")

        package_names = self._module_records.get_package_names()
        package_names_re_expr = "|".join(package_names)
        self._docstring_links_re = re.compile(
            r"`+(?:{})\.\S+`+".format(package_names_re_expr))
        self._prepare_index()
Пример #4
0
def main():
    # type: () -> None
    """
	Main entrypoint for CLI.
	"""
    args = parse_args(sys.argv[1:])

    log_level = logging.INFO
    if args.debug:
        log_level = logging.DEBUG
    if args.quiet:
        log_level = logging.CRITICAL

    logger = get_logger(level=log_level)

    path_finder = (PathFinder(args.input_path).exclude(
        *(EXCLUDE_EXPRS + args.exclude)).include(*args.include))

    try:
        generator = Generator(
            project_name=args.project_name,
            input_path=args.input_path,
            output_path=args.output_path,
            source_paths=path_finder.glob(SOURCES_GLOB),
            raise_errors=args.panic,
            source_code_url=args.source_code_url,
            toc_depth=args.toc_depth,
        )
        if args.files:
            for path in args.files:
                generator.generate_doc(path)
        else:
            generator.generate_docs()
            #generator.generate_index()
            generator.generate_modules()  # This is the index...
            if args.cleanup:
                generator.cleanup_old_docs()

        if args.source_code_url:
            create_external_configs(args)
    except GeneratorError as e:
        logger.error(e)
        sys.exit(1)
Пример #5
0
 def __init__(self):
     # type: () -> None
     super(ExpressionAnalyzer, self).__init__()
     self._logger = get_logger()
     self.parts = []  # type: List[DirtyRenderExpr]
Пример #6
0
 def __init__(self, root_path, output_path):
     # type: (Path, Path) -> None
     self._logger = get_logger()
     self._root_path = root_path
     self._root_path_finder = PathFinder(self._root_path)
     self._output_path = output_path
Пример #7
0
	def __init__(self):
		# type: () -> None
		self._logger = get_logger()
		self.data = []  # type: List[ModuleRecord]
		self.import_string_map = {}  # type: Dict[ImportString, Any]