toxic: 0.15.1 -> 0.16.0
[NixPkgs.git] / pkgs / tools / typesetting / asciidoc / default.nix
blob3f8caf570f625afc995f9e9efec89cc91d64c588
2   fetchurl,
3   lib,
4   stdenv,
5   python3,
6   fetchFromGitHub,
7   autoreconfHook,
8   installShellFiles,
9   enableStandardFeatures ? false,
10   sourceHighlight,
11   highlight,
12   pygments,
13   graphviz,
14   texliveMinimal,
15   dblatexFull,
16   libxslt,
17   w3m,
18   lynx,
19   imagemagick,
20   lilypond,
21   libxml2,
22   docbook_xml_dtd_45,
23   docbook_xsl_ns,
24   docbook_xsl,
25   fop,
26   epubcheck,
27   gnused,
28   coreutils,
30   # if true, enable all the below filters and backends
31   enableExtraPlugins ? false,
33   # unzip is needed to extract filter and backend plugins
34   unzip,
35   # filters
36   enableDitaaFilter ? false,
37   jre,
38   enableMscgenFilter ? false,
39   mscgen,
40   enableDiagFilter ? false,
41   blockdiag,
42   seqdiag,
43   actdiag,
44   nwdiag,
45   enableQrcodeFilter ? false,
46   qrencode,
47   enableMatplotlibFilter ? false,
48   matplotlib,
49   numpy,
50   enableAafigureFilter ? false,
51   aafigure,
52   recursive-pth-loader,
53   # backends
54   enableDeckjsBackend ? false,
55   enableOdfBackend ? false,
57   # java is problematic on some platforms, where it is unfree
58   enableJava ? true,
60   buildPackages,
63 let
65   _enableDitaaFilter = (enableExtraPlugins && enableJava) || enableDitaaFilter;
66   _enableMscgenFilter = enableExtraPlugins || enableMscgenFilter;
67   _enableDiagFilter = enableExtraPlugins || enableDiagFilter;
68   _enableQrcodeFilter = enableExtraPlugins || enableQrcodeFilter;
69   _enableMatplotlibFilter = enableExtraPlugins || enableMatplotlibFilter;
70   _enableAafigureFilter = enableExtraPlugins || enableAafigureFilter;
71   _enableDeckjsBackend = enableExtraPlugins || enableDeckjsBackend;
72   _enableOdfBackend = enableExtraPlugins || enableOdfBackend;
74   #
75   # texlive environment
76   #
77   texlive = texliveMinimal.withPackages (ps: [ ps.dvipng ]);
79   #
80   # filters
81   #
83   ditaaFilterSrc = fetchurl {
84     url = "https://asciidoc-ditaa-filter.googlecode.com/files/ditaa-filter-1.1.zip";
85     sha256 = "0p7hm2a1xywx982ia3vg4c0lam5sz0xknsc10i2a5vswy026naf6";
86   };
88   mscgenFilterSrc = fetchurl {
89     url = "https://asciidoc-mscgen-filter.googlecode.com/files/mscgen-filter-1.2.zip";
90     sha256 = "1nfwmj375gpv5dn9i770pjv59aihzy2kja0fflsk96xwnlqsqq61";
91   };
93   diagFilterSrc = fetchurl {
94     # unfortunately no version number
95     url = "https://asciidoc-diag-filter.googlecode.com/files/diag_filter.zip";
96     sha256 = "1qlqrdbqkdqqgfdhjsgdws1al0sacsyq6jmwxdfy7r8k7bv7n7mm";
97   };
99   qrcodeFilterSrc = fetchurl {
100     url = "https://asciidoc-qrencode-filter.googlecode.com/files/qrcode-filter-1.0.zip";
101     sha256 = "0h4bql1nb4y4fmg2yvlpfjhvy22ln8jsaxdr10f8bfcg5lr0zkxs";
102   };
104   # there are no archives or tags, using latest commit in master branch as per 2013-09-22
105   matplotlibFilterSrc =
106     let
107       commit = "75f0d009629f93f33fab04b83faca20cc35dd358";
108     in
109     fetchurl {
110       name = "mplw-${commit}.tar.gz";
111       url = "https://api.github.com/repos/lvv/mplw/tarball/${commit}";
112       sha256 = "0yfhkm2dr8gnp0fcg25x89hwiymkri2m5cyqzmzragzwj0hbmcf1";
113     };
115   aafigureFilterSrc = fetchurl {
116     url = "https://asciidoc-aafigure-filter.googlecode.com/files/aafigure-filter-1.1.zip";
117     sha256 = "1hq2s30dvmv5dqvj0xm1qwdwafhgm9w1iyr0lr0c40cyk8h00j8j";
118   };
120   #
121   # backends
122   #
124   deckjsBackendSrc = fetchurl {
125     url = "https://github.com/downloads/houqp/asciidoc-deckjs/deckjs-1.6.2.zip";
126     sha256 = "1siy1j8naj5irrrrv5bfgl4d8nal6j9pyahy4f50wmrr9wv59s46";
127   };
129   # the odf backend is actually two plugins: odt + odp
130   odtBackendSrc = fetchurl {
131     url = "https://github.com/downloads/dagwieers/asciidoc-odf/odt-backend-0.1.zip";
132     sha256 = "1zaa97h9sx6ncxcdkl1x3ggydi7f8kjgvrnpjnkjiizi45k350kw";
133   };
135   odpBackendSrc = fetchurl {
136     url = "https://github.com/downloads/dagwieers/asciidoc-odf/odp-backend-0.1.zip";
137     sha256 = "08ya4bskygzqkfqwjllpg31qc5k08xp2k78z9b2480g8y57bfy10";
138   };
141 python3.pkgs.buildPythonApplication rec {
142   pname =
143     "asciidoc"
144     + lib.optionalString enableStandardFeatures "-full"
145     + lib.optionalString enableExtraPlugins "-with-plugins";
146   version = "10.2.1";
147   pyproject = true;
149   src = fetchFromGitHub {
150     owner = "asciidoc-py";
151     repo = "asciidoc-py";
152     rev = version;
153     hash = "sha256-td3C7xTWfSzdo9Bbz0dHW2oPaCQYmUE9H2sUFfg5HH0=";
154   };
156   nativeBuildInputs = [
157     autoreconfHook
158     installShellFiles
159     unzip
160   ];
162   # install filters early, so their shebangs are patched too
163   postPatch =
164     ''
165       mkdir -p "$out/etc/asciidoc/filters"
166       mkdir -p "$out/etc/asciidoc/backends"
167     ''
168     + lib.optionalString _enableDitaaFilter ''
169       echo "Extracting ditaa filter"
170       unzip -d "$out/etc/asciidoc/filters/ditaa" "${ditaaFilterSrc}"
171       sed -i -e "s|java -jar|${jre}/bin/java -jar|" \
172           "$out/etc/asciidoc/filters/ditaa/ditaa2img.py"
173     ''
174     + lib.optionalString _enableMscgenFilter ''
175       echo "Extracting mscgen filter"
176       unzip -d "$out/etc/asciidoc/filters/mscgen" "${mscgenFilterSrc}"
177       sed -i -e "s|filter-wrapper.py mscgen|filter-wrapper.py ${mscgen}/bin/mscgen|" \
178           "$out/etc/asciidoc/filters/mscgen/mscgen-filter.conf"
179     ''
180     + lib.optionalString _enableDiagFilter ''
181       echo "Extracting diag filter"
182       unzip -d "$out/etc/asciidoc/filters/diag" "${diagFilterSrc}"
183       sed -i \
184           -e "s|filter='blockdiag|filter=\'${blockdiag}/bin/blockdiag|" \
185           -e "s|filter='seqdiag|filter=\'${seqdiag}/bin/seqdiag|" \
186           -e "s|filter='actdiag|filter=\'${actdiag}/bin/actdiag|" \
187           -e "s|filter='nwdiag|filter=\'${nwdiag}/bin/nwdiag|" \
188           -e "s|filter='packetdiag|filter=\'${nwdiag}/bin/packetdiag|" \
189           "$out/etc/asciidoc/filters/diag/diag-filter.conf"
190     ''
191     + lib.optionalString _enableQrcodeFilter ''
192       echo "Extracting qrcode filter"
193       unzip -d "$out/etc/asciidoc/filters/qrcode" "${qrcodeFilterSrc}"
194       sed -i -e "s|systemcmd('qrencode|systemcmd('${qrencode}/bin/qrencode|" \
195           "$out/etc/asciidoc/filters/qrcode/qrcode2img.py"
196     ''
197     + lib.optionalString _enableMatplotlibFilter ''
198       echo "Extracting mpl (matplotlib) filter"
199       mkdir -p "$out/etc/asciidoc/filters/mpl"
200       tar xvf "${matplotlibFilterSrc}" -C "$out/etc/asciidoc/filters/mpl" --strip-components=1
201       # Stop asciidoc from loading mpl/.old/chart-filter.conf
202       rm -rf "$out/etc/asciidoc/filters/mpl/.old"
203       # Add matplotlib and numpy to sys.path
204       matplotlib_path="$(toPythonPath ${matplotlib})"
205       numpy_path="$(toPythonPath ${numpy})"
206       sed -i "/^import.*sys/asys.path.append(\"$matplotlib_path\"); sys.path.append(\"$numpy_path\");" \
207           "$out/etc/asciidoc/filters/mpl/mplw.py"
208     ''
209     + lib.optionalString _enableAafigureFilter ''
210       echo "Extracting aafigure filter"
211       unzip -d "$out/etc/asciidoc/filters/aafigure" "${aafigureFilterSrc}"
212       # Add aafigure to sys.path (and it needs recursive-pth-loader)
213       pth_loader_path="$(toPythonPath ${recursive-pth-loader})"
214       aafigure_path="$(toPythonPath ${aafigure})"
215       sed -i "/^import.*sys/asys.path.append(\"$pth_loader_path\"); sys.path.append(\"$aafigure_path\"); import sitecustomize" \
216           "$out/etc/asciidoc/filters/aafigure/aafig2img.py"
217     ''
218     + lib.optionalString _enableDeckjsBackend ''
219       echo "Extracting deckjs backend"
220       unzip -d "$out/etc/asciidoc/backends/deckjs" "${deckjsBackendSrc}"
221     ''
222     + lib.optionalString _enableOdfBackend ''
223       echo "Extracting odf backend (odt + odp)"
224       unzip -d "$out/etc/asciidoc/backends/odt" "${odtBackendSrc}"
225       unzip -d "$out/etc/asciidoc/backends/odp" "${odpBackendSrc}"
226       # The odt backend has a TODO note about removing this hardcoded path, but
227       # the odp backend already has that fix. Copy it here until fixed upstream.
228       sed -i "s|'/etc/asciidoc/backends/odt/asciidoc.ott'|os.path.dirname(__file__),'asciidoc.ott'|" \
229           "$out/etc/asciidoc/backends/odt/a2x-backend.py"
230     ''
231     + (
232       if enableStandardFeatures then
233         ''
234           sed -e "s|dot|${graphviz}/bin/dot|g" \
235               -e "s|neato|${graphviz}/bin/neato|g" \
236               -e "s|twopi|${graphviz}/bin/twopi|g" \
237               -e "s|circo|${graphviz}/bin/circo|g" \
238               -e "s|fdp|${graphviz}/bin/fdp|g" \
239               -i "asciidoc/resources/filters/graphviz/graphviz2png.py"
241           sed -e "s|run('latex|run('${texlive}/bin/latex|g" \
242               -e "s|cmd = 'dvipng'|cmd = '${texlive}/bin/dvipng'|g" \
243               -e "s|cmd = 'dvisvgm'|cmd = '${texlive}/bin/dvisvgm'|g" \
244               -i "asciidoc/resources/filters/latex/latex2img.py"
246           sed -e "s|run('abc2ly|run('${lilypond}/bin/abc2ly|g" \
247               -e "s|run('lilypond|run('${lilypond}/bin/lilypond|g" \
248               -e "s|run('convert|run('${imagemagick.out}/bin/convert|g" \
249               -i "asciidoc/resources/filters/music/music2png.py"
251           sed -e 's|filter="source-highlight|filter="${sourceHighlight}/bin/source-highlight|' \
252               -e 's|filter="highlight|filter="${highlight}/bin/highlight|' \
253               -e 's|filter="pygmentize|filter="${pygments}/bin/pygmentize|' \
254               -i "asciidoc/resources/filters/source/source-highlight-filter.conf"
256           # ENV is custom environment passed to programs that a2x invokes. Here we
257           # use it to work around an impurity in the tetex package; tetex tools
258           # cannot find their neighbours (e.g. pdflatex doesn't find mktextfm).
259           # We can remove PATH= when those impurities are fixed.
260           # TODO: Is this still necessary when using texlive?
261           sed -e "s|^ENV =.*|ENV = dict(XML_CATALOG_FILES='${docbook_xml_dtd_45}/xml/dtd/docbook/catalog.xml ${docbook_xsl_ns}/xml/xsl/docbook/catalog.xml ${docbook_xsl}/xml/xsl/docbook/catalog.xml', PATH='${
262             lib.makeBinPath [
263               texlive
264               coreutils
265               gnused
266             ]
267           }', **(dict(filter(lambda v: v[0] == 'SOURCE_DATE_EPOCH', os.environ.items()))))|" \
268               -e "s|^ASCIIDOC =.*|ASCIIDOC = '$out/bin/asciidoc'|" \
269               -e "s|^XSLTPROC =.*|XSLTPROC = '${libxslt.bin}/bin/xsltproc'|" \
270               -e "s|^DBLATEX =.*|DBLATEX = '${dblatexFull}/bin/dblatex'|" \
271               ${lib.optionalString enableJava ''-e "s|^FOP =.*|FOP = '${fop}/bin/fop'|"''} \
272               -e "s|^W3M =.*|W3M = '${w3m}/bin/w3m'|" \
273               -e "s|^LYNX =.*|LYNX = '${lynx}/bin/lynx'|" \
274               -e "s|^XMLLINT =.*|XMLLINT = '${libxml2.bin}/bin/xmllint'|" \
275               -e "s|^EPUBCHECK =.*|EPUBCHECK = '${epubcheck}/bin/epubcheck'|" \
276               -i asciidoc/a2x.py
277         ''
278       else
279         ''
280           sed -e "s|^ENV =.*|ENV = dict(XML_CATALOG_FILES='${docbook_xml_dtd_45}/xml/dtd/docbook/catalog.xml ${docbook_xsl_ns}/xml/xsl/docbook/catalog.xml ${docbook_xsl}/xml/xsl/docbook/catalog.xml', **(dict(filter(lambda v: v[0] == 'SOURCE_DATE_EPOCH', os.environ.items()))))|" \
281               -e "s|^XSLTPROC =.*|XSLTPROC = '${libxslt.bin}/bin/xsltproc'|" \
282               -e "s|^XMLLINT =.*|XMLLINT = '${libxml2.bin}/bin/xmllint'|" \
283               -i asciidoc/a2x.py
284         ''
285     )
286     + ''
287       # Fix tests
288       for f in $(grep -R --files-with-matches "2002-11-25") ; do
289         substituteInPlace $f --replace "2002-11-25" "1980-01-02"
290         substituteInPlace $f --replace "00:37:42" "00:00:00"
291       done
292     ''
293     + lib.optionalString (stdenv.buildPlatform != stdenv.hostPlatform) ''
294       # We want to use asciidoc from the build platform to build the documentation.
295       substituteInPlace Makefile.in \
296         --replace "python3 -m asciidoc.a2x" "${buildPackages.asciidoc}/bin/a2x"
297     '';
299   build-system = with python3.pythonOnBuildForHost.pkgs; [ setuptools ];
301   postBuild = ''
302     make manpages
303   '';
305   postInstall = ''
306     installManPage doc/asciidoc.1 doc/a2x.1 doc/testasciidoc.1
307   '';
309   nativeCheckInputs = with python3.pkgs; [
310     pytest
311     pytest-mock
312   ];
314   checkPhase = ''
315     runHook preCheck
317     make test
319     runHook postCheck
320   '';
322   meta = {
323     description = "Text-based document generation system";
324     longDescription = ''
325       AsciiDoc is a text document format for writing notes, documentation,
326       articles, books, ebooks, slideshows, web pages, man pages and blogs.
327       AsciiDoc files can be translated to many formats including HTML, PDF,
328       EPUB, man page.
330       AsciiDoc is highly configurable: both the AsciiDoc source file syntax and
331       the backend output markups (which can be almost any type of SGML/XML
332       markup) can be customized and extended by the user.
333     '';
334     sourceProvenance = [
335       lib.sourceTypes.fromSource
336     ] ++ lib.optional _enableDitaaFilter lib.sourceTypes.binaryBytecode;
337     homepage = "https://asciidoc-py.github.io/";
338     changelog = "https://github.com/asciidoc-py/asciidoc-py/blob/${version}/CHANGELOG.adoc";
339     license = lib.licenses.gpl2Plus;
340     platforms = lib.platforms.unix;
341     maintainers = with lib.maintainers; [
342       bjornfor
343       dotlambda
344     ];
345   };