Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_rst(markdown_file):
doc = pandoc.Document()
doc.markdown = open(markdown_file).read()
return doc.rst
def pandoc_read_md(fname):
if 'PANDOC_PATH' not in os.environ:
raise ImportError("No pandoc path to use")
import pandoc
pandoc.core.PANDOC_PATH = os.environ['PANDOC_PATH']
doc = pandoc.Document()
doc.markdown = read(fname)
return doc.rst
LONG_DESCRIPTION = None
README_MARKDOWN = None
with open('README.md') as markdown_source:
README_MARKDOWN = markdown_source.read()
if 'upload' in sys.argv:
# Converts the README.md file to ReST, since PyPI uses ReST for formatting,
# This allows to have one canonical README file, being the README.md
# The conversion only needs to be done on upload.
# Otherwise, the pandoc import and errors that are thrown when
# pandoc are both overhead and a source of confusion for general
# usage/installation.
import pandoc
pandoc.core.PANDOC_PATH = 'pandoc'
doc = pandoc.Document()
doc.markdown = README_MARKDOWN
LONG_DESCRIPTION = doc.rst
else:
# If pandoc isn't installed, e.g. when downloading from pip,
# just use the regular README.
LONG_DESCRIPTION = README_MARKDOWN
setup(
name='qdb',
version='0.1.0',
description='Quantopian Remote Debugger for Python',
author='Quantopian Inc.',
author_email='opensource@quantopian.com',
packages=find_packages(),
scripts=['client/qdb-cli'],
long_description=LONG_DESCRIPTION,
def pandoc_read_md(fname):
if 'PANDOC_PATH' not in os.environ:
raise ImportError("No pandoc path to use")
import pandoc
pandoc.core.PANDOC_PATH = os.environ['PANDOC_PATH']
doc = pandoc.Document()
doc.markdown = read(fname)
return doc.rst
def include_readme():
try:
import pandoc
except ImportError:
return ''
pandoc.core.PANDOC_PATH = find_executable('pandoc')
readme_file = os.path.join(os.path.dirname(__file__), 'README.md')
doc = pandoc.Document()
with open(readme_file, 'r') as rf:
doc.markdown = rf.read().encode()
return doc.rst.decode()
if os.path.isfile(self.path):
with open(self.path,"rb") as f:
s = f.read()
#Be compatible with files made on a certain android text editor that puts those bytes there sometimes.
if s.startswith(b"\xff\xfe"):
s = s[2:]
self.pre_bytes = b"\xff\xfe"
elif s.startswith(b"\xfe\xff"):
s = s[2:]
self.pre_bytes = b"\xfe\xff"
elif s.startswith(b"\xef\xbb\xbf"):
s = s[3:]
self.pre_bytes = b"\xef\xbb\xbf"
else:
self.pre_bytes = b'' #now we are going to use pandoc to convert to html
doc = pandoc.Document()
#Figure out the input format. We back things up and archive them by appenting a Timestamp
#to the end or else a ~. That function strips both of those things.
if util.striptrailingnumbers(self.path).endswith(".html"):
doc.html = s
self.edit.page().setContentEditable(False)
#The special html.ro lets us have read only HTML used for handy calculators and stuff.
elif util.striptrailingnumbers(self.path).endswith(".html.ro"):
doc.html = s
self.edit.page().setContentEditable(False)
elif util.striptrailingnumbers(self.path).endswith(".md"):
doc.markdown_github = s
elif util.striptrailingnumbers(self.path).endswith(".rst"):
if not self.edit.page().isModified():
return
#Back Up File
buf =None
#If the file exists, copy it to file~ first. If that exists, copy it to file4857475928345
if os.path.exists(name):
if not os.path.exists(name+"~"):
buf=(name+"~")
shutil.copy(name, name+"~")
else:
buf = name+str(time.time())
shutil.copy(name,buf )
#Again, pandoc to convert to the proper format
doc = pandoc.Document()
h = downloadAllImages(self.edit.page().mainFrame().toHtml(),name)
doc.html = destyle_html(h).encode("utf-8")
if util.striptrailingnumbers(name).endswith(".md"):
with open(name,"wb") as f:
f.write(self.pre_bytes+doc.markdown_github)
if util.striptrailingnumbers(name).endswith(".rst"):
with open(name,"wb") as f:
f.write(self.pre_bytes+doc.rst)
if buf and os.path.isfile(buf):
os.remove(buf)
#Reload to mark as saved, before the filesystem watcher ca get to it.
self.reload()
def markdown_to_rst(src):
pandoc.core.PANDOC_PATH = "/usr/local/bin/pandoc"
if not os.path.exists(pandoc.core.PANDOC_PATH):
raise Exception("Pandoc not available")
doc = pandoc.Document()
doc.markdown = open("README.md").read()
return doc.rst
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 = long_description
long_description = doc.rst
open("README.rst", "w").write(doc.rst)
except:
if os.path.exists("README.rst"):
long_description = open("README.rst").read()
else:
print("Could not find pandoc or convert properly")
print(" make sure you have pandoc (system) and pyandoc (python module) installed")
return 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 = long_description
long_description = doc.rst
open("README.rst", "w").write(doc.rst)
except:
if os.path.exists("README.rst"):
long_description = open("README.rst").read()
else:
print("Could not find pandoc or convert properly")
print(" make sure you have pandoc (system) and pyandoc (python module) installed")
return long_description