Build markdown documentation from a directory and/or python module.

    # ignore_modules: takes a list of module names to ignore
    # index_filename: __init__.py output (default index.md), use README.md for github indexes
423777
def build(
    root, source_module, output_dir,
    json_dump=False, ignore_modules=None, index_filename='index'
):
    '''
    
    '''
    if root.endswith('/'):
        root = root[:-1]

    if ignore_modules is None:
        ignore_modules = []
    elif isinstance(ignore_modules, str):
        ignore_modules = ignore_modules.split(',')

    # Ensure output_dir format (no / at start, / at end)
    if output_dir.startswith('/'):
        output_dir = output_dir[1:]

    if not output_dir.endswith('/'):
        output_dir = '{}/'.format(output_dir)

    # Apply root to it, make the directory if not exists
    output_dir = '{}/{}'.format(root, output_dir)
    if not path.isdir(output_dir):
            makedirs(output_dir)

    if source_module == '.':
        source_dir = '{}/'.format(root)
    else:
        source_dir = '{}/{}/'.format(root, source_module.replace('.', os.sep))

    # Cd into the source directory
    chdir(source_dir)
    # And build the module list
    module_list = _build_module_list(
        source_module,
        index_filename=index_filename,
        ignore_modules=ignore_modules
    )

    # Cd back to old directory
    chdir(root)
    # And parse all the modules
    _parse_module_list(module_list)

    # Cd inot the target directory
    chdir(output_dir)
    # Finally, write the module list to our output dir
    _write_docs(module_list, output_dir)

    if json_dump:
        print json.dumps(module_list, indent=4)
405333
def find_pyd_file():
    

    if not os.path.isdir("./build"):
        raise NotADirectoryError

    for path, dirs, files in os.walk("./build"):
        for file_name in files:
            file_name_parts = os.path.splitext(file_name)
            if file_name_parts[1] == ".pyd":
                return path
    return None
415286
function outputModuleDefinitions (module, headWasOutput)
  {
    for (var i = 0, m = module.bodies.length; i < m; ++i) {
      var bodyPath = module.bodyPaths[i];
      if (!bodyPath)
        console.log (module.name, i, module.bodies.length, module.bodyPaths);
      // Skip bodies who's corresponding file was already output.
      if (context.outputtedFiles[bodyPath])
        continue;
      context.outputtedFiles[bodyPath] = true;

      var body = module.optimize ?
        optimize (module.bodies[i], bodyPath, module)
        : {status: STAT.INDENTED, data: module.bodies[i]};

      if (i || !headWasOutput)
        traceOutput.push (LINE, '// File: ' + bodyPath, LINE, '');
      traceOutput.push (conditionalIndent (body));
    }
  }
821660
def doc(ctx):
    ''''''
    header(doc.__doc__)
    with ctx.cd(os.path.join(ROOT, 'doc')):
        ctx.run('make html', pty=True)
    success('Documentation available in doc/_build/html')
290652
def autodocs():
    ""
    build_dir = path('docs/_build')
    index_html = build_dir / 'html/index.html'
    if build_dir.exists():
        build_dir.rmtree()

    with pushd("docs"):
        print "\n*** Generating API doc ***\n"
        sh("sphinx-apidoc -o apidoc -f -T -M ../src/pyrocore")
        sh("sphinx-apidoc -o apidoc -f -T -M $(dirname $(python -c 'import tempita; print(tempita.__file__)'))")
        print "\n*** Generating HTML doc ***\n"
        sh('nohup %s/Makefile SPHINXBUILD="sphinx-autobuild -p %d'
           ' -i \'.*\' -i \'*.log\' -i \'*.png\' -i \'*.txt\'" html >autobuild.log 2>&1 &'
           % (os.getcwd(), SPHINX_AUTOBUILD_PORT))

    for i in range(25):
        time.sleep(2.5)
        pid = watchdog_pid()
        if pid:
            sh("touch docs/index.rst")
            sh('ps {}'.format(pid))
            url = 'http://localhost:{port:d}/'.format(port=SPHINX_AUTOBUILD_PORT)
            print("\n*** Open '{}' in your browser...".format(url))
            break
