Commit 4ace3df1 authored by Ingo Meyer's avatar Ingo Meyer
Browse files

Drop Python 2 support

parent 724c0cbc
......@@ -11,6 +11,6 @@ class CodeBlock(Directive):
def run(self):
language = self.arguments[0]
content = u"\n".join(self.content)
latex = u"\\begin{{minted}}{{{}}}\n{}\n\\end{{minted}}".format(language, content)
content = "\n".join(self.content)
latex = "\\begin{{minted}}{{{}}}\n{}\n\\end{{minted}}".format(language, content)
return [nodes.raw("", latex, format="latex")]
......@@ -4,18 +4,12 @@ import base64
import os
import shutil
import subprocess
import tempfile
import requests
try:
from urllib.parse import urlparse
except ImportError:
from urlparse import urlparse
import sys
import tempfile
from io import BytesIO
from urllib.parse import urlparse
import requests
from docutils import nodes
from docutils.nodes import fully_normalize_name, whitespace_normalize_name
from docutils.parsers.rst import Directive, directives, states
......@@ -118,7 +112,9 @@ def load_and_convert_image(
else:
image_format = "unknown"
if convert_to_base64:
image_reference = "data:image/{format};base64,".format(format=image_format) + base64.b64encode(image_content)
image_reference = "data:image/{format};base64,".format(format=image_format) + base64.b64encode(
image_content
).decode("ascii")
else:
image_reference = image_filepath
self.image_number += 1
......
......@@ -10,8 +10,9 @@ class JupyterOutbox(Directive):
has_content = True
def run(self):
content = u"\n".join(self.content)
latex = u"\\begin{{minted}}[bgcolor=white,breakanywhere=true,breaklines=true,linenos=false]{{text}}\n{}\n\\end{{minted}}".format(
content
)
content = "\n".join(self.content)
latex = (
"\\begin{{minted}}[bgcolor=white,breakanywhere=true,breaklines=true,linenos=false]"
"{{text}}\n{}\n\\end{{minted}}"
).format(content)
return [nodes.raw("", latex, format="latex")]
# -*- coding: utf-8 -*-
VALID_OUTPUT_MODES = ("latex", "html")
_output_mode = "latex"
......
# -*- coding: utf-8 -*-
import base64
import codecs
import os
......@@ -17,7 +15,7 @@ from PIL import Image
from .output_mode import get_output_mode
TEMPLATE_LATEX = u"""
TEMPLATE_LATEX = """
\\documentclass{%- if document_options -%}[{{ document_options }}]{%- endif -%}{standalone}
{% if not do_not_use_default_packages -%}
\\usepackage[utf8]{inputenc}
......@@ -52,18 +50,6 @@ OUT_SVG_FILENAME = "_tikz_rendered{:04d}.svg"
BUILD_DIRECTORY = "."
class TemporaryDirectory(object):
def __init__(self):
self.tmp_dir = tempfile.mkdtemp()
def __enter__(self):
return self.tmp_dir
def __exit__(self, exception_type, value, traceback):
shutil.rmtree(self.tmp_dir)
self.tmp_dir = None
def render_tikz(tikz_code, options, output_png=False, output_svg=False):
self = render_tikz
if not hasattr(self, "image_number"):
......@@ -79,7 +65,7 @@ def render_tikz(tikz_code, options, output_png=False, output_svg=False):
out_pdf_filename = OUT_PDF_FILENAME.format(self.image_number)
out_png_filename = OUT_PNG_FILENAME.format(self.image_number)
out_svg_filename = OUT_SVG_FILENAME.format(self.image_number)
with TemporaryDirectory() as tmp_dir:
with tempfile.TemporaryDirectory() as tmp_dir:
tmp_latex_path = os.path.join(tmp_dir, TMP_LATEX_FILENAME)
tmp_pdf_path = os.path.join(tmp_dir, TMP_PDF_FILENAME)
tmp_png_path = os.path.join(tmp_dir, TMP_PNG_FILENAME)
......
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
# $Id: rst2html.py 4564 2006-05-21 20:44:42Z wiemann $
# Author: David Goodger <goodger@python.org>
# Copyright: This module has been placed in the public domain.
#!/usr/bin/env python3
"""
A customized front end to the Docutils Publisher, producing HTML with support for embedded images and Tikz figures.
Based on the original `rst2html.py`
"""
try:
......
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
# $Id: rst2latex.py 5905 2009-04-16 12:04:49Z milde $
# Author: David Goodger <goodger@python.org>
# Copyright: This module has been placed in the public domain.
#!/usr/bin/env python3
"""
A customized front end to the Docutils Publisher, producing LaTeX with valid codeblocks using the listings package and
support for Tikz images.
Based on the original `rst2latex.py`
"""
try:
......
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import codecs
import os
import runpy
import subprocess
from setuptools import setup, find_packages
from setuptools import find_packages, setup
def get_version_from_pyfile(version_file="docutils_extended/_version.py"):
......@@ -18,22 +10,10 @@ def get_version_from_pyfile(version_file="docutils_extended/_version.py"):
def get_long_description_from_readme(readme_filename="README.md"):
rst_filename = "{}.rst".format(os.path.splitext(os.path.basename(readme_filename))[0])
created_tmp_rst = False
if not os.path.isfile(rst_filename):
try:
subprocess.check_call(["pandoc", readme_filename, "-t", "rst", "-o", rst_filename])
created_tmp_rst = True
except (OSError, subprocess.CalledProcessError):
import logging
logging.warning("Could not convert the readme file to rst.")
long_description = None
if os.path.isfile(rst_filename):
with codecs.open(rst_filename, "r", "utf-8") as readme_file:
if os.path.isfile(readme_filename):
with open(readme_filename, "r", encoding="utf-8") as readme_file:
long_description = readme_file.read()
if created_tmp_rst:
os.remove(rst_filename)
return long_description
......@@ -44,7 +24,7 @@ setup(
name="docutils-extended",
version=version,
packages=find_packages(),
python_requires=">=2.7",
python_requires="~=3.5",
install_requires=["docutils", "jinja2", "pillow", "pygments", "requests"],
entry_points={
"console_scripts": [
......@@ -56,6 +36,7 @@ setup(
author_email="i.meyer@fz-juelich.de",
description="HTML and LaTeX rst writer with support for extra directives",
long_description=long_description,
long_description_content_type="text/markdown",
license="MIT",
url="https://iffgit.fz-juelich.de/doc-utils/doc-utils",
keywords=["docutils", "rst", "reStructuredText", "TikZ"],
......@@ -65,10 +46,15 @@ setup(
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Operating System :: MacOS",
"Operating System :: Unix",
"Operating System :: POSIX :: Linux",
"Programming Language :: Python",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3 :: Only",
"Topic :: Documentation",
"Topic :: Software Development :: Documentation",
],
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment