From e01524ed4895cf52aeba3464bf9d062d716149eb Mon Sep 17 00:00:00 2001 From: Isidro Arias Date: Mon, 11 Dec 2023 12:08:22 +0100 Subject: [PATCH 1/4] passed 2to3 script --- latex/__init__.py | 32 ++++++++++++++++---------------- latex/jinja2.py | 2 +- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/latex/__init__.py b/latex/__init__.py index 3a8c9cc..5da0c02 100644 --- a/latex/__init__.py +++ b/latex/__init__.py @@ -4,26 +4,26 @@ from .build import build_pdf CHAR_ESCAPE = { - u'&': u'\\&', - u'%': u'\\%', - u'$': u'\\$', - u'#': u'\\#', - u'_': u'\\_', - u'{': u'\\{', - u'}': u'\\}', - u'~': u'\\textasciitilde{}', - u'^': u'\\textasciicircum{}', - u'\\': u'\\textbackslash{}', + '&': '\\&', + '%': '\\%', + '$': '\\$', + '#': '\\#', + '_': '\\_', + '{': '\\{', + '}': '\\}', + '~': '\\textasciitilde{}', + '^': '\\textasciicircum{}', + '\\': '\\textbackslash{}', # these may be optional: - u'<': u'\\textless{}', - u'>': u'\\textgreater{}', - u'|': u'\\textbar{}', - u'"': u'\\textquotedbl{}', + '<': '\\textless{}', + '>': '\\textgreater{}', + '|': '\\textbar{}', + '"': '\\textquotedbl{}', # to prevent issues with '\\' linebreaks - u'[': u'{[}', - u']': u'{]}', + '[': '{[}', + ']': '{]}', } diff --git a/latex/jinja2.py b/latex/jinja2.py index 27f7a35..8f4fef6 100644 --- a/latex/jinja2.py +++ b/latex/jinja2.py @@ -1,4 +1,4 @@ -from __future__ import absolute_import + from markupsafe import Markup from jinja2 import Environment From 6db2e73b79bacc3b9d8bc647730ccffdc919cc0a Mon Sep 17 00:00:00 2001 From: Isidro Arias Date: Mon, 11 Dec 2023 12:14:55 +0100 Subject: [PATCH 2/4] fix test, drop python2 --- latex/build.py | 5 ++--- setup.py | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/latex/build.py b/latex/build.py index 9fad818..af44b96 100644 --- a/latex/build.py +++ b/latex/build.py @@ -2,7 +2,6 @@ import subprocess from subprocess import CalledProcessError -from future.utils import raise_from from data import Data as I from data.decorators import data from shutilwhich import which @@ -110,7 +109,7 @@ def build_pdf(self, source, texinputs=[]): stdout=open(os.devnull, 'w'), stderr=open(os.devnull, 'w'), ) except CalledProcessError as e: - raise_from(LatexBuildError(base_fn + '.log'), e) + raise LatexBuildError(base_fn + '.log') from e return I(open(output_fn, 'rb').read(), encoding=None) @@ -174,7 +173,7 @@ def build_pdf(self, source, texinputs=[]): stdin=open(os.devnull, 'r'), stdout=open(os.devnull, 'w'), ) except CalledProcessError as e: - raise_from(LatexBuildError(base_fn + '.log'), e) + raise LatexBuildError(base_fn + '.log') from e # check aux-file aux = open(aux_fn, 'rb').read() diff --git a/setup.py b/setup.py index 2de4fbc..fc28c34 100644 --- a/setup.py +++ b/setup.py @@ -20,9 +20,8 @@ def read(fname): url='http://github.com/mbr/latex', license='MIT', packages=find_packages(exclude=['tests']), - install_requires=['tempdir', 'data', 'future', 'shutilwhich'], + install_requires=['tempdir', 'data', 'shutilwhich'], classifiers=[ - 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 3', ] ) From 8d613032730f0e9d65ff48dab60489b4b1e2fa6f Mon Sep 17 00:00:00 2001 From: Isidro Arias Date: Mon, 11 Dec 2023 12:25:47 +0100 Subject: [PATCH 3/4] using shutil.which --- latex/build.py | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/latex/build.py b/latex/build.py index af44b96..3e0e8bb 100644 --- a/latex/build.py +++ b/latex/build.py @@ -4,7 +4,7 @@ from data import Data as I from data.decorators import data -from shutilwhich import which +from shutil import which from six.moves import shlex_quote from tempdir import TempDir diff --git a/setup.py b/setup.py index fc28c34..959d744 100644 --- a/setup.py +++ b/setup.py @@ -20,7 +20,7 @@ def read(fname): url='http://github.com/mbr/latex', license='MIT', packages=find_packages(exclude=['tests']), - install_requires=['tempdir', 'data', 'shutilwhich'], + install_requires=['tempdir', 'data'], classifiers=[ 'Programming Language :: Python :: 3', ] From 55b6b324f329cb8c5e7ee1c1c40b885d711715d8 Mon Sep 17 00:00:00 2001 From: Isidro Arias Date: Mon, 11 Dec 2023 13:24:54 +0100 Subject: [PATCH 4/4] 2to3 applied to docs --- README.rst | 2 +- docs/examples/ex4.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index 22aff04..3a2635f 100644 --- a/README.rst +++ b/README.rst @@ -20,7 +20,7 @@ Allows calling LaTeX from Python without leaving a mess. Similar to the pdf = build_pdf(min_latex) # look at the first few bytes of the header - print bytes(pdf)[:10] + print(bytes(pdf)[:10]) Also comes with support for using `Jinja2 `_ templates to generate LaTeX files. diff --git a/docs/examples/ex4.py b/docs/examples/ex4.py index 377f5ab..c6faa82 100644 --- a/docs/examples/ex4.py +++ b/docs/examples/ex4.py @@ -13,7 +13,7 @@ build_pdf(src) except LatexBuildError as e: for err in e.get_errors(): - print u'Error in {0[filename]}, line {0[line]}: {0[error]}'.format(err) + print('Error in {0[filename]}, line {0[line]}: {0[error]}'.format(err)) # also print one line of context - print u' {}'.format(err['context'][1]) - print + print(' {}'.format(err['context'][1])) + print()