def _install_and_run(*args: Any, **kwargs: Any) -> Any: try: # First try to run pypandoc function result = func(*args, **kwargs) except OSError: # Install pandoc and retry logger.warning( "Pandoc is required but not found. Lander is going to try to " "install it for you right now.") try: pypandoc.download_pandoc() logger.info( "Pandoc version %s installation complete", pypandoc.get_pandoc_version(), ) except Exception: logger.exception("Failed to download pandoc.") raise RuntimeError( "Could not install Pandoc. Please pre-install pandoc on " "your system and try again. See " "https://pandoc.org/installing.html.") result = func(*args, **kwargs) return result
def init_source(source): try: html = urllib.request.urlopen(source).read() except ValueError: if ".docx" not in source: source = source + ".docx" if not path.exists(source): raise FileNotFoundError return source while True: try: pypandoc.convert_text(source=html, format='html', to='docx', outputfile="text_pre_translate.docx", extra_args=['-RTS']) except OSError: pypandoc.download_pandoc() continue break return "text_pre_translate.docx"
def convert_readme(config=None): """Converts readme.md to README.rst. If config is provided, update the version accordingly.""" import pypandoc if config: with open('readme.md') as f: readme = f.readlines() readme[0] = '[![Build Status](https://travis-ci.org/{github_username}/{libname}.svg?branch=v%s)]' \ '(https://travis-ci.org/{github_username}/{libname})\n'.format(**config.__dict__) % config.version with open('readme.md', 'w') as f: f.writelines(readme) try: rst = pypandoc.convert_file('readme.md', 'rst') except OSError: pypandoc.download_pandoc() rst = pypandoc.convert_file('readme.md', 'rst') # pandoc put a lot of carriage return at the end, and we don't want them rst = rst.replace('\r', '') # save the converted readme with open('README.rst', 'w') as f: f.write(rst) click.echo('Readme converted.')
def read(fname, ext=None): if ext: try: return pypandoc.convert(fname, ext) except OSError: pypandoc.download_pandoc() return pypandoc.convert(fname, ext) return open(fname, 'r').read()
def build(working_directory, configuration): """ Preprocess READEME.rst Doxygen doesn't support the importation of .rst files, and the support for .md files doesn't support images that also have links. To get around this limitation, this preprocessor will use docutils to convert the README.rst into an html file which will be directly imported into the Doxygen documentation so only one copy of the README is needed. On exit, return 0 for no error, or a non zero error code if there was an error to report. Args: working_directory Directory this script resides in. configuration Configuration to build, ``all`` if no configuration was requested. Returns: None if not implemented, otherwise an integer error code. """ # Copy README.rst to docs/temp/README.html # Doxygen may not create the output folder, ensure it exists. temp_dir = os.path.join(working_directory, 'temp') create_folder_if_needed(temp_dir) # Get the input and output file names source = os.path.join(os.path.dirname(working_directory), 'README.rst') dest = os.path.join(temp_dir, 'README.html') # Was the file already created and newer than the source? if is_source_newer(source, dest): # Load pandoc if needed to do the conversion if hasattr(pypandoc, 'ensure_pandoc_installed'): # pylint: disable=E1101 pypandoc.ensure_pandoc_installed(quiet=True, delete_installer=True) else: try: pypandoc.get_pandoc_path() except OSError: pypandoc.download_pandoc() pypandoc.convert_file(source, to='html', outputfile=dest) return 0
def download_pandoc(): """Download pandoc if not already installed""" try: # Check whether it is already installed pypandoc.get_pandoc_version() except OSError: # Pandoc not installed. Let's download it. pypandoc.download_pandoc() # Hack to delete the downloaded file from the folder, # otherwise it could get accidently committed to the repo # by other scripts in the repo. pf = platform if pf.startswith('linux'): pf = 'linux' url = pypandoc.pandoc_download._get_pandoc_urls()[0][pf] filename = url.split('/')[-1] os.remove(filename)
def ensure_pandoc_installed(_): import pypandoc # Download pandoc if necessary. If pandoc is already installed and on # the PATH, the installed version will be used. Otherwise, we will # download a copy of pandoc into docs/bin/ and add that to our PATH. pandoc_dir = os.path.join(DOCS_DIRECTORY, "bin") # Add if pandoc_dir not in os.environ["PATH"].split(os.pathsep): os.environ["PATH"] += os.pathsep + pandoc_dir if hasattr(pypandoc, "ensure_pandoc_installed"): pypandoc.ensure_pandoc_installed( quiet=True, targetfolder=pandoc_dir, delete_installer=True, ) else: pypandoc.download_pandoc(targetfolder=pandoc_dir)
def build_readme(working_directory): """ Preprocess READEME.rst Doxygen doesn't support the importation of .rst files, and the support for .md files doesn't support images that also have links. To get around this limitation, this preprocessor will use docutils to convert the README.rst into an html file which will be directly imported into the Doxygen documentation so only one copy of the README is needed. Arg: working_directory: Directory for this function to build. Returns: Zero on no error, non-zero on error. """ # Copy README.rst to docs/temp/README.html # Doxygen may not create the output folder, ensure it exists. temp_dir = os.path.join(working_directory, 'temp') burger.create_folder_if_needed(temp_dir) # Get the input and output file names source = os.path.join(os.path.dirname(working_directory), 'README.rst') dest = os.path.join(temp_dir, 'README.html') # Was the file already created and newer than the source? if burger.is_source_newer(source, dest): # Load pandoc if needed to do the conversion if hasattr(pypandoc, 'ensure_pandoc_installed'): # pylint: disable=E1101 pypandoc.ensure_pandoc_installed(quiet=True, delete_installer=True) else: try: pypandoc.get_pandoc_path() except OSError: pypandoc.download_pandoc() pypandoc.convert_file(source, to='html', outputfile=dest) return 0
# Check that the user has installed the Python development headers PythonH = os.path.join(get_python_inc(), 'Python.h') if not os.path.exists(PythonH): print >> sys.stderr, "You must install the Python development headers!" print >> sys.stderr, "$ apt-get install python-dev" sys.exit(-1) # Convert README.md to reStructuredText for PyPI long_description = '' try: import pypandoc try: pypandoc.get_pandoc_path() except OSError: pypandoc.download_pandoc() long_description = pypandoc.convert_file('README.md', 'rst') except ImportError: pass except Exception as e: print >> sys.stderr, "Failed to convert README.md through pandoc, proceeding anyway" traceback.print_exc() setup( name='pwntools', packages=find_packages(), version='3.5.0dev', data_files=[ ('', glob.glob('*.md') + glob.glob('*.txt')), ], package_data={
package_name = 'mxnet' variant = os.environ['mxnet_variant'].upper() if variant != 'CPU': package_name = 'mxnet_{0}'.format(variant.lower()) with open('doc/PYPI_README.md') as readme_file: long_description = readme_file.read() with open('doc/{0}_ADDITIONAL.md'.format(variant)) as variant_doc: long_description = long_description + variant_doc.read() # pypi only supports rst, so use pandoc to convert import pypandoc if platform.system() == 'Darwin': pypandoc.download_pandoc() long_description = pypandoc.convert_text(long_description, 'rst', 'md') short_description = 'MXNet is an ultra-scalable deep learning framework.' libraries = [] if variant == 'CPU': libraries.append('openblas') else: if variant.startswith('CU100'): libraries.append('CUDA-10.0') elif variant.startswith('CU92'): libraries.append('CUDA-9.2') elif variant.startswith('CU91'): libraries.append('CUDA-9.1') elif variant.startswith('CU90'): libraries.append('CUDA-9.0') elif variant.startswith('CU80'):
def read(*parts): return Path(__file__).parent.joinpath(*parts).read_text() def find_version(*parts): vers_file = read(*parts) match = re.search(r'^__version__ = "(\d+\.\d+\.\d+)"', vers_file, re.M) if match is not None: return match.group(1) raise RuntimeError("Unable to find version string.") # install pandoc if not shutil.which('pandoc'): import pypandoc pypandoc.download_pandoc(version='2.2.3.2', download_folder='/tmp') setup(name="Redmine-zulip", version=find_version("redmine_zulip", "__init__.py"), author="Thomas Michelat", author_email="*****@*****.**", maintainer="Thomas Michelat", url="", description=("Publish Redmine issues to Zulip"), long_description=read("README.md"), license="BSD-3-Clause", entry_points={ "console_scripts": [ "redmine-zulip-publisher = redmine_zulip.redmine:main", ], },
if args.plat_name == "win32": source_path = "src/main/win32" elif args.plat_name == "win-amd64": source_path = "src/main/win-amd64" else: raise OSError("mosi-cbc does not support '%s' platform" % args.plat_name) long_description = "!!! pypandoc and/or pandoc not found, long_description is bad, don't upload this to PyPI !!!" if any(arg in unknown_args for arg in ["sdist", "bdist_wheel"]): try: # noinspection PyUnresolvedReferences from pypandoc import convert, download_pandoc download_pandoc() long_description = convert("README.md", "rst") except (ImportError, OSError): pass setup(name="mosi-cbc", version="0.0.1", description="CBC solver plugin for the mosi package.", long_description=long_description, url="https://github.com/alexbahnisch/mosi-cbc", author="Alex Bahnisch", author_email="*****@*****.**", license="MIT", classifiers=[ "Development Status :: 2 - Pre-Alpha",