Generate README.rst from README.md via pandoc.

    In case of errors, we show a message having the error that we got and
    exit the program.
553939
def generate_readme_rst():
    

    pandoc_cmd = [
        'pandoc',
        '--from=markdown',
        '--to=rst',
        '--output=README.rst',
        'README.md'
    ]

    if os.path.exists('README.rst'):
        return
    try:
        subprocess.call(pandoc_cmd)
    except (IOError, OSError) as e:
        print('Could not run "pandoc". Error: %s' % e, file=sys.stderr)
        print('Generating only a stub instead of the real documentation.')
1127059
def read_long_description(readme_file):
    
    try:
        import pypandoc
    except (ImportError, OSError) as e:
        print('No pypandoc or pandoc: %s' % (e,))
        if is_py3:
            fh = open(readme_file, encoding='utf-8')
        else:
            fh = open(readme_file)
        long_description = fh.read()
        fh.close()
        return long_description
    else:
        return pypandoc.convert(readme_file, 'rst')
321124
def readme(fname):
    """"""
    md = open(os.path.join(os.path.dirname(__file__), fname)).read()
    output = md
    try:
        import pypandoc
        output = pypandoc.convert(md, 'rst', format='md')
    except ImportError:
        pass
    return output
1151385
def check_rst(code, ignore):
    """"""
    filename = '<string>'

    for result in check(code,
                        filename=filename,
                        ignore=ignore):
        yield result
518917
def get_long_description():
    

    with open(
        os.path.join(BASE_DIRECTORY, 'README.md'),
        'r',
        encoding='utf-8'
    ) as readme_file:
        return readme_file.read()
958792
def split_readme(readme_path, before_key, after_key, options_key, end_key):
    """"""
    with open(readme_path) as readme_file:
        readme = readme_file.read()

    top, rest = readme.split(before_key)
    before, rest = rest.split(after_key)
    _, rest = rest.split(options_key)
    _, bottom = rest.split(end_key)

    return (top.rstrip('\n'),
            before.strip('\n'),
            end_key + '\n\n' + bottom.lstrip('\n'))
940634
def pandoc_process(app, what, name, obj, options, lines):
    "

    if not lines:
        return None

    input_format = app.config.mkdsupport_use_parser
    output_format = 'rst'

    # Since default encoding for sphinx.ext.autodoc is unicode and pypandoc.convert_text, which will always return a
    # unicode string, expects unicode or utf-8 encodes string, there is on need for dealing with coding
    text = SEP.join(lines)
    text = pypandoc.convert_text(text, output_format, format=input_format)

    # The 'lines' in Sphinx is a list of strings and the value should be changed
    del lines[:]
    lines.extend(text.split(SEP))
222541
def read_readme():
    
    text = open("README.rst", "rt").read()
    text_lines = text.split("\n")
    ld_i_beg = 0
    while text_lines[ld_i_beg].find("start long description") < 0:
        ld_i_beg += 1
    ld_i_beg += 1
    ld_i_end = ld_i_beg
    while text_lines[ld_i_end].find("end long description") < 0:
        ld_i_end += 1

    ld_text = "\n".join(text_lines[ld_i_beg:ld_i_end])

    return ld_text
203607
function exportReadme(readmePath) {
    const readmePaths = path.resolve(process.cwd(), srcDir);

    glob(readmePaths, void(0), function(error, files) {
        files.forEach((filePath) => {
            let documentation = startFile;
            const markdown = fs.readFileSync(filePath, "utf8");
            const exportPath = filePath.replace(/README\.md/, readmePath);

            if (markdown.length !== 0) {
                documentation += md.render(markdown);
            } else {
                documentation += emptyFile;
            }

            documentation += endFile;
            
            if (!fs.existsSync(exportPath)){
                fs.mkdirSync(exportPath);
            }

            fs.writeFileSync(path.resolve(exportPath, "documentation.tsx"), documentation);
        });
    });
}
1203204
def generateRevision(self):
        
        revpath = self.sourcePath()
        if not os.path.exists(revpath):
            return

        # determine the revision location
        revfile = os.path.join(revpath, self.revisionFilename())
        mode = ''
        # test for svn revision
        try:
            args = ['svn', 'info', revpath]
            proc = subprocess.Popen(args, stdout=subprocess.PIPE)
            mode = 'svn'
        except WindowsError:
            try:
                args = ['git', 'rev-parse', 'HEAD', revpath]
                proc = subprocess.Popen(args, stdout=subprocess.PIPE)
                mode = 'git'
            except WindowsError:
                return

        # process SVN revision
        rev = None

        if mode == 'svn':
            for line in proc.stdout:
                data = re.match('^Revision: (\d+)', line)
                if data:
                    rev = int(data.group(1))
                    break

        if rev is not None:
            try:
                f = open(revfile, 'w')
                f.write('__revision__ = {0}\n'.format(rev))
                f.close()
            except IOError:
                pass