1293487
def runAllInDir(dir_path, exclude=[], add_args=(), ignoreErrors=True):
    
    print('testing all modules of %s' % dir_path)

    if type(add_args) in (tuple, list):
        sys.argv.extend(add_args)
    else:
        sys.argv.append(add_args)
    t = 0
    failed = []
    for _, modname, ispkg in pkgutil.walk_packages(
            [dir_path],
            #onerror=lambda x: None
    ):
        if not ispkg and modname != thismodname and modname not in exclude:  # don't test this module
            print('... %s' % modname)
            t0 = time()
            try:
                runpy.run_module(
                    modname,
                    init_globals=None,
                    run_name='__main__',
                    alter_sys=False)
            except Exception as err:
                if ignoreErrors:
                    print("FAILED: %s" % err)
                else:
                    raise err
                failed.append((modname, err))
            dt = time() - t0
            t += dt
            print('execution time=%s' % dt)
    print('----------------')
    print('time needed=%s' % t)
    if failed:
        print('=======================')
        print('failed for %s modules' % len(failed))
        print('-----------------------')
        for mod, err in failed:
            print(mod, err)
480863
def mkdocs(dir = Dir.pwd, options = {})
      info "Initialize MkDocs (see http://www.mkdocs.org/)"
      path = normalized_path(dir)
      use_git = FalkorLib::Git.init?(path)
      rootdir = (use_git) ? FalkorLib::Git.rootdir(path) : path
      templatedir = File.join( FalkorLib.templates, 'mkdocs')
      config = guess_project_config(rootdir, options)
      config[:sitename] = ask("\tSite name: ", config[:name].capitalize)
      puts config.to_yaml
      #FalkorLib::GitFlow.start('feature', 'mkdocs', rootdir) if (use_git && FalkorLib::GitFlow.init?(rootdir))
      init_from_template(templatedir, rootdir, config,
                         :no_interaction => true,
                         :no_commit => true)
      Dir.chdir( File.join(rootdir, 'docs')) do
        run %(ln -s README.md index.md )
        run %(ln -s README.md contributing/index.md )
        run %(ln -s README.md setup/index.md )
      end
      #exit_status.to_i
    end
1300595
def get_module_names(path_dir, exclude=None):
    if exclude is None: exclude = _default_exclude
    ""
    files = sorted(path_dir.glob('*'), key=lambda x: (x.is_dir(), x.name), reverse=True) # directories first
    res = [f'{path_dir.name}']
    for f in files:
        if f.is_dir() and f.name in exclude: continue # exclude directories
        if any([f.name.endswith(ex) for ex in exclude]): continue # exclude extensions

        if f.suffix == '.py': res.append(f'{path_dir.name}.{f.stem}')
        elif f.is_dir(): res += [f'{path_dir.name}.{name}' for name in get_module_names(f)]
    return res
1004483
def build(ctx, less=False, docs=False, js=False, force=False):
    
    specified = any([less, docs, js])
    buildall = not specified

    if buildall or less:
        less_fname = ctx.pkg.source_less / ctx.pkg.name + '.less'
        if less_fname.exists():
            lessc.LessRule(
                ctx,
                src='{pkg.source_less}/{pkg.name}.less',
                dst='{pkg.django_static}/{pkg.name}/css/{pkg.name}-{version}.min.css',
                force=force
            )
        elif less:
            print("WARNING: build --less specified, but no file at:", less_fname)

    if buildall or docs:
        if WARN_ABOUT_SETTINGS:
            warnings.warn(
                "autodoc might need a dummy settings file in the root of "
                "your package. Since it runs in a separate process you cannot"
                "use settings.configure()"
            )
        doctools.build(ctx, force=force)

    if buildall or js:
        build_js(ctx, force)

    if HAVE_SETTINGS and (force or changed(ctx.pkg.django_static)):
        collectstatic(ctx, DJANGO_SETTINGS_MODULE)
952267
def update_readme_for_modules(modules):
    
    readme = parse_readme()
    module_docstrings = core_module_docstrings()
    if modules == ["__all__"]:
        modules = core_module_docstrings().keys()
    for module in modules:
        if module in module_docstrings:
            print_stderr("Updating README.md for module {}".format(module))
            readme[module] = module_docstrings[module]
        else:
            print_stderr("Module {} not in core modules".format(module))

    # write the file
    readme_file = os.path.join(modules_directory(), "README.md")
    with open(readme_file, "w") as f:
        f.write(create_readme(readme))
