Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
34282: dd spkg='texlive', refactoring, pycodestyle
Browse files Browse the repository at this point in the history
  • Loading branch information
soehms committed Aug 8, 2022
1 parent c599e49 commit 7358dc2
Showing 1 changed file with 40 additions and 13 deletions.
53 changes: 40 additions & 13 deletions src/sage/features/latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
from sage.features.join_feature import JoinFeature

latex_url = 'https://www.latex-project.org/'
latex_spkg = 'texlive'

class latex(Executable):

class LaTeX(Executable):
r"""
A :class:`~sage.features.Feature` describing the presence of ``latex``
Expand All @@ -27,15 +29,15 @@ class latex(Executable):
sage: latex().is_present() # optional - latex
FeatureTestResult('latex', True)
"""
def __init__(self):
def __init__(self, name):
r"""
TESTS::
sage: from sage.features.latex import latex
sage: isinstance(latex(), latex)
True
"""
Executable.__init__(self, "latex", executable="latex", url=latex_url)
Executable.__init__(self, name, executable=name, spkg=latex_spkg, url=latex_url)

def is_functional(self):
r"""
Expand Down Expand Up @@ -64,7 +66,7 @@ def is_functional(self):

# running latex
from subprocess import run
cmd = ['latex', '-interaction=nonstopmode', filename_tex]
cmd = [self.name, '-interaction=nonstopmode', filename_tex]
cmd = ' '.join(cmd)
result = run(cmd, shell=True, cwd=base, capture_output=True, text=True)

Expand All @@ -73,10 +75,32 @@ def is_functional(self):
return FeatureTestResult(self, True)
else:
return FeatureTestResult(self, False, reason="Running latex on "
"a sample file returned non-zero "
"exit status {}".format(result.returncode))
"a sample file returned non-zero "
"exit status {}".format(result.returncode))


class latex(LaTeX):
r"""
A :class:`~sage.features.Feature` describing the presence of ``latex``
EXAMPLES::
sage: from sage.features.latex import latex
sage: latex().is_present() # optional - latex
FeatureTestResult('latex', True)
"""
def __init__(self):
r"""
TESTS::
sage: from sage.features.latex import latex
sage: isinstance(latex(), latex)
True
"""
LaTeX.__init__(self, "latex")

class pdflatex(Executable):

class pdflatex(LaTeX):
r"""
A :class:`~sage.features.Feature` describing the presence of ``pdflatex``
Expand All @@ -94,9 +118,10 @@ def __init__(self):
sage: isinstance(pdflatex(), pdflatex)
True
"""
Executable.__init__(self, "pdflatex", executable="pdflatex", url=latex_url)
LaTeX.__init__(self, "pdflatex")


class xelatex(Executable):
class xelatex(LaTeX):
r"""
A :class:`~sage.features.Feature` describing the presence of ``xelatex``
Expand All @@ -114,10 +139,10 @@ def __init__(self):
sage: isinstance(xelatex(), xelatex)
True
"""
Executable.__init__(self, "xelatex", executable="xelatex", url=latex_url)
LaTeX.__init__(self, "xelatex")


class lualatex(Executable):
class lualatex(LaTeX):
r"""
A :class:`~sage.features.Feature` describing the presence of ``lualatex``
Expand All @@ -135,7 +160,7 @@ def __init__(self):
sage: isinstance(lualatex(), lualatex)
True
"""
Executable.__init__(self, "lualatex", executable="lualatex", url=latex_url)
LaTeX.__init__(self, "lualatex")


class TeXFile(StaticFile, JoinFeature):
Expand All @@ -158,7 +183,8 @@ def __init__(self, name, filename, **kwds):
sage: LaTeXPackage("tkz-graph")._features
[Feature('pdflatex')]
"""
JoinFeature.__init__(self, name, [pdflatex()], url=latex_url) # see :trac:`34282`
JoinFeature.__init__(self, name, [pdflatex()],
spkg=latex_spkg, url=latex_url) # see :trac:`34282`
StaticFile.__init__(self, name, filename, search_path=[], **kwds)

def absolute_filename(self) -> str:
Expand Down Expand Up @@ -199,6 +225,7 @@ def _is_present(self):
return test
return super(TeXFile, self)._is_present()


class LaTeXPackage(TeXFile):
r"""
A :class:`sage.features.Feature` describing the presence of a LaTeX package
Expand Down

0 comments on commit 7358dc2

Please sign in to comment.