1033483
def sync_readmes():
    
    print("syncing README")
    with open("README.md", 'r') as reader:
        file_text = reader.read()
    with open("README", 'w') as writer:
        writer.write(file_text)
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))
868475
def release_readme_verify():
    
    version = "{version}"
    expected = populate_readme(
        version,
        version,
        pypi="",
        pypi_img="",
        versions="\n\n",
        versions_img="",
        circleci_badge=CIRCLECI_BADGE_RELEASE,
        circleci_path="/{circleci_build}",
        travis_badge=TRAVIS_BADGE_RELEASE,
        travis_path="/builds/{travis_build}",
        appveyor_badge=APPVEYOR_BADGE_RELEASE,
        appveyor_path="/build/{appveyor_build}",
        coveralls_badge=COVERALLS_BADGE_RELEASE,
        coveralls_path="builds/{coveralls_build}",
    )
    with open(RELEASE_README_FILE, "r") as file_obj:
        contents = file_obj.read()
    if contents != expected:
        err_msg = "\n" + get_diff(
            contents,
            expected,
            "README.rst.release.actual",
            "README.rst.release.expected",
        )
        raise ValueError(err_msg)

    else:
        print("README.rst.release.template contents are as expected.")
353913
def create_readme(data):
    
    out = ['<a name="top"></a>Modules\n========\n\n']
    # Links
    for module in sorted(data.keys()):
        desc = "".join(data[module]).strip().split("\n")[0]
        format_str = "\n**[{name}](#{name})** — {desc}\n"
        out.append(format_str.format(name=module, desc=desc))
    # details
    for module in sorted(data.keys()):
        out.append(
            '\n---\n\n### <a name="{name}"></a>{name}\n\n{details}\n'.format(
                name=module, details="".join(data[module]).strip()
            )
        )
    return "".join(out)
805985
def produce_pdf(rst_content=None, doctree_content=None, filename=None):
    
    if filename is None:
        filename = os.path.join(
            "/tmp", ''.join([random.choice(string.ascii_letters +
            string.digits) for n in range(15)]) + '.pdf')
    r2p = RstToPdf(stylesheets=['pdf.style'],
                   style_path=[os.path.join(os.path.dirname(__file__),
                                            'styles')],
                   breaklevel=0,
                   splittables=True,
                   footer="""###Title### - ###Page###/###Total###""")
    r2p.createPdf(text=rst_content,
                  doctree=doctree_content,
                  output=filename)
    return filename
987754
def get_long_description():
    """"""
    try:
        with open('README.md', 'r') as f:
            description = f.read()
    except OSError as e:
        if e.errno != errno.ENOENT:
            raise
        return None

    try:
        process = subprocess.Popen([
                'pandoc',
                '-f', 'markdown_github',
                '-t', 'rst',
            ],
            stdin=subprocess.PIPE,
            stdout=subprocess.PIPE,
            universal_newlines=True,
            )
    except OSError as e:
        if e.errno == errno.ENOENT:
            return None
        raise

    description, __ = process.communicate(input=description)
    if process.poll() is None:
        process.kill()
        raise Exception("pandoc did not terminate")
    if process.poll():
        raise Exception("pandoc terminated abnormally")

    return description
177599
def create_module_rst_file(module_name):
    

    return_text = 'Module:  ' + module_name
    dash = '=' * len(return_text)
    return_text += '\n' + dash + '\n\n'
    return_text += '.. automodule:: ' + module_name + '\n'
    return_text += '   :members:\n\n'

    return return_text