{ pkgs ? import <nixpkgs> { }, lint ? false }:
pkgs.python3Packages.callPackage ({ lib, buildPythonPackage, makeWrapper
, autopep8, mypy, pylint, beautifulsoup4, requests, requests-cache
- , types-beautifulsoup4, types-requests, xdg-base-dirs, pandoc-cli }:
+ , texliveBasic, types-beautifulsoup4, types-requests, xdg-base-dirs
+ , pandoc-cli }:
buildPythonPackage rec {
pname = "paperdoorknob";
version = "0.0.1";
nativeBuildInputs = [ makeWrapper ];
propagatedBuildInputs =
[ beautifulsoup4 requests requests-cache xdg-base-dirs ];
- nativeCheckInputs = [ mypy pandoc-cli types-beautifulsoup4 types-requests ]
+ nativeCheckInputs =
+ [ mypy pandoc-cli texliveBasic types-beautifulsoup4 types-requests ]
++ lib.optionals lint [ autopep8 pylint ];
doCheck = true;
checkPhase = "./test.sh";
texout: IO[bytes],
pandoc: str,
) -> None:
+ texout.write(b'\\documentclass{article}\n\\begin{document}\n')
html = clean(fetch(url, session, timeout))
for r in replies(html):
texout.write(html_to_tex(pandoc, r))
+ texout.write(b'\\end{document}\n')
def main() -> None:
import unittest
import io
+import subprocess
import threading
from http.server import BaseHTTPRequestHandler, HTTPServer
import requests
TIMEOUT,
buf,
'pandoc')
- self.assertEqual(
- buf.getvalue(),
- b'This is glowfic\nYou \\emph{sure}?\nPretty sure.\n')
+ self.assertEqual(buf.getvalue(), b'''\\documentclass{article}
+\\begin{document}
+This is glowfic
+You \\emph{sure}?
+Pretty sure.
+\\end{document}
+''')
+
+ def testPDF(self) -> None:
+ with requests.session() as s:
+ with open("test.tex", 'wb') as out:
+ paperdoorknob.process(
+ f"http://localhost:{self._port()}",
+ s,
+ TIMEOUT,
+ out,
+ 'pandoc')
+ subprocess.run(['pdflatex', 'test.tex'],
+ stdin=subprocess.DEVNULL, check=True)
if __name__ == '__main__':