Skip to content

Instantly share code, notes, and snippets.

@aubricus
Created February 24, 2014 08:48
Show Gist options
  • Save aubricus/9184003 to your computer and use it in GitHub Desktop.
Save aubricus/9184003 to your computer and use it in GitHub Desktop.
Use pandoc to convert README.md into .rst for Pypi
long_description = ''
try:
import subprocess
import pandoc
process = subprocess.Popen(
['which pandoc'],
shell=True,
stdout=subprocess.PIPE,
universal_newlines=True
)
pandoc_path = process.communicate()[0]
pandoc_path = pandoc_path.strip('\n')
pandoc.core.PANDOC_PATH = pandoc_path
doc = pandoc.Document()
doc.markdown = open('README.md').read()
long_description = doc.rst
except:
pass
# other params omitted for berevity
setup(
long_description=long_description
)
@jessejensen
Copy link

Here's what I ended up doing, since I know where pandoc is installed on my build system:

# README.md is used as the long description by default
ld_md                           = open('README.md').read()

try:
  import pandoc
  pandoc.core.PANDOC_PATH       = '/usr/bin/pandoc'

  # Here is a great place to fix anything in ld_md that breaks the conversion

  doc                           = pandoc.Document()
  doc.markdown                  = ld_md
  ld                            = doc.rst
except:
  ld                            = ld_md


setup(
  long_description              = ld,
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment