def create_package_file(root, master_package, subroot, py_files, opts, subs, is_namespace, excludes=[]): # NOQA # type: (str, str, str, List[str], Any, List[str], bool, List[str]) -> None """Build the text of the file and write the file.""" # build a list of sub packages (directories containing an INITPY file) subpackages = [sub for sub in subs if not shall_skip(path.join(root, sub, INITPY), opts, excludes)] subpackages = [makename(makename(master_package, subroot), pkgname) for pkgname in subpackages] # build a list of sub modules submodules = [path.splitext(sub)[0] for sub in py_files if not shall_skip(path.join(root, sub), opts, excludes) and sub != INITPY] submodules = [makename(master_package, makename(subroot, modname)) for modname in submodules] context = { 'pkgname': makename(master_package, subroot), 'subpackages': subpackages, 'submodules': submodules, 'is_namespace': is_namespace, 'modulefirst': opts.modulefirst, 'separatemodules': opts.separatemodules, 'automodule_options': OPTIONS, 'show_headings': not opts.noheadings, } text = ReSTRenderer(template_dir).render('package.rst', context) write_file(makename(master_package, subroot), text, opts) if submodules and opts.separatemodules: for submodule in submodules: create_module_file(None, submodule, opts)
def create_package_file(root: str, master_package: str, subroot: str, py_files: List[str], opts: Any, subs: List[str], is_namespace: bool, excludes: List[str] = [], user_template_dir: str = None) -> None: """Build the text of the file and write the file.""" # build a list of sub packages (directories containing an INITPY file) subpackages = [sub for sub in subs if not shall_skip(path.join(root, sub, INITPY), opts, excludes)] subpackages = [module_join(master_package, subroot, pkgname) for pkgname in subpackages] # build a list of sub modules submodules = [path.splitext(sub)[0] for sub in py_files if not is_skipped_module(path.join(root, sub), opts, excludes) and sub != INITPY] submodules = [module_join(master_package, subroot, modname) for modname in submodules] pkgname = module_join(master_package, subroot) context = { 'pkgname': pkgname, 'subpackages': subpackages, 'submodules': submodules, 'is_namespace': is_namespace, 'modulefirst': opts.modulefirst, 'separatemodules': opts.separatemodules, 'automodule_options': OPTIONS, 'show_headings': not opts.noheadings, } text = ReSTRenderer([user_template_dir, template_dir]).render('package.rst_t', context) write_file(pkgname, text, opts) if submodules and opts.separatemodules: for submodule in submodules: create_module_file(None, submodule, opts, user_template_dir)
def create_module_file(package, basename, opts): # type: (str, str, Any) -> None """Build the text of the file and write the file.""" qualname = makename(package, basename) context = { 'show_headings': not opts.noheadings, 'basename': basename, 'qualname': qualname, 'automodule_options': OPTIONS, } text = ReSTRenderer(template_dir).render('module.rst', context) write_file(qualname, text, opts)
def create_module_file(package: str, basename: str, opts: Any, user_template_dir: str = None) -> None: """Build the text of the file and write the file.""" qualname = module_join(package, basename) context = { 'show_headings': not opts.noheadings, 'basename': basename, 'qualname': qualname, 'automodule_options': OPTIONS, } text = ReSTRenderer([user_template_dir, template_dir]).render('module.rst_t', context) write_file(qualname, text, opts)
def create_package_file(root: str, master_package: str, subroot: str, py_files: List[str], opts: Any, subs: List[str], is_namespace: bool, excludes: List[str] = [], user_template_dir: str = None) -> None: """Build the text of the file and write the file.""" # build a list of sub packages (directories containing an __init__ file) subpackages = [ module_join(master_package, subroot, pkgname) for pkgname in subs if not is_skipped_package(path.join(root, pkgname), opts, excludes) ] # build a list of sub modules submodules = [ sub.split('.')[0] for sub in py_files if not is_skipped_module(path.join(root, sub), opts, excludes) and not is_initpy(sub) ] submodules = sorted(set(submodules)) submodules = [ module_join(master_package, subroot, modname) for modname in submodules ] options = copy(OPTIONS) if opts.includeprivate and 'private-members' not in options: options.append('private-members') pkgname = module_join(master_package, subroot) context = { 'pkgname': pkgname, 'subpackages': subpackages, 'submodules': submodules, 'is_namespace': is_namespace, 'modulefirst': opts.modulefirst, 'separatemodules': opts.separatemodules, 'automodule_options': options, 'show_headings': not opts.noheadings, 'maxdepth': opts.maxdepth, } text = ReSTRenderer([user_template_dir, template_dir]).render('package.rst_t', context) write_file(pkgname, text, opts) if submodules and opts.separatemodules: for submodule in submodules: create_module_file(None, submodule, opts, user_template_dir)
def create_module_file(package: str, basename: str, opts: Any, user_template_dir: str = None) -> None: """Build the text of the file and write the file.""" options = copy(OPTIONS) if opts.includeprivate and 'private-members' not in options: options.append('private-members') qualname = module_join(package, basename) context = { 'show_headings': not opts.noheadings, 'basename': basename, 'qualname': qualname, 'automodule_options': options, } text = ReSTRenderer([user_template_dir, template_dir]).render('module.rst_t', context) write_file(qualname, text, opts)
def create_modules_toc_file(modules: List[str], opts: Any, name: str = 'modules', user_template_dir: str = None) -> None: """Create the module's index.""" modules.sort() prev_module = '' for module in modules[:]: # look if the module is a subpackage and, if yes, ignore it if module.startswith(prev_module + '.'): modules.remove(module) else: prev_module = module context = { 'header': opts.header, 'maxdepth': opts.maxdepth, 'docnames': modules, } text = ReSTRenderer([user_template_dir, template_dir]).render('toc.rst_t', context) write_file(name, text, opts)
def test_ReSTRenderer_heading(): r = ReSTRenderer() template = '{{ "hello" | heading }}' assert r.render_string(template, {}) == 'hello\n=====' template = '{{ "hello" | heading(1) }}' assert r.render_string(template, {}) == 'hello\n=====' template = '{{ "русский язык" | heading(2) }}' assert r.render_string(template, {}) == ('русский язык\n' '------------') # language: ja r.env.language = 'ja' template = '{{ "русский язык" | heading }}' assert r.render_string(template, {}) == ('русский язык\n' '=======================')
def test_ReSTRenderer_escape(): r = ReSTRenderer() template = '{{ "*hello*" | e }}' assert r.render_string(template, {}) == r'\*hello\*'