102310
def ignore_sphinx():
    """"""
    (directives, roles) = _get_directives_and_roles_from_sphinx()

    directives += [
        'centered',
        'include',
        'deprecated',
        'index',
        'no-code-block',
        'literalinclude',
        'hlist',
        'seealso',
        'toctree',
        'todo',
        'versionadded',
        'versionchanged']

    ext_autosummary = [
        'autosummary',
        'currentmodule',
    ]

    ignore_directives_and_roles(directives + ext_autosummary,
                                roles + ['ctype'])
291090
def main(argv=None):
    
    # Get command line arguments, validate them, and normalize them
    opts = cmdparse.parse_args(argv)
    assert validate_opts.validate(opts)
    opts = normalize_opts.normalize(opts)

    if opts.verbose:
        # Update client: print input and output directories
        messages.print_input_output(opts)

    file_paths = fileparse.get_file_list(opts)
    assert validate_files.validate(file_paths, opts)

    if opts.verbose and opts.is_dir:
        # Update client: print files that will be parsed
        messages.print_files(opts, file_paths)

    # For now, only using default GitHub Markdown for parsing
    # Collect tag/anchor combinations
    collector = make_github_markdown_collector(opts)
    anchors, duplicate_tags = collector.collect(file_paths)
    assert validate_anchors.validate(anchors, duplicate_tags, opts)

    # Write files using previously found AnchorHub tags and generated anchors
    writer = make_github_markdown_writer(opts)
    counter = writer.write(file_paths, anchors, opts)

    if opts.verbose:
        if opts.is_dir:
            # Update client: print files that had modifications
            messages.print_modified_files(opts, anchors)
        # Print summary statistics
        messages.print_summary_stats(counter)
1009020
def compile_markdown_file(source_file):
  ''''''
  template = pkg_resources.resource_string('md2remark.resources.templates', 'slideshow.mustache')

  renderer = pystache.Renderer(search_dirs='./templates')

  f = open(source_file, 'r')
  slideshow_md = f.read()
  f.close()
  slideshow_name = os.path.split(source_file)[1].split('.')[0]

  rendered_text = renderer.render(template, {'title': slideshow_name, 'slideshow': slideshow_md})  

  if not os.path.exists('md2remark_build'):
    os.makedirs('md2remark_build')
  
  f = open(os.path.join('md2remark_build', slideshow_name + '.html'), 'w')
  f.write(rendered_text)
  f.close()
1115301
def dump_index(args, idx):
    """"""

    import csv
    import sys

    from metatab import MetatabDoc

    doc = MetatabDoc()

    pack_section = doc.new_section('Packages', ['Identifier', 'Name', 'Nvname', 'Version', 'Format'])

    r = doc['Root']
    r.new_term('Root.Title', 'Package Index')

    for p in idx.list():

        pack_section.new_term('Package',
                   p['url'],
                   identifier=p['ident'],
                   name=p['name'],
                   nvname=p['nvname'],
                   version=p['version'],
                   format=p['format'])

    doc.write_csv(args.dump)
1340914
def readme():
    """"""
    try:
        import pypandoc
        readme_content = pypandoc.convert('README.md', 'rst')
    except(IOError, ImportError):
        print("Warning: no pypandoc module found.")
        try:
            readme_content = open('README.md').read()
        except IOError:
            readme_content = ''
    return readme_content
1134658
def ftdetect(filename):
    
    _, extension = os.path.splitext(filename)
    md_exts = ['.md', '.markdown', '.mkd', '.mdown', '.mkdn', '.Rmd']
    nb_exts = ['.ipynb']
    if extension in md_exts:
        return 'markdown'
    elif extension in nb_exts:
        return 'notebook'
    else:
        return None
1183812
def gen(skipdirhtml=False):
    """"""
    docs_changelog = 'docs/changelog.rst'
    check_git_unchanged(docs_changelog)
    pandoc('--from=markdown', '--to=rst', '--output=' + docs_changelog, 'CHANGELOG.md')
    if not skipdirhtml:
        sphinx_build['-b', 'dirhtml', '-W', '-E', 'docs', 'docs/_build/dirhtml'] & FG
    sphinx_build['-b', 'html', '-W', '-E', 'docs', 'docs/_build/html'] & FG